Skip to content

Commit 6a524aa

Browse files
committed
Add "dev" builds of buildkit
Clamped to officially update once per week, but written such that a BUILDKIT_COMMIT build-arg can build any commit.
1 parent c6deafb commit 6a524aa

File tree

7 files changed

+167
-8
lines changed

7 files changed

+167
-8
lines changed

.libs/git.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,49 @@ github-file-commit() {
8585
unix: ($unix | tonumber),
8686
}'
8787
}
88+
89+
github-clamp-commit() {
90+
local repo="$1" # "containerd/containerd"
91+
local date="${2:-last monday 00:00:00}" # something date(1) can parse
92+
local ref="${3:-HEAD}" # ref to start walking backwards from
93+
94+
local clampUnix
95+
clampUnix="$(date --utc --date "$date" '+%s')" || return 1
96+
97+
local commit= date unix
98+
while [ -z "$commit" ]; do
99+
local commits
100+
commits="$(
101+
wget -qO- --header 'Accept: application/json' "https://github.com/$repo/commits/$ref.atom" \
102+
| jq -r '
103+
.payload.commitGroups[].commits[]
104+
| first([ .committedDate, .authoredDate ] | sort | reverse[]) as $date
105+
| "\(.oid) \($date)"
106+
| @sh
107+
'
108+
)"
109+
eval "local commitDates=( $commits ) commitDate"
110+
[ "${#commitDates[@]}" -gt 0 ] || return 1 # TODO error message?
111+
for commitDate in "${commitDates[@]}"; do
112+
ref="${commitDate%%[[:space:]]*}"
113+
date="${commitDate#$ref[[:space:]]}"
114+
[ "$ref" != "$date" ] || return 1 # TODO error message?
115+
unix="$(date --utc --date "$date" '+%s')" || return 1 # TODO error message?
116+
if [ "$unix" -le "$clampUnix" ]; then
117+
commit="$ref"
118+
break 2
119+
fi
120+
done
121+
done
122+
[ -n "$commit" ] || return 1 # TODO error message?
123+
[ -n "$date" ] || return 1
124+
[ -n "$unix" ] || return 1
125+
126+
echo >&2 "github $repo: $commit ($date -- @$unix)"
127+
128+
jq -nc --arg commit "$commit" --arg date "$date" --arg unix "$unix" '{
129+
version: $commit,
130+
$date,
131+
unix: ($unix | tonumber),
132+
}'
133+
}

