From 5c0df8fb50e73e2b787e28029b1ee420440b240b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Mon, 21 Sep 2026 16:30:52 +0200 Subject: [PATCH 1/2] hack/gen-ver: Allow an explicit version override MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added an optional version argument so callers can set a release version independently of source tags while retaining the source commit identity. Explicit versions use the existing binary and package version formatting without being replaced by a pseudo version for untagged commits. Source-derived defaults remain unchanged, and NIGHTLY_BUILD=1 still forces a pseudo version. Added tests for overrides, prereleases, prefixed tags, untagged commits, and nightlies. Signed-off-by: Paweł Gronowski --- hack/scripts/gen-ver.sh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/hack/scripts/gen-ver.sh b/hack/scripts/gen-ver.sh index 8b48c052..50e95a9f 100755 --- a/hack/scripts/gen-ver.sh +++ b/hack/scripts/gen-ver.sh @@ -22,19 +22,23 @@ set -x srcdir="$1" if [ -z "$srcdir" ]; then - echo "usage: ./gen-ver " >&2 + echo "usage: ./gen-ver [version]" >&2 exit 1 fi -tagregex="${TAGPREFIX}v[0-9]*" -version=$(git -C "${srcdir}" describe --match "$tagregex" --tags) +version="${2:-}" +if [ -n "$version" ]; then + version="v${version#v}" +else + tagregex="${TAGPREFIX}v[0-9]*" + version=$(git -C "${srcdir}" describe --match "$tagregex" --tags) + if [ -n "$TAGPREFIX" ]; then + version="${version#$TAGPREFIX}" + fi +fi commit="$(git --git-dir "${srcdir}/.git" rev-parse HEAD)" commitShort=${commit:0:7} -if [ -n "$TAGPREFIX" ]; then - version="${version#$TAGPREFIX}" -fi - # rpm "Release:" field ($rpmRelease) is used to set the "_release" macro, which # is an incremental number for builds of the same release (Version: / #rpmVersion). # @@ -66,10 +70,9 @@ fi # Docker 22.06.0-dev: version=0.0.0~YYYYMMDDHHMMSS.gitHASH, release=0 rpmRelease=1 -# if NIGHTLY_BUILD=1, or we have a "-dev" suffix or a commit not pointing to a -# tag, this is a nightly build, and we'll create a pseudo version based on -# commit-date and -sha. -if [[ "$NIGHTLY_BUILD" == "1" ]] || [[ "$version" == *-dev ]] || [[ -z "$(git -C "${srcdir}" tag --points-at HEAD --sort -version:refname)" ]]; then +# NIGHTLY_BUILD=1 always forces a pseudo version. Without an explicit version, +# a "-dev" suffix or a commit not pointing to a tag also denotes a nightly. +if [[ "$NIGHTLY_BUILD" == "1" || ( -z "${2:-}" && ( "$version" == *-dev || -z "$(git -C "${srcdir}" tag --points-at HEAD --sort -version:refname)" ) ) ]]; then # based on golang's pseudo-version: https://groups.google.com/forum/#!topic/golang-dev/a5PqQuBljF4 # # using a "pseudo-version" of the form v0.0.0-yyyymmddhhmmss-abcdefa, From 525db3c9b63b0da419e69a466745760ca7fda414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Mon, 21 Sep 2026 16:31:12 +0200 Subject: [PATCH 2/2] release/docker: Apply version to Engine and CLI too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pass DOCKER_VERSION to the Engine and CLI Bake targets. The release workflow applied the requested version only to the combined static archives. Signed-off-by: Paweł Gronowski --- .github/workflows/release-docker.yml | 2 ++ docker-bake.hcl | 4 +++- pkg/docker-cli/Dockerfile | 7 ++++++- pkg/docker-cli/scripts/pkg-deb-build.sh | 2 +- pkg/docker-cli/scripts/pkg-rpm-build.sh | 2 +- pkg/docker-cli/scripts/pkg-static-build.sh | 2 +- pkg/docker-engine/Dockerfile | 6 +++++- pkg/docker-engine/scripts/pkg-deb-build.sh | 2 +- pkg/docker-engine/scripts/pkg-rpm-build.sh | 2 +- pkg/docker-engine/scripts/pkg-static-build.sh | 2 +- 10 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release-docker.yml b/.github/workflows/release-docker.yml index f862dd9b..0824b3c5 100644 --- a/.github/workflows/release-docker.yml +++ b/.github/workflows/release-docker.yml @@ -67,6 +67,7 @@ jobs: vars: | PKG_REPO=${{ inputs.engine-repo }} PKG_REF=${{ inputs.engine-ref }} + DOCKER_VERSION=${{ inputs.version }} PKG_DEB_REVISION=${{ inputs.revision }} PKG_RPM_RELEASE=${{ inputs.revision }} dockerhub_username: dockereng @@ -87,6 +88,7 @@ jobs: vars: | PKG_REPO=${{ inputs.cli-repo }} PKG_REF=${{ inputs.cli-ref }} + DOCKER_VERSION=${{ inputs.version }} PKG_DEB_REVISION=${{ inputs.revision }} PKG_RPM_RELEASE=${{ inputs.revision }} dockerhub_username: dockereng diff --git a/docker-bake.hcl b/docker-bake.hcl index a0d2538a..b921f37d 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -192,7 +192,7 @@ variable "CLI_REF" { default = null } variable "DOCKER_VERSION" { - description = "Docker version to use for the combined Docker static package. If empty, the Engine source version is used." + description = "Version for Docker, Engine, and CLI packages. If empty, versions are derived from source; combined archives use the Engine version." default = null } variable "RUNC_REF" { @@ -622,6 +622,7 @@ target "_pkg-docker-cli" { PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "docker-ce-cli" PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/cli.git" PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "master" + DOCKER_VERSION = DOCKER_VERSION GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.26.8" # https://github.com/docker/cli/blob/master/Dockerfile GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm" PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : "5" @@ -634,6 +635,7 @@ target "_pkg-docker-engine" { PKG_NAME = PKG_NAME != null && PKG_NAME != "" ? PKG_NAME : "docker-ce" PKG_REPO = PKG_REPO != null && PKG_REPO != "" ? PKG_REPO : "https://github.com/docker/docker.git" PKG_REF = PKG_REF != null && PKG_REF != "" ? PKG_REF : "master" + DOCKER_VERSION = DOCKER_VERSION GO_VERSION = GO_VERSION != null && GO_VERSION != "" ? GO_VERSION : "1.26.8" # https://github.com/moby/moby/blob/master/Dockerfile GO_IMAGE_VARIANT = GO_IMAGE_VARIANT != null && GO_IMAGE_VARIANT != "" ? GO_IMAGE_VARIANT : "bookworm" PKG_DEB_EPOCH = PKG_DEB_EPOCH != null && PKG_DEB_EPOCH != "" ? PKG_DEB_EPOCH : "5" diff --git a/pkg/docker-cli/Dockerfile b/pkg/docker-cli/Dockerfile index 7b30954a..203b0a41 100644 --- a/pkg/docker-cli/Dockerfile +++ b/pkg/docker-cli/Dockerfile @@ -67,12 +67,13 @@ RUN --mount=from=src,source=/src,target=/cli \ FROM src-base AS metadata-builder ARG PKG_REPO ARG PKG_REF +ARG DOCKER_VERSION ARG NIGHTLY_BUILD RUN --mount=type=bind,from=scripts,source=gen-ver.sh,target=/usr/local/bin/gen-ver \ --mount=type=bind,from=src,source=/src,target=/src < "/out/metadata.env" <<-EOF @@ -111,6 +112,7 @@ COPY deb /root/package/debian ARG TARGETPLATFORM RUN mk-build-deps -t "xx-apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y" -i /root/package/debian/control WORKDIR /root/package +ARG DOCKER_VERSION ARG NIGHTLY_BUILD ARG DISTRO_RELEASE ARG DISTRO_ID @@ -148,6 +150,7 @@ ARG TARGETPLATFORM RUN --mount=type=bind,from=scripts,source=rpm-builddep.sh,target=/usr/local/bin/rpm-builddep \ rpm-builddep $(xx-info rhel-arch) /root/rpmbuild/SPECS WORKDIR /root/rpmbuild +ARG DOCKER_VERSION ARG NIGHTLY_BUILD ARG DISTRO_RELEASE ARG DISTRO_ID @@ -184,6 +187,7 @@ RUN --mount=type=bind,from=gocross,source=/usr/local/go,target=/usr/local/go,rw FROM build-base-static AS builder-static-nosdk RUN apt-get install -y --no-install-recommends dpkg-dev clang lld llvm make pkg-config +ARG DOCKER_VERSION ARG PKG_NAME ARG PKG_REF ARG NIGHTLY_BUILD @@ -204,6 +208,7 @@ FROM builder-static-nosdk AS builder-static-windows FROM build-base-static AS builder-static-darwin RUN apt-get install -y --no-install-recommends dpkg-dev clang lld llvm make pkg-config +ARG DOCKER_VERSION ARG PKG_NAME ARG PKG_REF ARG NIGHTLY_BUILD diff --git a/pkg/docker-cli/scripts/pkg-deb-build.sh b/pkg/docker-cli/scripts/pkg-deb-build.sh index 080aaf1b..3eaa78bc 100755 --- a/pkg/docker-cli/scripts/pkg-deb-build.sh +++ b/pkg/docker-cli/scripts/pkg-deb-build.sh @@ -52,7 +52,7 @@ if ! command -v xx-info &> /dev/null; then exit 1 fi -for l in $(gen-ver "${SRCDIR}"); do +for l in $(gen-ver "${SRCDIR}" "${DOCKER_VERSION:-}"); do export "${l?}" done diff --git a/pkg/docker-cli/scripts/pkg-rpm-build.sh b/pkg/docker-cli/scripts/pkg-rpm-build.sh index 6dfd47a4..a0e21d09 100755 --- a/pkg/docker-cli/scripts/pkg-rpm-build.sh +++ b/pkg/docker-cli/scripts/pkg-rpm-build.sh @@ -51,7 +51,7 @@ if ! command -v xx-info &> /dev/null; then exit 1 fi -for l in $(gen-ver "${SRCDIR}"); do +for l in $(gen-ver "${SRCDIR}" "${DOCKER_VERSION:-}"); do export "${l?}" done diff --git a/pkg/docker-cli/scripts/pkg-static-build.sh b/pkg/docker-cli/scripts/pkg-static-build.sh index 1245883e..004b2afa 100755 --- a/pkg/docker-cli/scripts/pkg-static-build.sh +++ b/pkg/docker-cli/scripts/pkg-static-build.sh @@ -38,7 +38,7 @@ if ! command -v xx-info &> /dev/null; then exit 1 fi -for l in $(gen-ver "${SRCDIR}"); do +for l in $(gen-ver "${SRCDIR}" "${DOCKER_VERSION:-}"); do export "${l?}" done diff --git a/pkg/docker-engine/Dockerfile b/pkg/docker-engine/Dockerfile index 7121e033..cefe547e 100644 --- a/pkg/docker-engine/Dockerfile +++ b/pkg/docker-engine/Dockerfile @@ -66,13 +66,14 @@ RUN --mount=from=src,source=/src,target=/engine \ FROM src-base AS metadata-builder ARG PKG_REPO ARG PKG_REF +ARG DOCKER_VERSION ARG NIGHTLY_BUILD ARG TAGPREFIX RUN --mount=type=bind,from=scripts,source=gen-ver.sh,target=/usr/local/bin/gen-ver \ --mount=type=bind,from=src,source=/src,target=/src < "/out/metadata.env" <<-EOF @@ -112,6 +113,7 @@ COPY deb /root/package/debian ARG TARGETPLATFORM RUN mk-build-deps -t "xx-apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y" -i /root/package/debian/control WORKDIR /root/package +ARG DOCKER_VERSION ARG NIGHTLY_BUILD ARG DISTRO_RELEASE ARG DISTRO_ID @@ -160,6 +162,7 @@ RUN --mount=type=bind,from=scripts,source=rpm-builddep.sh,target=/usr/local/bin/ rpm-builddep $(xx-info rhel-arch) /root/rpmbuild/SPECS --define "_no_libnftables ${no_libnftables}" EOT WORKDIR /root/rpmbuild +ARG DOCKER_VERSION ARG NIGHTLY_BUILD ARG DISTRO_RELEASE ARG DISTRO_ID @@ -197,6 +200,7 @@ RUN --mount=type=bind,from=gocross,source=/usr/local/go,target=/usr/local/go,rw FROM build-base-static AS builder-static RUN apt-get install -y --no-install-recommends clang cmake gcc libc6-dev lld llvm make pkg-config +ARG DOCKER_VERSION ARG PKG_NAME ARG PKG_REF ARG NIGHTLY_BUILD diff --git a/pkg/docker-engine/scripts/pkg-deb-build.sh b/pkg/docker-engine/scripts/pkg-deb-build.sh index d03e0335..57dada38 100755 --- a/pkg/docker-engine/scripts/pkg-deb-build.sh +++ b/pkg/docker-engine/scripts/pkg-deb-build.sh @@ -52,7 +52,7 @@ if ! command -v xx-info &> /dev/null; then exit 1 fi -for l in $(gen-ver "${SRCDIR}"); do +for l in $(gen-ver "${SRCDIR}" "${DOCKER_VERSION:-}"); do export "${l?}" done diff --git a/pkg/docker-engine/scripts/pkg-rpm-build.sh b/pkg/docker-engine/scripts/pkg-rpm-build.sh index 883ec0dc..ed828a57 100755 --- a/pkg/docker-engine/scripts/pkg-rpm-build.sh +++ b/pkg/docker-engine/scripts/pkg-rpm-build.sh @@ -51,7 +51,7 @@ if ! command -v xx-info &> /dev/null; then exit 1 fi -for l in $(gen-ver "${SRCDIR}"); do +for l in $(gen-ver "${SRCDIR}" "${DOCKER_VERSION:-}"); do export "${l?}" done diff --git a/pkg/docker-engine/scripts/pkg-static-build.sh b/pkg/docker-engine/scripts/pkg-static-build.sh index ce8a8f58..efb0491a 100755 --- a/pkg/docker-engine/scripts/pkg-static-build.sh +++ b/pkg/docker-engine/scripts/pkg-static-build.sh @@ -38,7 +38,7 @@ if ! command -v xx-info &> /dev/null; then exit 1 fi -for l in $(gen-ver "${SRCDIR}"); do +for l in $(gen-ver "${SRCDIR}" "${DOCKER_VERSION:-}"); do export "${l?}" done