1
0
mirror of https://github.com/moby/buildkit.git synced 2025-04-18 18:04:03 +03:00

hack: aggregate protobuf includes to a separate stage

This moves the aggregation of the various protobuf includes (binaries
and include files) to a separate stage so the files can be retrieved
more easily by external tools.

Since the canonical way of retrieving the protobuf dependencies is to
use this file and the dependencies can be quite complicated to retrieve,
this makes it easier for outside contributors to retrieve the
dependencies and copy them into their own repositories.

This was possible before by using the `tools` target, but that would
also include the entire `golang` image. Now you can retrieve just the
`protobuf` target to get the binaries and the include files.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
Jonathan A. Sternberg 2025-04-14 11:00:14 -05:00
parent 40a5c2d56d
commit 4fc3a2d435
No known key found for this signature in database
GPG Key ID: 6603D4B96394F6B1

View File

@ -43,7 +43,8 @@ RUN --mount=type=bind,source=go.mod,target=/app/go.mod \
set -e
mkdir -p /opt/vtprotobuf
go mod download github.com/planetscale/vtprotobuf
cp -r $(go list -m -f='{{.Dir}}' github.com/planetscale/vtprotobuf)/include /opt/vtprotobuf
cp -R $(go list -m -f='{{.Dir}}' github.com/planetscale/vtprotobuf)/include /opt/vtprotobuf
chmod -R 0755 /opt/vtprotobuf
EOT
FROM gobuild-base AS vendored
@ -53,6 +54,12 @@ RUN --mount=type=bind,source=vendor,target=/app <<EOT
find . -name '*.proto' | tar -cf - --files-from - | tar -C /opt/vendored/include -xf -
EOT
FROM scratch AS protobuf
COPY --link --from=protoc /opt/protoc /
COPY --link --from=googleapis /opt/googleapis /
COPY --link --from=vtprotobuf /opt/vtprotobuf /
COPY --link --from=vendored /opt/vendored /
FROM gobuild-base AS tools
RUN --mount=type=bind,source=go.mod,target=/app/go.mod \
--mount=type=bind,source=go.sum,target=/app/go.sum \
@ -62,10 +69,7 @@ RUN --mount=type=bind,source=go.mod,target=/app/go.mod \
github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto \
google.golang.org/grpc/cmd/protoc-gen-go-grpc \
google.golang.org/protobuf/cmd/protoc-gen-go
COPY --link --from=protoc /opt/protoc /usr/local
COPY --link --from=googleapis /opt/googleapis /usr/local
COPY --link --from=vtprotobuf /opt/vtprotobuf /usr/local
COPY --link --from=vendored /opt/vendored /usr/local
COPY --link --from=protobuf / /usr/local
FROM tools AS generated
RUN --mount=type=bind,target=github.com/moby/buildkit <<EOT