Skip to content

Commit 39964a6

Browse files
authored
Merge pull request moby#3664 from crazy-max/bake-validate
Bake workflow for validation
2 parents 722235f + 8eb972c commit 39964a6

16 files changed

+260
-173
lines changed

.github/workflows/validate.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,28 @@ env:
2020
SETUP_BUILDKIT_IMAGE: "moby/buildkit:latest"
2121

2222
jobs:
23+
prepare:
24+
runs-on: ubuntu-20.04
25+
outputs:
26+
targets: ${{ steps.targets.outputs.matrix }}
27+
steps:
28+
-
29+
name: Checkout
30+
uses: actions/checkout@v3
31+
-
32+
name: Matrix
33+
id: targets
34+
run: |
35+
echo "matrix=$(docker buildx bake validate --print | jq -cr '.group.validate.targets')" >> $GITHUB_OUTPUT
36+
2337
validate:
2438
runs-on: ubuntu-20.04
39+
needs:
40+
- prepare
2541
strategy:
2642
fail-fast: false
2743
matrix:
28-
include:
29-
- script: ./hack/lint
30-
- script: ./hack/validate-vendor
31-
- script: ./hack/validate-generated-files
32-
- script: ./hack/validate-shfmt
44+
target: ${{ fromJson(needs.prepare.outputs.targets) }}
3345
steps:
3446
-
3547
name: Checkout
@@ -42,6 +54,7 @@ jobs:
4254
driver-opts: image=${{ env.SETUP_BUILDKIT_IMAGE }}
4355
buildkitd-flags: --debug
4456
-
45-
name: Run
46-
run: |
47-
${{ matrix.script }}
57+
name: Validate
58+
uses: docker/bake-action@v2
59+
with:
60+
targets: ${{ matrix.target }}

Makefile

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,78 @@
11
prefix=/usr/local
22
bindir=$(prefix)/bin
33

4-
binaries: FORCE
4+
export BUILDX_CMD ?= docker buildx
5+
6+
.PHONY: binaries
7+
binaries:
58
hack/binaries
69

7-
images: FORCE
10+
.PHONY: images
11+
images:
812
# moby/buildkit:local and moby/buildkit:local-rootless are created on Docker
913
hack/images local moby/buildkit
1014
TARGET=rootless hack/images local moby/buildkit
1115

