Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 1.92 KB

build_protobuf_notes.md

File metadata and controls

59 lines (42 loc) · 1.92 KB

Build Protocol Buffers using Docker

Building the protobufs on my local Mac results in the below error. It is caused by not having the latest compiler. However, I am not able to fix the issue locally. Therefore, to solve the problem, I use a Docker container.

../../../../../go/pkg/mod/github.com/garystafford/[email protected]/greeting/v2/greeting.pb.gw.go:39:2: cannot use msg (type *GreetingResponse) as type protoreflect.ProtoMessage in return argument:
	*GreetingResponse does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
../../../../../go/pkg/mod/github.com/garystafford/[email protected]/greeting/v2/greeting.pb.gw.go:48:2: cannot use msg (type *GreetingResponse) as type protoreflect.ProtoMessage in return argument:
	*GreetingResponse does not implement protoreflect.ProtoMessage (missing ProtoReflect method)`

Builder Container

mkdir build-protobufs
cd build-protobufs

docker run --rm -it -v "$PWD":/tmp golang:latest bash

Build Protobufs

cd /tmp

# 1x only
export bufbuilder=v0.43.2
wget https://github.com/bufbuild/buf/releases/download/${bufbuilder}/buf-Linux-aarch64.tar.gz \
    && tar -xf buf-Linux-aarch64.tar.gz \
    && rm -rf buf-Linux-aarch64.tar.gz

export PATH="/tmp/buf/bin:$PATH"

go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest \
    && go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest \
    && go install google.golang.org/protobuf/cmd/protoc-gen-go@latest \
    && go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

git clone https://github.com/garystafford/pb-greeting.git \
    && cd pb-greeting/

buf beta mod update

buf lint
buf ls-files

buf generate

# or
buf generate --path proto/greeting/v3 -v

Copy the resulting files into the protobuf project and commit to GitHub.

rm -rf pb-greeting
rm -rf protobuf