buildkit/Dockerfile.dev

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#
2+
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
3+
#
4+
# PLEASE DO NOT EDIT IT DIRECTLY.
5+
#
6+
7+
FROM --platform=$BUILDPLATFORM golang:1.22 AS build
8+
9+
# https://github.com/moby/buildkit/commits/HEAD
10+
ARG BUILDKIT_COMMIT=787d9d078a3c4083d5f69f51a228151d61f969fe
11+
# https://github.com/moby/buildkit/tree/787d9d078a3c4083d5f69f51a228151d61f969fe -- 2024-11-23T12:49:46.000+01:00 (@1732362586)
12+
ENV BUILDKIT_COMMIT $BUILDKIT_COMMIT
13+
14+
COPY \
15+
argsescaped.patch \
16+
containerd-arm64-v8.patch \
17+
git-no-submodules.patch \
18+
mips64le.patch \
19+
noclip.patch \
20+
nolint.patch \
21+
/tmp/buildkit-patches/
22+
23+
WORKDIR /app
24+
25+
RUN set -eux; \
26+
git init --quiet; \
27+
git config advice.detachedHead false; \
28+
git fetch --depth 1 'https://github.com/moby/buildkit.git' "$BUILDKIT_COMMIT:"; \
29+
git checkout FETCH_HEAD; \
30+
for patch in /tmp/buildkit-patches/*.patch; do \
31+
git apply --verbose "$patch"; \
32+
done; \
33+
git diff --color
34+
35+
ENV CGO_ENABLED 0
36+
37+
ARG TARGETOS TARGETARCH TARGETVARIANT
38+
ENV GOOS=$TARGETOS GOARCH=$TARGETARCH VARIANT=$TARGETVARIANT
39+
40+
RUN set -eux; \
41+
case "$GOARCH/$VARIANT" in \
42+
amd64/*) export GOAMD64="$VARIANT" ;; \
43+
arm/*) export GOARM="${VARIANT#v}" ;; \
44+
arm64/v8) ;; \
45+
*) [ -z "$VARIANT" ] ;; \
46+
esac; \
47+
go env | grep -E 'OS=|ARCH=|AMD64=|ARM64=|ARM='; \
48+
\
49+
# https://github.com/moby/buildkit/blob/v0.13.2/Dockerfile#L93
50+
pkg='github.com/moby/buildkit'; \
51+
ldflags=" \
52+
-d -w \
53+
-X '$pkg/version.Version=dev-tianon' \
54+
-X '$pkg/version.Revision=$BUILDKIT_COMMIT+tianon-patches' \
55+
-X '$pkg/version.Package=$pkg' \
56+
"; \
57+
go build -o /buildkitd -trimpath -ldflags "$ldflags" ./cmd/buildkitd; \
58+
go build -o /buildctl -trimpath -ldflags "$ldflags" ./cmd/buildctl; \
59+
\
60+
# https://github.com/moby/buildkit/blob/v0.14.0/frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile#L21
61+
pkg='github.com/moby/buildkit/frontend/dockerfile/cmd/dockerfile-frontend'; \
62+
ldflags=" \
63+
-d -w \
64+
-X '$pkg/version.Version=dev-tianon' \
65+
-X '$pkg/version.Revision=$BUILDKIT_COMMIT+tianon-patches' \
66+
-X '$pkg/version.Package=$pkg' \
67+
"; \
68+
go build -o /dockerfile-frontend -trimpath -ldflags "$ldflags" ./frontend/dockerfile/cmd/dockerfile-frontend
69+
70+
FROM --platform=$TARGETPLATFORM infosiftr/moby
71+
72+
RUN set -eux; \
73+
apt-get update; \
74+
apt-get install -y --no-install-recommends git; \
75+
rm -rf /var/lib/apt/lists/*
76+
77+
COPY --from=build --link /buildkitd /buildctl /dockerfile-frontend /usr/local/bin/
78+
COPY buildkitd-entrypoint.sh /usr/local/bin/
79+
80+
VOLUME /var/lib/buildkit
81+
82+
# https://github.com/docker/buildx/issues/484#issuecomment-749352728
83+
ENV BUILDKIT_STEP_LOG_MAX_SIZE -1
84+
ENV BUILDKIT_STEP_LOG_MAX_SPEED -1
85+
86+
# https://github.com/moby/buildkit/blob/v0.14.0/frontend/gateway/gateway.go#L309
87+
# https://github.com/moby/buildkit/blob/v0.14.0/frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile#L35-L36
88+
LABEL moby.buildkit.frontend.network.none="true"
89+
LABEL moby.buildkit.frontend.caps="moby.buildkit.frontend.inputs,moby.buildkit.frontend.subrequests,moby.buildkit.frontend.contexts"
90+
91+
ENTRYPOINT ["buildkitd-entrypoint.sh"]
92+
CMD []

buildkit/Dockerfile.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ FROM --platform=$BUILDPLATFORM golang:{{ .go.version }} AS build
44

55
{{ if env.variant == "dev" then ( -}}
66
# https://github.com/moby/buildkit/commits/HEAD
7-
# https://github.com/moby/buildkit/tree/{{ .version }}
87
ARG BUILDKIT_COMMIT={{ .version }}
8+
# https://github.com/moby/buildkit/tree/{{ .version }} -- {{ .date }} (@{{ .unix | tostring }})
99
ENV BUILDKIT_COMMIT $BUILDKIT_COMMIT
1010
{{ ) else ( -}}
1111
# https://github.com/moby/buildkit/releases

buildkit/gsl.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ exec jq -r '
2323
Builder: "buildkit",
2424
},
2525
(
26-
(
26+
.dev as $dev
27+
| (
2728
[
2829
.variants[] as $variant
2930
| {
@@ -48,7 +49,14 @@ exec jq -r '
4849
| .value as $version
4950
| .value = (
5051
if $variant == "dev" then
51-
[]
52+
[
53+
$dev.unix
54+
| strftime("dev-%Y%m%d-%H%M%S"),
55+
strftime("dev-%Y%m%d"),
56+
"dev-\($version)",
57+
"dev-\($version[:7])",
58+
empty
59+
]
5260
else
5361
$version
5462
| [ scan("(?:[.-]+|^)[^.-]*") ]

buildkit/versions.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"",
1111
"rc",
1212
"0.16",
13-
"0.13"
13+
"0.13",
14+
"dev"
1415
],
1516
"rc": {
1617
"commit": "db6989ab182b94eebac1c18f12ddd6d52a8c0ef4",
@@ -38,5 +39,13 @@
3839
"go": {
3940
"version": "1.21"
4041
}
42+
},
43+
"dev": {
44+
"version": "787d9d078a3c4083d5f69f51a228151d61f969fe",
45+
"date": "2024-11-23T12:49:46.000+01:00",
46+
"unix": 1732362586,
47+
"go": {
48+
"version": "1.22"
49+
}
4150
}
4251
}

buildkit/versions.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ variants=(
1414
'0.16'
1515
'0.13'
1616

17-
# TODO add this back when I figure out a clean way to do something more akin to a "weekly snapshot" or something so it doesn't have an update every single day
18-
#'dev'
17+
'dev'
1918
)
2019

2120
json='{}'
@@ -52,7 +51,7 @@ for variant in "${variants[@]}"; do
5251
;;
5352

5453
dev)
55-
bk="$(git-ref-commit 'https://github.com/moby/buildkit.git' 'HEAD')"
54+
bk="$(github-clamp-commit 'moby/buildkit')"
5655
;;
5756

5857
*) echo >&2 "error: unknown variant: '$variant'"; exit 1 ;;

containerd/versions.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ variants=(
1616
'1.7'
1717
'1.6'
1818

19-
# TODO add this when I figure out a clean way to do something more akin to a "weekly snapshot" or something so it doesn't have an update every single day (see also "buildkit")
19+
# TODO update Dockerfile.template with the necessary bits to build containerd from source (see buildkit/Dockerfile.template)
2020
#'dev'
2121
)
2222

@@ -81,6 +81,11 @@ for variant in "${variants[@]}"; do
8181
versions_hooks+=( hook_no-prereleases )
8282
;;
8383
84+
(dev)
85+
github-clamp-commit 'containerd/containerd'
86+
exit # kill the subshell (no "git-tags" invocation)
87+
;;
88+
8489
(*) echo >&2 "error: unknown variant: '$variant'"; exit 1 ;;
8590
esac
8691

0 commit comments

Comments
 (0)