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