Skip to content

Commit 1b721f4

Browse files
committed
hack: bake definition with vendor targets
Signed-off-by: CrazyMax <[email protected]>
1 parent a84cd1c commit 1b721f4

File tree

5 files changed

+80
-65
lines changed

5 files changed

+80
-65
lines changed

Makefile

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,62 @@
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:
2331
./hack/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:
2939
./hack/validate-shfmt
3040

41+
.PHONY: shfmt
3142
shfmt:
3243
./hack/shfmt
3344

45+
.PHONY: validate-generated-files
3446
validate-generated-files:
3547
./hack/validate-generated-files
3648

49+
.PHONY: validate-all
3750
validate-all: test lint validate-vendor validate-generated-files
3851

52+
.PHONY: vendor
3953
vendor:
40-
./hack/update-vendor
54+
$(eval $@_TMP_OUT := $(shell mktemp -d -t buildkit-output.XXXXXXXXXX))
55+
$(BUILDX_CMD) bake --set "*.output=type=local,dest=$($@_TMP_OUT)" vendor
56+
rm -rf ./vendor
57+
cp -R "$($@_TMP_OUT)"/out/* .
58+
rm -rf "$($@_TMP_OUT)"/
4159

60+
.PHONY: generated-files
4261
generated-files:
4362
./hack/update-generated-files
44-
45-
.PHONY: vendor generated-files test binaries images install clean lint validate-all validate-vendor validate-generated-files
46-
FORCE:

docker-bake.hcl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
variable "GO_VERSION" {
2+
default = null
3+
}
4+
5+
target "_common" {
6+
args = {
7+
GO_VERSION = GO_VERSION
8+
BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1
9+
}
10+
}
11+
12+
group "validate" {
13+
targets = ["validate-vendor"]
14+
}
15+
16+
target "validate-vendor" {
17+
inherits = ["_common"]
18+
dockerfile = "./hack/dockerfiles/vendor.Dockerfile"
19+
target = "validate"
20+
output = ["type=cacheonly"]
21+
}
22+
23+
target "vendor" {
24+
inherits = ["_common"]
25+
dockerfile = "./hack/dockerfiles/vendor.Dockerfile"
26+
target = "update"
27+
output = ["."]
28+
}

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

hack/update-vendor

Lines changed: 0 additions & 16 deletions
This file was deleted.

hack/validate-vendor

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)