Skip to content
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
6 changes: 2 additions & 4 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ variable "PKG_PLATFORMS_BASE" {
model = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm64", "linux/arm/v7", "windows/amd64", "windows/arm64"]
# https://github.com/docker/docker-agent/blob/5b9feaabe743a5ad577f2247ed55d5dcb2678e8b/Taskfile.yml#L79
agent = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm64", "windows/amd64", "windows/arm64"]
# Linux packages only; darwin and windows ship through the source repo.
offload = ["linux/amd64", "linux/arm64"]
# darwin and windows are static archives only. The linux platforms also build a static archive.
offload = ["darwin/amd64", "darwin/arm64", "linux/amd64", "linux/arm64", "windows/amd64", "windows/arm64"]
}
}

Expand All @@ -105,8 +105,6 @@ variable "PKG_DISTROS" {
description = "Package-specific distro mapping. Packages omitted here build for all DISTROS."
default = {
docker = ["static"]
# Every distro except static: the offload Dockerfile has no builder-static stage.
offload = [for distro in DISTROS : distro if distro != "static"]
}
}

Expand Down
26 changes: 26 additions & 0 deletions pkg/offload/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
# go base image to retrieve /usr/local/go
FROM ${GO_IMAGE}:${GO_VERSION}-${GO_IMAGE_VARIANT} AS go

# go toolchain for the build platform, used by static to cross compile for any target platform
FROM --platform=$BUILDPLATFORM ${GO_IMAGE}:${GO_VERSION}-${GO_IMAGE_VARIANT} AS go-build

# deb
FROM ${DISTRO_IMAGE} AS builder-deb
COPY --from=xx / /
Expand Down Expand Up @@ -108,6 +111,29 @@ RUN --mount=type=bind,source=scripts/pkg-rpm-build.sh,target=/usr/local/bin/pkg-
--mount=type=secret,id=build-env,target=/run/secrets/build-env \
OUTDIR=/out SRCDIR=/usr/local/src/offload BUILD_ENV_FILE=/run/secrets/build-env pkg-rpm-build

# static
# Compiles from source, like the deb and rpm builders, and archives the unsigned binary.
FROM --platform=$BUILDPLATFORM ${DISTRO_IMAGE} AS builder-static
COPY --from=xx / /
RUN apt-get update && apt-get install -y --no-install-recommends bash file make tar zip
ENV GOPATH="/go"
ENV PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"
ENV GOTOOLCHAIN="local"
ARG PKG_NAME
ARG VERSION
ARG COMMIT
ARG BUILD
ARG DATE
WORKDIR /build
ARG TARGETPLATFORM
RUN --mount=type=bind,source=scripts/pkg-static-build.sh,target=/usr/local/bin/pkg-static-build \
--mount=type=bind,from=scripts,source=write-sha256sum.sh,target=/usr/local/bin/write-sha256sum \
--mount=type=bind,from=src,target=/usr/local/src/offload,rw \
--mount=type=bind,from=go-build,source=/usr/local/go,target=/usr/local/go,rw \
--mount=type=secret,id=build-env,target=/run/secrets/build-env \
OUTDIR=/out BUILDDIR=/build SRCDIR=/usr/local/src/offload \
BUILD_ENV_FILE=/run/secrets/build-env pkg-static-build

FROM builder-${DISTRO_TYPE} AS build-pkg
ARG BUILDKIT_SBOM_SCAN_STAGE=true

Expand Down
102 changes: 102 additions & 0 deletions pkg/offload/scripts/pkg-static-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env bash

# Copyright 2026 Docker Packaging authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

: "${VERSION=}"
: "${COMMIT=}"
: "${BUILD=}"
: "${DATE=}"
: "${BUILD_ENV_FILE=}"

: "${PKG_NAME=}"

: "${BUILDDIR=/work/build}"
: "${SRCDIR=/usr/local/src/offload}"
: "${OUTDIR=/out}"

set -e

if [ -z "$VERSION" ]; then
echo >&2 "error: VERSION is required"
exit 1
fi
case "$VERSION" in
v*) ;;
*) echo >&2 "error: VERSION must start with v, got $VERSION"; exit 1 ;;
esac
if [ -z "$PKG_NAME" ]; then
echo >&2 "error: PKG_NAME is required"
exit 1
fi
if [ -z "$OUTDIR" ]; then
echo >&2 "error: OUTDIR is required"
exit 1
fi

if ! command -v xx-info &> /dev/null; then
echo >&2 "error: xx cross compilation helper is required"
exit 1
fi

mkdir -p "$OUTDIR" "$BUILDDIR"

