0

The docker image named golang:1.15 contains everything I require to generate grpc code using protoc. The only problem is that I want the output to be stable, by pinning the version of few packages (protoc-gen-go, protoc-gen-go-grpc, grpc, protobuf).

Here is my Dockerfile

FROM golang:1.15

WORKDIR /app

RUN export GO111MODULE=on  # Enable module mode
RUN go mod init id

RUN go get google.golang.org/protobuf/cmd/protoc-gen-go@v1.25.0
RUN go get google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0
RUN go get google.golang.org/grpc@v1.35.0
RUN go get github.com/golang/protobuf@v1.4.3

RUN export PATH="$PATH:$(go env GOPATH)/bin"

The code-gen is done like so:

docker run -v "$$(pwd):/app" -v "$$(pwd)/pb:/pb" apigen protoc --go_out=../pb --go_opt=paths=source_relative --go-grpc_out=../pb --go-grpc_opt=paths=source_relative ./myproto.proto

This generates the code alright, but with this line on top // protoc-gen-go v1.25.0-devel This is not the version I asked.

I tried changing the RUN go get .../protoc-gen-go@v1.25.0 to get v1.24.0 and it still shows the same output in the file, which means it doesn't use my modules at all, and must be using the ones from the golang image.

How can I override what's in the image to pin the versions?

David Gourde
  • 3,709
  • 2
  • 31
  • 65
  • Are you sure you're running the correct build from that `Dockerfile`? There's no mention of a `protoc` download/install. Unless you're relying on the `-v` mount to pull in `protoc` from your host system? In which case are you sure the protoc `include` (needed for basic proto definitions) directory is part of your docker run? – colm.anseo Feb 22 '21 at 19:18
  • When I run the same command locally, it works fine (I have the correct version installed locally). It doesn't mention the protoc install, as it seems to be part of the base image already. What's in the base image might interfere with the versions I want to use. – David Gourde Feb 23 '21 at 16:29
  • `protoc` is *NOT* part of the `golang` docker image: `docker run -it golang:1.15 find / -name protoc` – colm.anseo Feb 23 '21 at 18:50
  • I ran your docker image (using downloaded `protoc` compiler mounted via `-v`) - and it produced `.pb.go` files consistent with the versions requested. Altering versions (e.g. `v1.24.0`) yielded the expected results. Are you sure you are looking in the correct output directory? Maybe you are checking stale files. Check their timestamps to be sure. – colm.anseo Feb 23 '21 at 18:52

0 Answers0