FROM --platform=$BUILDPLATFORM alpine as protoc ARG BUILDPLATFORM=linux/amd64 TARGETOS=linux TARGETARCH=amd64 # download the protoc binary from github # We unzip the file into /usr/local. Notice that we are extracting both the protoc # binary (/bin/protoc) and the /include folder because the first one is the compiler that we are # going to use and the second one is all the files needed to include Well-Known Types. RUN export PROTOC_VERSION=26.1 \ && export PROTOC_OS=$(echo $TARGETOS | sed s/darwin/linux/) \ && export PROTOC_ARCH=$(uname -m | sed s/aarch64/aarch_64/) \ && export PROTOC_ZIP=protoc-$PROTOC_VERSION-$PROTOC_OS-$PROTOC_ARCH.zip \ && echo "downloading: " https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_ZIP \ && wget https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_ZIP \ && unzip -o $PROTOC_ZIP -d /usr/local bin/protoc 'include/*' \ && rm -f $PROTOC_ZIP FROM --platform=$BUILDPLATFORM golang:1.22-alpine as build ARG BUILDPLATFORM=linux/amd64 TARGETOS=linux TARGETARCH=amd64 # copy the protoc binary and the protobuf includes COPY --from=protoc /usr/local/bin/protoc /usr/local/bin/protoc COPY --from=protoc /usr/local/include/google /usr/local/include/google # dowload protoc plugins RUN go env -w GOPROXY=https://goproxy.io,direct RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest RUN go install github.com/envoyproxy/protoc-gen-validate@latest # copy proto files into go/src/proto WORKDIR /go/src/proto COPY ./proto . # generate code out of proto files WORKDIR /go/src RUN mkdir pb RUN protoc --proto_path=proto \ --go_out=pb \ --go_opt=paths=source_relative \ --go-grpc_out=pb \ --go-grpc_opt=paths=source_relative \ --validate_out="lang=go,paths=source_relative:pb" \ proto/*.proto
标签:protoc,&&,proto,--,PROTOC,Install,go,Dockerfile From: https://www.cnblogs.com/zhangzhihui/p/18141788