12-
install: FORCE
16+
.PHONY: install
17+
install:
1318
mkdir -p $(DESTDIR)$(bindir)
1419
install bin/* $(DESTDIR)$(bindir)
1520

16-
clean: FORCE
21+
.PHONY: clean
22+
clean:
1723
rm -rf ./bin
1824

25+
.PHONY: test
1926
test:
2027
./hack/test integration gateway dockerfile
2128

29+
.PHONY: lint
2230
lint:
23-
./hack/lint
31+
$(BUILDX_CMD) bake lint
2432

33+
.PHONY: validate-vendor
2534
validate-vendor:
26-
./hack/validate-vendor
35+
$(BUILDX_CMD) bake validate-vendor
2736

37+
.PHONY: validate-shfmt
2838
validate-shfmt:
29-
./hack/validate-shfmt
39+
$(BUILDX_CMD) bake validate-shfmt
3040

41+
.PHONY: shfmt
3142
shfmt:
32-
./hack/shfmt
43+
$(BUILDX_CMD) bake shfmt
44+
45+
.PHONY: validate-authors
46+
validate-authors:
47+
$(BUILDX_CMD) bake validate-authors
3348

49+
.PHONY: validate-generated-files
3450
validate-generated-files:
35-
./hack/validate-generated-files
51+
$(BUILDX_CMD) bake validate-generated-files
3652

37-
validate-all: test lint validate-vendor validate-generated-files
53+
.PHONY: validate-doctoc
54+
validate-doctoc:
55+
$(BUILDX_CMD) bake validate-doctoc
3856

57+
.PHONY: validate-all
58+
validate-all: test lint validate-vendor validate-generated-files validate-doctoc
59+
60+
.PHONY: vendor
3961
vendor:
40-
./hack/update-vendor
62+
$(eval $@_TMP_OUT := $(shell mktemp -d -t buildkit-output.XXXXXXXXXX))
63+
$(BUILDX_CMD) bake --set "*.output=type=local,dest=$($@_TMP_OUT)" vendor
64+
rm -rf ./vendor
65+
cp -R "$($@_TMP_OUT)"/out/* .
66+
rm -rf "$($@_TMP_OUT)"/
4167

68+
.PHONY: generated-files
4269
generated-files:
43-
./hack/update-generated-files
70+
$(BUILDX_CMD) bake generated-files
71+
72+
.PHONY: authors
73+
authors:
74+
$(BUILDX_CMD) bake authors
4475

45-
.PHONY: vendor generated-files test binaries images install clean lint validate-all validate-vendor validate-generated-files
46-
FORCE:
76+
.PHONY: doctoc
77+
doctoc:
78+
$(BUILDX_CMD) bake doctoc

docker-bake.hcl

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
variable "ALPINE_VERSION" {
2+
default = null
3+
}
4+
5+
variable "GO_VERSION" {
6+
default = null
7+
}
8+
9+
variable "NODE_VERSION" {
10+
default = null
11+
}
12+
13+
target "_common" {
14+
args = {
15+
ALPINE_VERSION = ALPINE_VERSION
16+
GO_VERSION = GO_VERSION
17+
NODE_VERSION = NODE_VERSION
18+
BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1
19+
}
20+
}
21+
22+
group "validate" {
23+
targets = ["lint", "validate-vendor", "validate-doctoc", "validate-generated-files", "validate-shfmt"]
24+
}
25+
26+
target "lint" {
27+
inherits = ["_common"]
28+
dockerfile = "./hack/dockerfiles/lint.Dockerfile"
29+
output = ["type=cacheonly"]
30+
}
31+
32+
target "validate-vendor" {
33+
inherits = ["_common"]
34+
dockerfile = "./hack/dockerfiles/vendor.Dockerfile"
35+
target = "validate"
36+
output = ["type=cacheonly"]
37+
}
38+
39+
target "validate-generated-files" {
40+
inherits = ["_common"]
41+
dockerfile = "./hack/dockerfiles/generated-files.Dockerfile"
42+
target = "validate"
43+
output = ["type=cacheonly"]
44+
}
45+
46+
target "validate-shfmt" {
47+
inherits = ["_common"]
48+
dockerfile = "./hack/dockerfiles/shfmt.Dockerfile"
49+
target = "validate"
50+
output = ["type=cacheonly"]
51+
}
52+
53+
target "validate-doctoc" {
54+
inherits = ["_common"]
55+
dockerfile = "./hack/dockerfiles/doctoc.Dockerfile"
56+
target = "validate-toc"
57+
output = ["type=cacheonly"]
58+
}
59+
60+
target "validate-authors" {
61+
inherits = ["_common"]
62+
dockerfile = "./hack/dockerfiles/authors.Dockerfile"
63+
target = "validate"
64+
output = ["type=cacheonly"]
65+
}
66+
67+
target "vendor" {
68+
inherits = ["_common"]
69+
dockerfile = "./hack/dockerfiles/vendor.Dockerfile"
70+
target = "update"
71+
output = ["."]
72+
}
73+
74+
target "generated-files" {
75+
inherits = ["_common"]
76+
dockerfile = "./hack/dockerfiles/generated-files.Dockerfile"
77+
target = "update"
78+
output = ["."]
79+
}
80+
81+
target "shfmt" {
82+
inherits = ["_common"]
83+
dockerfile = "./hack/dockerfiles/shfmt.Dockerfile"
84+
target = "update"
85+
output = ["."]
86+
}
87+
88+
target "doctoc" {
89+
inherits = ["_common"]
90+
dockerfile = "./hack/dockerfiles/doctoc.Dockerfile"
91+
target = "update"
92+
output = ["."]
93+
}
94+
95+
target "authors" {
96+
inherits = ["_common"]
97+
dockerfile = "./hack/dockerfiles/authors.Dockerfile"
98+
target = "update"
99+
output = ["."]
100+
}

hack/dockerfiles/authors.Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# syntax=docker/dockerfile-upstream:master
2+
3+
ARG ALPINE_VERSION=3.17
4+
5+
FROM alpine:${ALPINE_VERSION} AS gen
6+
RUN apk add --no-cache git
7+
WORKDIR /src
8+
RUN --mount=type=bind,target=. <<EOT
9+
set -e
10+
mkdir /out
11+
# see also ".mailmap" for how email addresses and names are deduplicated
12+
{
13+
echo "# This file lists all individuals having contributed content to the repository."
14+
echo "# For how it is generated, see hack/dockerfiles/authors.Dockerfile."
15+
echo
16+
git log --format='%aN <%aE>' | LC_ALL=C.UTF-8 sort -uf
17+
} > /out/AUTHORS
18+
cat /out/AUTHORS
19+
EOT
20+
21+
FROM scratch AS update
22+
COPY --from=gen /out /
23+
24+
FROM gen AS validate
25+
RUN --mount=type=bind,target=.,rw <<EOT
26+
set -e
27+
git add -A
28+
cp -rf /out/* .
29+
if [ -n "$(git status --porcelain -- AUTHORS)" ]; then
30+
echo >&2 'ERROR: Authors result differs. Please update with "make authors"'
31+
git status --porcelain -- AUTHORS
32+
exit 1
33+
fi
34+
EOT

hack/dockerfiles/doctoc.Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# syntax=docker/dockerfile-upstream:master
2+
3+
ARG NODE_VERSION=19
4+
5+
FROM node:${NODE_VERSION}-alpine AS base
6+
RUN apk add --no-cache git
7+
WORKDIR /src
8+
9+
FROM base AS doctoc
10+
RUN npm install -g doctoc
11+
RUN --mount=type=bind,source=README.md,target=README.md,rw <<EOT
12+
set -e
13+
doctoc README.md
14+
mkdir /out
15+
cp README.md /out/
16+
EOT
17+
18+
FROM scratch AS update
19+
COPY --from=doctoc /out /
20+
21+
FROM base AS validate-toc
22+
RUN --mount=type=bind,target=.,rw \
23+
--mount=type=bind,from=doctoc,source=/out/README.md,target=./README.md <<EOT
24+
set -e
25+
diff=$(git status --porcelain -- 'README.md')
26+
if [ -n "$diff" ]; then
27+
echo >&2 'ERROR: The result of "doctoc" differs. Please update with "make doctoc"'
28+
echo "$diff"
29+
exit 1
30+
fi
31+
EOT

hack/dockerfiles/generated-files.Dockerfile

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# syntax=docker/dockerfile-upstream:master
22

33
ARG GO_VERSION="1.20"
4-
ARG NODE_VERSION="19"
54
ARG PROTOC_VERSION="3.11.4"
65

76
# protoc is dynamically linked to glibc so can't use alpine base
@@ -54,24 +53,3 @@ RUN --mount=type=bind,target=.,rw \
5453
exit 1
5554
fi
5655
EOT
57-
58-
FROM node:${NODE_VERSION}-alpine AS doctoc
59-
RUN npm install -g doctoc
60-
WORKDIR /buildkit
61-
RUN --mount=type=bind,target=.,rw <<EOT
62-
doctoc README.md
63-
mkdir /out
64-
cp README.md /out/
65-
EOT
66-
67-
FROM base AS validate-toc
68-
RUN --mount=type=bind,target=.,rw \
69-
--mount=type=bind,from=doctoc,source=/out/README.md,target=./README.md <<EOT
70-
set -e
71-
diff=$(git status --porcelain -- 'README.md')
72-
if [ -n "$diff" ]; then
73-
echo >&2 'ERROR: The result of "doctoc" differs. Please update with "doctoc README.md"'
74-
echo "$diff"
75-
exit 1
76-
fi
77-
EOT

hack/dockerfiles/shfmt.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# syntax=docker/dockerfile-upstream:master
2+
23
FROM mvdan/shfmt:v3.1.2-alpine AS shfmt
34
WORKDIR /src
45
ARG SHFMT_FLAGS="-i 2 -ci"

hack/dockerfiles/vendor.Dockerfile

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,36 @@
22

33
ARG GO_VERSION=1.20
44

5-
FROM golang:${GO_VERSION}-alpine AS vendored
6-
RUN apk add --no-cache git
5+
FROM golang:${GO_VERSION}-alpine AS base
6+
RUN apk add --no-cache git rsync
77
WORKDIR /src
8-
RUN --mount=target=/src,rw \
9-
--mount=target=/go/pkg/mod,type=cache \
10-
go mod tidy && go mod vendor && \
11-
mkdir /out && cp -r go.mod go.sum vendor /out
8+
9+
FROM base AS vendored
10+
RUN --mount=target=/context \
11+
--mount=target=.,type=tmpfs \
12+
--mount=target=/go/pkg/mod,type=cache <<EOT
13+
set -e
14+
rsync -a /context/. .
15+
go mod tidy
16+
go mod vendor
17+
mkdir /out
18+
cp -r go.mod go.sum vendor /out
19+
EOT
1220

1321
FROM scratch AS update
1422
COPY --from=vendored /out /out
1523

1624
FROM vendored AS validate
17-
RUN --mount=target=.,rw \
18-
git add -A && \
19-
rm -rf vendor && \
20-
cp -rf /out/* . && \
21-
./hack/validate-vendor check
25+
RUN --mount=target=/context \
26+
--mount=target=.,type=tmpfs <<EOT
27+
set -e
28+
rsync -a /context/. .
29+
git add -A
30+
rm -rf vendor
31+
cp -rf /out/* .
32+
if [ -n "$(git status --porcelain -- go.mod go.sum vendor)" ]; then
33+
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "make vendor"'
34+
git status --porcelain -- go.mod go.sum vendor
35+
exit 1
36+
fi
37+
EOT

0 commit comments

Comments
 (0)