binext=$([ "$(xx-info os)" = "windows" ] && echo ".exe" || true)
bin="${BUILDDIR}/docker-offload${binext}"

# Build from source, as the deb and rpm builds do. The binaries are unsigned.
(
set -x
xx-go --wrap
make -C "$SRCDIR" ce-release VERSION="$VERSION" COMMIT="$COMMIT" BUILD="$BUILD" DATE="$DATE" \
BUILD_ENV_FILE="$BUILD_ENV_FILE"
install -m 0755 "${SRCDIR}/dist/docker-offload${binext}" "$bin"
xx-verify --static "$bin"
)

for doc in LICENSE README.md; do
if [ ! -f "${SRCDIR}/${doc}" ]; then
echo >&2 "error: no ${doc} in ${SRCDIR}; pass the source tree as the src named context"
exit 1
fi
done

pkgoutput="$OUTDIR/static/$(xx-info os)/$(xx-info arch)"
if [ -n "$(xx-info variant)" ]; then
pkgoutput="${pkgoutput}/$(xx-info variant)"
fi
mkdir -p "${pkgoutput}"

workdir=$(mktemp -d -t docker-packaging.XXXXXXXXXX)
mkdir -p "$workdir/cli-plugins" "$workdir/doc"
(
set -x
cp "$bin" "$workdir/cli-plugins/"
cp "${SRCDIR}/LICENSE" "${SRCDIR}/README.md" "$workdir/doc/"
)
if [ "$(xx-info os)" = "windows" ]; then
pkgfile="${pkgoutput}/${PKG_NAME}_${VERSION#v}.zip"
(
set -x
cd "$workdir"
zip -r "$pkgfile" cli-plugins doc
)
else
pkgfile="${pkgoutput}/${PKG_NAME}_${VERSION#v}.tgz"
(
set -x
tar -czf "$pkgfile" -C "$workdir" cli-plugins doc
)
fi
write-sha256sum "$pkgfile"
56 changes: 56 additions & 0 deletions pkg/offload/verify.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,60 @@ RUN --mount=from=bin,target=/build <<EOT
fi
EOT

# The darwin and windows binaries cannot run in this Linux container, so check each archive:
# checksum, layout, and that the binary matches the platform in its path and holds the version.
# Only an archive whose platform equals the container's platform (linux) also runs the plugin and
# checks the version from its metadata; the others check the version as a string in the binary.
# Signatures are not checked.
FROM base AS verify-static
RUN apt-get update && apt-get install -y --no-install-recommends file tar unzip
COPY --from=xx / /
ARG TARGETPLATFORM
ARG VERSION
RUN --mount=from=bin,target=/build <<EOT
set -e
packages=$(find /build -type f \( -name '*.tgz' -o -name '*.zip' \) | sort)
if [ -z "$packages" ]; then
echo >&2 "error: no static archives found in /build"
exit 1
fi
for package in $packages; do
(
set -x
dir="${package%/*}"
name="${package##*/}"
platform="${dir#*/static/}"
os="${platform%%/*}"
arch="${platform#*/}"
arch="${arch%%/*}"
ext=""
[ "$os" = windows ] && ext=".exe"
cd "$dir"
sha256sum -c "${name}.sha256"
tmp=$(mktemp -d)
case "$name" in
*.tgz) tar -xzf "$name" -C "$tmp" ;;
*.zip) unzip -q "$name" -d "$tmp" ;;
esac
test "$(ls "$tmp" | tr '\n' ' ')" = "cli-plugins doc "
test "$(ls "$tmp/cli-plugins")" = "docker-offload${ext}"
test -x "$tmp/cli-plugins/docker-offload${ext}"
test -s "$tmp/doc/LICENSE"
test -s "$tmp/doc/README.md"
TARGETPLATFORM="${os}/${arch}" xx-verify --static "$tmp/cli-plugins/docker-offload${ext}"
if [ "$os/$arch" = "$(xx-info os)/$(xx-info arch)" ]; then
"$tmp/cli-plugins/docker-offload${ext}" docker-cli-plugin-metadata
if [ -n "$VERSION" ]; then
"$tmp/cli-plugins/docker-offload${ext}" docker-cli-plugin-metadata \
| grep -F "\"Version\": \"$VERSION\""
fi
elif [ -n "$VERSION" ]; then
# shortcut: substring match, so v0.7.1 also matches a v0.7.10 binary.
# The binary cannot run here; upgrade if a way to read its version appears.
grep -aqF "$VERSION" "$tmp/cli-plugins/docker-offload${ext}"
Comment thread
nicksieger marked this conversation as resolved.
Resolved
fi
)
done
EOT

FROM verify-${DISTRO_TYPE} AS verify