generate-files.Dockerfile 2.2 KB

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