generate-files.Dockerfile 2.3 KB

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