Debian Codegraph @

hack/dockerfiles/generated-files.Dockerfile

raw
1 # syntax=docker/dockerfile:1
2
3 ARG GO_VERSION=1.23
4 ARG PROTOC_VERSION=3.11.4
5
6 FROM golang:${GO_VERSION} AS base
7
8 FROM base AS protoc
9 RUN apt-get update && apt-get --no-install-recommends install -y 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 /opt/protoc
18 rm -f /opt/protoc/readme.md
19 EOT
20
21 FROM base AS protoc-libs
22 WORKDIR /app
23 RUN --mount=type=bind,source=go.mod,target=/app/go.mod \
24 --mount=type=bind,source=go.sum,target=/app/go.sum \
25 --mount=type=cache,target=/root/.cache \
26 --mount=type=cache,target=/go/pkg/mod <<EOT
27 set -e
28 mkdir -p /opt/protoc
29 go mod download github.com/planetscale/vtprotobuf
30 cp -r $(go list -m -f='{{.Dir}}' github.com/planetscale/vtprotobuf)/include /opt/protoc
31 EOT
32
33 FROM base AS tools
34 WORKDIR /app
35 RUN --mount=type=bind,source=go.mod,target=/app/go.mod \
36 --mount=type=bind,source=go.sum,target=/app/go.sum \
37 --mount=type=cache,target=/root/.cache \
38 --mount=type=cache,target=/go/pkg/mod \
39 go install \
40 github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto \
41 google.golang.org/protobuf/cmd/protoc-gen-go
42 COPY --link --from=protoc /opt/protoc /usr/local
43 COPY --link --from=protoc-libs /opt/protoc /usr/local
44
45 FROM tools AS generate
46 RUN --mount=target=github.com/tonistiigi/fsutil \
47 --mount=type=cache,target=/root/.cache \
48 --mount=type=cache,target=/go/pkg/mod <<EOT
49 set -e
50 mkdir /out
51 find github.com/tonistiigi/fsutil -name '*.proto' | xargs protoc --go_out=/out --go-vtproto_out=/out
52 EOT
53
54 FROM scratch AS update
55 COPY --link --from=generate /out/github.com/tonistiigi/fsutil/ /
56
57 FROM tools AS validate
58 WORKDIR /app/github.com/tonistiigi/fsutil
59 RUN --mount=target=.,rw \
60 --mount=target=/out,from=update <<EOT
61 set -e
62 git add -A
63 cp -rf /out/* /app/
64 diff=$(git status --porcelain -- **/*.pb.go 2>/dev/null)
65 if [ -n "$diff" ]; then
66 echo >&2 'ERROR: The result of "./hack/validate-generated-files" differs. Please update with "./hack/update-generated-files".'
67 echo "$diff"
68 exit 1
69 fi
70 EOT