Skip to content

Commit 7daaa00

Browse files
committed
hack: generated files update and validation
Adds a Dockerfile and make targets to update and validate generated files (proto, seccomp default profile) Signed-off-by: CrazyMax <[email protected]>
1 parent f1ca793 commit 7daaa00

3 files changed

Lines changed: 88 additions & 1 deletion

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
name: Create matrix
7474
id: scripts
7575
run: |
76-
scripts=$(jq -ncR '[inputs]' <<< "$(ls -I .validate -I all -I default -I dco -I golangci-lint.yml -I yamllint.yaml -A ./hack/validate/)")
76+
scripts=$(cd ./hack/validate && jq -nc '$ARGS.positional - ["all", "default", "dco"] | map(select(test("[.]")|not)) + ["generate-files"]' --args *)
7777
echo "matrix=$scripts" >> $GITHUB_OUTPUT
7878
-
7979
name: Show matrix

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ test-unit: build ## run the unit tests
214214
validate: build ## validate DCO, Seccomp profile generation, gofmt,\n./pkg/ isolation, golint, tests, tomls, go vet and vendor
215215
$(DOCKER_RUN_DOCKER) hack/validate/all
216216

217+
validate-generate-files:
218+
$(BUILD_CMD) --target "validate" \
219+
--output "type=cacheonly" \
220+
--file "./hack/dockerfiles/generate-files.Dockerfile" .
221+
217222
validate-%: build ## validate specific check
218223
$(DOCKER_RUN_DOCKER) hack/validate/$*
219224

@@ -235,3 +240,12 @@ swagger-docs: ## preview the API documentation
235240
-e 'REDOC_OPTIONS=hide-hostname="true" lazy-rendering' \
236241
-p $(SWAGGER_DOCS_PORT):80 \
237242
bfirsh/redoc:1.14.0
243+
244+
.PHONY: generate-files
245+
generate-files:
246+
$(eval $@_TMP_OUT := $(shell mktemp -d -t moby-output.XXXXXXXXXX))
247+
$(BUILD_CMD) --target "update" \
248+
--output "type=local,dest=$($@_TMP_OUT)" \
249+
--file "./hack/dockerfiles/generate-files.Dockerfile" .
250+
cp -R "$($@_TMP_OUT)"/. .
251+
rm -rf "$($@_TMP_OUT)"/*
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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

Comments
 (0)