mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
protobuf: remove gogoproto
Removes gogo/protobuf from buildx and updates to a version of moby/buildkit where gogo is removed. This also changes how the proto files are generated. This is because newer versions of protobuf are more strict about name conflicts. If two files have the same name (even if they are relative paths) and are used in different protoc commands, they'll conflict in the registry. Since protobuf file generation doesn't work very well with `paths=source_relative`, this removes the `go:generate` expression and just relies on the dockerfile to perform the generation. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
@ -7,10 +7,13 @@
|
||||
|
||||
ARG GO_VERSION="1.22"
|
||||
ARG PROTOC_VERSION="3.11.4"
|
||||
ARG PROTOC_GOOGLEAPIS_VERSION=2af421884dd468d565137215c946ebe4e245ae26
|
||||
|
||||
# protoc is dynamically linked to glibc so can't use alpine base
|
||||
FROM golang:${GO_VERSION}-bookworm AS base
|
||||
RUN apt-get update && apt-get --no-install-recommends install -y git unzip
|
||||
|
||||
FROM base AS protoc
|
||||
ARG PROTOC_VERSION
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
@ -18,34 +21,57 @@ RUN <<EOT
|
||||
set -e
|
||||
arch=$(echo $TARGETARCH | sed -e s/amd64/x86_64/ -e s/arm64/aarch_64/)
|
||||
wget -q https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${TARGETOS}-${arch}.zip
|
||||
unzip protoc-${PROTOC_VERSION}-${TARGETOS}-${arch}.zip -d /usr/local
|
||||
unzip protoc-${PROTOC_VERSION}-${TARGETOS}-${arch}.zip -d /opt/protoc
|
||||
EOT
|
||||
WORKDIR /go/src/github.com/docker/buildx
|
||||
|
||||
FROM base AS tools
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
FROM base AS googleapis
|
||||
ARG PROTOC_GOOGLEAPIS_VERSION
|
||||
RUN <<EOT
|
||||
set -e
|
||||
wget -q https://github.com/googleapis/googleapis/archive/${PROTOC_GOOGLEAPIS_VERSION}.zip -O googleapis.zip
|
||||
unzip googleapis.zip '*.proto' -d /opt
|
||||
mv /opt/googleapis-${PROTOC_GOOGLEAPIS_VERSION} /opt/googleapis
|
||||
EOT
|
||||
|
||||
FROM base AS protoc-buildkit
|
||||
WORKDIR /app
|
||||
RUN --mount=type=bind,target=/app \
|
||||
--mount=type=cache,target=/root/.cache \
|
||||
--mount=type=cache,target=/go/pkg/mod <<EOT
|
||||
set -e
|
||||
mkdir -p /opt/protoc
|
||||
find vendor -name '*.proto' | tar -cf - --files-from - | tar -C /opt/protoc -xf -
|
||||
EOT
|
||||
|
||||
FROM base AS gobuild-base
|
||||
WORKDIR /go/src
|
||||
COPY --link --from=protoc /opt/protoc /usr/local
|
||||
COPY --link --from=googleapis /opt/googleapis /usr/local/include
|
||||
COPY --link --from=protoc-buildkit /opt/protoc/vendor /usr/local/include
|
||||
|
||||
FROM gobuild-base AS tools
|
||||
RUN --mount=type=bind,source=go.mod,target=/go/src/go.mod,ro \
|
||||
--mount=type=bind,source=go.sum,target=/go/src/go.sum,ro \
|
||||
--mount=type=cache,target=/root/.cache \
|
||||
--mount=type=cache,target=/go/pkg/mod \
|
||||
go install \
|
||||
github.com/gogo/protobuf/protoc-gen-gogo \
|
||||
github.com/gogo/protobuf/protoc-gen-gogofaster \
|
||||
github.com/gogo/protobuf/protoc-gen-gogoslick \
|
||||
github.com/golang/protobuf/protoc-gen-go
|
||||
google.golang.org/protobuf/cmd/protoc-gen-go \
|
||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc
|
||||
|
||||
FROM tools AS generated
|
||||
RUN --mount=type=bind,target=.,rw <<EOT
|
||||
RUN --mount=type=bind,target=github.com/docker/buildx,ro <<EOT
|
||||
set -ex
|
||||
go generate -mod=vendor -v ./...
|
||||
mkdir /out
|
||||
git ls-files -m --others -- ':!vendor' '**/*.pb.go' | tar -cf - --files-from - | tar -C /out -xf -
|
||||
find github.com/docker/buildx -name '*.proto' -o -name vendor -prune -false | xargs \
|
||||
protoc --go_out=/out --go-grpc_out=require_unimplemented_servers=false:/out
|
||||
EOT
|
||||
|
||||
FROM scratch AS update
|
||||
COPY --from=generated /out /
|
||||
COPY --from=generated /out/github.com/docker/buildx /
|
||||
|
||||
FROM base AS validate
|
||||
FROM gobuild-base AS validate
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=bind,from=generated,source=/out,target=/generated-files <<EOT
|
||||
--mount=type=bind,from=update,target=/generated-files <<EOT
|
||||
set -e
|
||||
git add -A
|
||||
if [ "$(ls -A /generated-files)" ]; then
|
||||
|
Reference in New Issue
Block a user