| 1 |
# syntax=docker/dockerfile:1 |
| 2 |
|
| 3 |
ARG GO_VERSION=1.24.9 |
| 4 |
ARG BASE_DEBIAN_DISTRO="bookworm" |
| 5 |
ARG PROTOC_VERSION=3.11.4 |
| 6 |
|
| 7 |
# protoc is dynamically linked to glibc so can't use alpine base |
| 8 |
FROM golang:${GO_VERSION}-${BASE_DEBIAN_DISTRO} AS base |
| 9 |
RUN apt-get update && apt-get --no-install-recommends install -y git unzip |
| 10 |
ARG PROTOC_VERSION |
| 11 |
ARG TARGETOS |
| 12 |
ARG TARGETARCH |
| 13 |
ENV GOTOOLCHAIN=local |
| 14 |
RUN <<EOT |
| 15 |
set -e |
| 16 |
arch=$(echo $TARGETARCH | sed -e s/amd64/x86_64/ -e s/arm64/aarch_64/) |
| 17 |
wget -q https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${TARGETOS}-${arch}.zip |
| 18 |
unzip protoc-${PROTOC_VERSION}-${TARGETOS}-${arch}.zip -d /usr/local |
| 19 |
EOT |
| 20 |
WORKDIR /go/src/github.com/docker/docker |
| 21 |
|
| 22 |
FROM base AS src |
| 23 |
WORKDIR /out |
| 24 |
COPY . . |
| 25 |
RUN <<EOT |
| 26 |
set -ex |
| 27 |
git config --global user.email "[email protected]" |
| 28 |
git config --global user.name "moby" |
| 29 |
git init . |
| 30 |
git add . |
| 31 |
git commit -m 'init' |
| 32 |
EOT |
| 33 |
|
| 34 |
FROM base AS tools |
| 35 |
RUN --mount=from=src,source=/out,target=.,rw \ |
| 36 |
--mount=type=cache,target=/root/.cache/go-build <<EOT |
| 37 |
set -ex |
| 38 |
./hack/with-go-mod.sh go install -v -mod=vendor -modfile=vendor.mod \ |
| 39 |
github.com/gogo/protobuf/protoc-gen-gogo \ |
| 40 |
github.com/gogo/protobuf/protoc-gen-gogofaster \ |
| 41 |
github.com/gogo/protobuf/protoc-gen-gogoslick \ |
| 42 |
github.com/golang/protobuf/protoc-gen-go |
| 43 |
./hack/with-go-mod.sh go build -v -mod=vendor -modfile=vendor.mod \ |
| 44 |
-o /usr/bin/pluginrpc-gen \ |
| 45 |
./pkg/plugins/pluginrpc-gen |
| 46 |
EOT |
| 47 |
|
| 48 |
FROM tools AS generated |
| 49 |
ENV GO111MODULE=off |
| 50 |
RUN --mount=from=src,source=/out,target=.,rw <<EOT |
| 51 |
set -ex |
| 52 |
go generate -v ./... |
| 53 |
mkdir /out |
| 54 |
git ls-files -m --others -- ':!vendor' 'profiles/seccomp/default.json' '**/*.pb.go' | tar -cf - --files-from - | tar -C /out -xf - |
| 55 |
EOT |
| 56 |
|
| 57 |
FROM scratch AS update |
| 58 |
COPY --from=generated /out / |
| 59 |
|
| 60 |
FROM base AS validate |
| 61 |
RUN --mount=from=src,source=/out,target=.,rw \ |
| 62 |
--mount=type=bind,from=generated,source=/out,target=/generated-files <<EOT |
| 63 |
set -e |
| 64 |
git add -A |
| 65 |
if [ "$(ls -A /generated-files)" ]; then |
| 66 |
cp -rf /generated-files/* . |
| 67 |
fi |
| 68 |
diff=$(git status --porcelain -- ':!vendor' 'profiles/seccomp/default.json' '**/*.pb.go') |
| 69 |
if [ -n "$diff" ]; then |
| 70 |
echo >&2 'ERROR: The result of "go generate" differs. Please update with "make generate-files"' |
| 71 |
echo "$diff" |
| 72 |
exit 1 |
| 73 |
fi |
| 74 |
EOT |