Skip to content

Commit d31e77f

Browse files
committed
hack: doctoc bake target
Signed-off-by: CrazyMax <[email protected]>
1 parent c888041 commit d31e77f

File tree

5 files changed

+60
-30
lines changed

5 files changed

+60
-30
lines changed

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ validate-authors:
5050
validate-generated-files:
5151
./hack/validate-generated-files
5252

53+
.PHONY: validate-doctoc
54+
validate-doctoc:
55+
$(BUILDX_CMD) bake validate-doctoc
56+
5357
.PHONY: validate-all
54-
validate-all: test lint validate-vendor validate-generated-files
58+
validate-all: test lint validate-vendor validate-generated-files validate-doctoc
5559

5660
.PHONY: vendor
5761
vendor:
@@ -68,3 +72,7 @@ generated-files:
6872
.PHONY: authors
6973
authors:
7074
$(BUILDX_CMD) bake authors
75+
76+
.PHONY: doctoc
77+
doctoc:
78+
$(BUILDX_CMD) bake doctoc

docker-bake.hcl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@ variable "GO_VERSION" {
66
default = null
77
}
88

9+
variable "NODE_VERSION" {
10+
default = null
11+
}
12+
913
target "_common" {
1014
args = {
1115
ALPINE_VERSION = ALPINE_VERSION
1216
GO_VERSION = GO_VERSION
17+
NODE_VERSION = NODE_VERSION
1318
BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1
1419
}
1520
}
1621

1722
group "validate" {
18-
targets = ["lint", "validate-vendor"]
23+
targets = ["lint", "validate-vendor", "validate-doctoc"]
1924
}
2025

2126
target "lint" {
@@ -31,6 +36,13 @@ target "validate-vendor" {
3136
output = ["type=cacheonly"]
3237
}
3338

39+
target "validate-doctoc" {
40+
inherits = ["_common"]
41+
dockerfile = "./hack/dockerfiles/doctoc.Dockerfile"
42+
target = "validate-toc"
43+
output = ["type=cacheonly"]
44+
}
45+
3446
target "validate-authors" {
3547
inherits = ["_common"]
3648
dockerfile = "./hack/dockerfiles/authors.Dockerfile"
@@ -45,6 +57,13 @@ target "vendor" {
4557
output = ["."]
4658
}
4759

60+
target "doctoc" {
61+
inherits = ["_common"]
62+
dockerfile = "./hack/dockerfiles/doctoc.Dockerfile"
63+
target = "update"
64+
output = ["."]
65+
}
66+
4867
target "authors" {
4968
inherits = ["_common"]
5069
dockerfile = "./hack/dockerfiles/authors.Dockerfile"

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/validate-generated-files

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,3 @@ buildxCmd build \
88
--output "type=cacheonly" \
99
--file "./hack/dockerfiles/generated-files.Dockerfile" \
1010
.
11-
12-
buildxCmd build \
13-
--target "validate-toc" \
14-
--output "type=cacheonly" \
15-
--file "./hack/dockerfiles/generated-files.Dockerfile" \
16-
.

0 commit comments

Comments
 (0)