Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit variants to buildkit (rc, dev, 0.13, for now) #744

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions buildkit/Dockerfile.0.13
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#

FROM --platform=$BUILDPLATFORM golang:1.21 AS build

# https://github.com/moby/buildkit/releases
ENV BUILDKIT_VERSION 0.13.2

COPY \
backport-5072-fetch-tags.patch \
containerd-arm64-v8.patch \
git-no-submodules.patch \
mips64le.patch \
noclip.patch \
/tmp/buildkit-patches/

WORKDIR /app

RUN set -eux; \
git clone --branch "v$BUILDKIT_VERSION" --depth 1 --config advice.detachedHead=false 'https://github.com/moby/buildkit.git' .; \
git apply /tmp/buildkit-patches/*.patch; \
git diff --color

ENV CGO_ENABLED 0

ARG TARGETOS TARGETARCH TARGETVARIANT
ENV GOOS=$TARGETOS GOARCH=$TARGETARCH VARIANT=$TARGETVARIANT

RUN set -eux; \
case "$GOARCH" in \
arm) export GOARM="${VARIANT#v}" ;; \
amd64) export GOAMD64="$VARIANT" ;; \
*) [ -z "$VARIANT" ] ;; \
esac; \
go env | grep -E 'OS=|ARCH=|ARM=|AMD64='; \
\
# https://github.com/moby/buildkit/blob/v0.13.2/Dockerfile#L93
pkg='github.com/moby/buildkit'; \
ldflags=" \
-d -w \
-X '$pkg/version.Version=$BUILDKIT_VERSION-tianon' \
-X '$pkg/version.Revision=v$BUILDKIT_VERSION+tianon-patches' \
-X '$pkg/version.Package=$pkg' \
"; \
go build -o /buildkitd -trimpath -ldflags "$ldflags" ./cmd/buildkitd; \
go build -o /buildctl -trimpath -ldflags "$ldflags" ./cmd/buildctl; \
\
# https://github.com/moby/buildkit/blob/v0.14.0/frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile#L21
pkg='github.com/moby/buildkit/frontend/dockerfile/cmd/dockerfile-frontend'; \
ldflags=" \
-d -w \
-X '$pkg/version.Version=buildkit-$BUILDKIT_VERSION-tianon' \
-X '$pkg/version.Revision=v$BUILDKIT_VERSION+tianon-patches' \
-X '$pkg/version.Package=$pkg' \
"; \
go build -o /dockerfile-frontend -trimpath -ldflags "$ldflags" ./frontend/dockerfile/cmd/dockerfile-frontend

FROM --platform=$TARGETPLATFORM infosiftr/moby

RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends git; \
rm -rf /var/lib/apt/lists/*

COPY --from=build --link /buildkitd /buildctl /dockerfile-frontend /usr/local/bin/
COPY buildkitd-entrypoint.sh /usr/local/bin/

VOLUME /var/lib/buildkit

# https://github.com/docker/buildx/issues/484#issuecomment-749352728
ENV BUILDKIT_STEP_LOG_MAX_SIZE -1
ENV BUILDKIT_STEP_LOG_MAX_SPEED -1

# https://github.com/moby/buildkit/blob/v0.14.0/frontend/gateway/gateway.go#L309
# https://github.com/moby/buildkit/blob/v0.14.0/frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile#L35-L36
LABEL moby.buildkit.frontend.network.none="true"
LABEL moby.buildkit.frontend.caps="moby.buildkit.frontend.inputs,moby.buildkit.frontend.subrequests,moby.buildkit.frontend.contexts"

ENTRYPOINT ["buildkitd-entrypoint.sh"]
CMD []
83 changes: 83 additions & 0 deletions buildkit/Dockerfile.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#

FROM --platform=$BUILDPLATFORM golang:1.21 AS build

# https://github.com/moby/buildkit/releases
ENV BUILDKIT_VERSION 0.14.0-rc2

COPY \
backport-5072-fetch-tags.patch \
containerd-arm64-v8.patch \
git-no-submodules.patch \
mips64le.patch \
noclip.patch \
/tmp/buildkit-patches/

WORKDIR /app

RUN set -eux; \
git clone --branch "v$BUILDKIT_VERSION" --depth 1 --config advice.detachedHead=false 'https://github.com/moby/buildkit.git' .; \
git apply /tmp/buildkit-patches/*.patch; \
git diff --color

ENV CGO_ENABLED 0

ARG TARGETOS TARGETARCH TARGETVARIANT
ENV GOOS=$TARGETOS GOARCH=$TARGETARCH VARIANT=$TARGETVARIANT

RUN set -eux; \
case "$GOARCH" in \
arm) export GOARM="${VARIANT#v}" ;; \
amd64) export GOAMD64="$VARIANT" ;; \
*) [ -z "$VARIANT" ] ;; \
esac; \
go env | grep -E 'OS=|ARCH=|ARM=|AMD64='; \
\
# https://github.com/moby/buildkit/blob/v0.13.2/Dockerfile#L93
pkg='github.com/moby/buildkit'; \
ldflags=" \
-d -w \
-X '$pkg/version.Version=$BUILDKIT_VERSION-tianon' \
-X '$pkg/version.Revision=v$BUILDKIT_VERSION+tianon-patches' \
-X '$pkg/version.Package=$pkg' \
"; \
go build -o /buildkitd -trimpath -ldflags "$ldflags" ./cmd/buildkitd; \
go build -o /buildctl -trimpath -ldflags "$ldflags" ./cmd/buildctl; \
\
# https://github.com/moby/buildkit/blob/v0.14.0/frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile#L21
pkg='github.com/moby/buildkit/frontend/dockerfile/cmd/dockerfile-frontend'; \
ldflags=" \
-d -w \
-X '$pkg/version.Version=buildkit-$BUILDKIT_VERSION-tianon' \
-X '$pkg/version.Revision=v$BUILDKIT_VERSION+tianon-patches' \
-X '$pkg/version.Package=$pkg' \
"; \
go build -o /dockerfile-frontend -trimpath -ldflags "$ldflags" ./frontend/dockerfile/cmd/dockerfile-frontend

FROM --platform=$TARGETPLATFORM infosiftr/moby

RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends git; \
rm -rf /var/lib/apt/lists/*

COPY --from=build --link /buildkitd /buildctl /dockerfile-frontend /usr/local/bin/
COPY buildkitd-entrypoint.sh /usr/local/bin/

VOLUME /var/lib/buildkit

# https://github.com/docker/buildx/issues/484#issuecomment-749352728
ENV BUILDKIT_STEP_LOG_MAX_SIZE -1
ENV BUILDKIT_STEP_LOG_MAX_SPEED -1

# https://github.com/moby/buildkit/blob/v0.14.0/frontend/gateway/gateway.go#L309
# https://github.com/moby/buildkit/blob/v0.14.0/frontend/dockerfile/cmd/dockerfile-frontend/Dockerfile#L35-L36
LABEL moby.buildkit.frontend.network.none="true"
LABEL moby.buildkit.frontend.caps="moby.buildkit.frontend.inputs,moby.buildkit.frontend.subrequests,moby.buildkit.frontend.contexts"

ENTRYPOINT ["buildkitd-entrypoint.sh"]
CMD []
28 changes: 28 additions & 0 deletions buildkit/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
{{ if env.variant != "" then .[env.variant] else . end | ( -}}
{{ # https://github.com/tianon/bashbrew/commit/823f2c4716e0c697a10a772e46a5d51c386a5dcc (bashbrew ~support for "--platform=$BUILDPLATFORM" specifically for this use case -- applied to Tianon's own local builds) -}}
FROM --platform=$BUILDPLATFORM golang:{{ .go.version }} AS build

{{ if env.variant == "dev" then ( -}}
# https://github.com/moby/buildkit/commits/HEAD
# https://github.com/moby/buildkit/tree/{{ .version }}
ARG BUILDKIT_COMMIT={{ .version }}
ENV BUILDKIT_COMMIT $BUILDKIT_COMMIT
{{ ) else ( -}}
# https://github.com/moby/buildkit/releases
ENV BUILDKIT_VERSION {{ .version }}
{{ ) end -}}

COPY \
{{ if env.variant != "dev" and (.version | startswith("0.13.") or startswith("0.14.")) then ( -}}
backport-5072-fetch-tags.patch \
{{ ) else "" end -}}
containerd-arm64-v8.patch \
git-no-submodules.patch \
mips64le.patch \
Expand All @@ -15,7 +25,14 @@ COPY \
WORKDIR /app

RUN set -eux; \
{{ if env.variant == "dev" then ( -}}
git init --quiet; \
git config advice.detachedHead false; \
git fetch --depth 1 'https://github.com/moby/buildkit.git' "$BUILDKIT_COMMIT:"; \
git checkout FETCH_HEAD; \
{{ ) else ( -}}
git clone --branch "v$BUILDKIT_VERSION" --depth 1 --config advice.detachedHead=false 'https://github.com/moby/buildkit.git' .; \
{{ ) end -}}
git apply /tmp/buildkit-patches/*.patch; \
git diff --color

Expand All @@ -36,8 +53,13 @@ RUN set -eux; \
pkg='github.com/moby/buildkit'; \
ldflags=" \
-d -w \
{{ if env.variant == "dev" then ( -}}
-X '$pkg/version.Version={{ env.variant }}-tianon' \
-X '$pkg/version.Revision=$BUILDKIT_COMMIT+tianon-patches' \
{{ ) else ( -}}
-X '$pkg/version.Version=$BUILDKIT_VERSION-tianon' \
-X '$pkg/version.Revision=v$BUILDKIT_VERSION+tianon-patches' \
{{ ) end -}}
-X '$pkg/version.Package=$pkg' \
"; \
go build -o /buildkitd -trimpath -ldflags "$ldflags" ./cmd/buildkitd; \
Expand All @@ -47,8 +69,13 @@ RUN set -eux; \
pkg='github.com/moby/buildkit/frontend/dockerfile/cmd/dockerfile-frontend'; \
ldflags=" \
-d -w \
{{ if env.variant == "dev" then ( -}}
-X '$pkg/version.Version={{ env.variant }}-tianon' \
-X '$pkg/version.Revision=$BUILDKIT_COMMIT+tianon-patches' \
{{ ) else ( -}}
-X '$pkg/version.Version=buildkit-$BUILDKIT_VERSION-tianon' \
-X '$pkg/version.Revision=v$BUILDKIT_VERSION+tianon-patches' \
{{ ) end -}}
-X '$pkg/version.Package=$pkg' \
"; \
go build -o /dockerfile-frontend -trimpath -ldflags "$ldflags" ./frontend/dockerfile/cmd/dockerfile-frontend
Expand Down Expand Up @@ -76,3 +103,4 @@ LABEL moby.buildkit.frontend.caps="moby.buildkit.frontend.inputs,moby.buildkit.f

ENTRYPOINT ["buildkitd-entrypoint.sh"]
CMD []
{{ ) -}}
87 changes: 80 additions & 7 deletions buildkit/gsl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,88 @@ cd "$(dirname "$BASH_SOURCE")"
dir="$(basename "$PWD")"
cd ..

version="$(jq -r '.version' "$dir/versions.json")"
# TODO from="$(awk '$1 == "FROM" { from = $3 } END { print from }' "$dir/Dockerfile")" # TODO multi-stage build more intelligently 😬
from='infosiftr/moby'
arches="$(bashbrew remote arches --json "$from" | jq -r '.arches | keys | join(", ")')"

source gsl-libs.sh
commit="$(git -C "$dir" log -1 --format='format:%H' HEAD -- .)"

globalEntry
echo "Architectures: $arches"
echo 'Builder: buildkit' # meta

versionedTagsEntry "$dir" "$version" latest
export arches commit dir
exec jq -r '
[
{
Maintainers: "Tianon Gravi <[email protected]> (@tianon)",
GitRepo: "https://github.com/tianon/dockerfiles.git",
GitCommit: env.commit,
Directory: env.dir,
Architectures: env.arches,
Builder: "buildkit",
},
(
(
[
.variants[] as $variant
| {
key: $variant,
value: (
if $variant == "" then
.version
else
.[$variant].version
end
),
}
]
| from_entries
)
| if (.rc | split(".-") | tonumber? // .) <= (.[""] | split(".-") | tonumber? // .) then
# if the RC is not newer than the current stable, skip it
del(.rc)
else . end
| with_entries(
.key as $variant
| .value as $version
| .value = (
if $variant == "dev" then
[]
else
$version
| [ scan("(?:[.-]+|^)[^.-]*") ]
| reduce .[] as $p ([];
if length > 0 then
[ .[0] + $p, .[] ]
else [ $p ] end
)
end
| . + [
if $variant == "" then
"latest"
elif index($variant) | not then
$variant
else empty end
]
)
)
| reduce to_entries[] as $e ({};
.[$e.key] = $e.value - ([ .[][] ])
)
| to_entries[]
| .key as $variant
| .value
| {
Tags: join(", "),
File: ("Dockerfile" + if $variant != "" then "." + $variant else "" end),
}
)
]
| .[0].File as $globalFile
| map(
if .File == "Dockerfile" and ($globalFile | not) then
del(.File)
else . end
| to_entries
| map(.key + ": " + .value)
| join("\n")
)
| join("\n\n")
' "$dir/versions.json"
23 changes: 23 additions & 0 deletions buildkit/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,28 @@
"version": "0.14.1",
"go": {
"version": "1.21"
},
"variants": [
"",
"rc",
"0.13"
],
"rc": {
"commit": "aebcc1f0eabcbaeef4be8e948641f653140fe2bf",
"ref": "refs/tags/v0.14.0-rc2",
"tag": "v0.14.0-rc2",
"version": "0.14.0-rc2",
"go": {
"version": "1.21"
}
},
"0.13": {
"commit": "2e18d709fefdcc2db20853ee241c75b058189d39",
"ref": "refs/tags/v0.13.2",
"tag": "v0.13.2",
"version": "0.13.2",
"go": {
"version": "1.21"
}
}
}
Loading
Loading