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
19 changes: 10 additions & 9 deletions hack/scripts/gen-ver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -x
# optional tag prefix to handle versions like:
# cmd/cli/v0.1.44 -> v0.1.44
# docker-v29.0.0 -> v29.0.0
: "${TAGPREFIX:=}"

srcdir="$1"
if [ -z "$srcdir" ]; then
echo "usage: ./gen-ver <srcdir>" >&2
exit 1
fi

version=$(git -C "${srcdir}" describe --match 'v[0-9]*' --always --tags)
tagregex="${TAGPREFIX}v[0-9]*"
version=$(git -C "${srcdir}" describe --match "$tagregex" --tags)
commit="$(git --git-dir "${srcdir}/.git" rev-parse HEAD)"
commitShort=${commit:0:7}

# Handle prefixed version formats
# cmd/cli/v0.1.44 -> v0.1.44
if [[ "$version" =~ .*/v[0-9] ]]; then
version="${version##*/}"
fi
# docker-v29.0.0 -> v29.0.0
if [[ "$version" =~ ^docker-v[0-9] ]]; then
version="${version#docker-}"
if [ -n "$TAGPREFIX" ]; then
version="${version#$TAGPREFIX}"
fi

# rpm "Release:" field ($rpmRelease) is used to set the "_release" macro, which
Expand Down
2 changes: 2 additions & 0 deletions pkg/buildx/scripts/pkg-deb-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$DISTRO_NAME" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/buildx/scripts/pkg-rpm-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$DISTRO_NAME" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/buildx/scripts/pkg-static-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$OUTDIR" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/compose/scripts/pkg-deb-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$DISTRO_NAME" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/compose/scripts/pkg-rpm-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$DISTRO_NAME" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/compose/scripts/pkg-static-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$OUTDIR" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/containerd/scripts/pkg-deb-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$DISTRO_NAME" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/containerd/scripts/pkg-rpm-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$DISTRO_NAME" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/containerd/scripts/pkg-static-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
: "${LIBSECCOMP_SRCDIR=/work/libseccomp-src}"
: "${RUNHCS_SRCDIR=/work/runhcs-src}"

: "${TAGPREFIX=}"

set -e

if [ -z "$OUTDIR" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/credential-helpers/scripts/pkg-deb-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$DISTRO_NAME" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/credential-helpers/scripts/pkg-rpm-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$DISTRO_NAME" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/credential-helpers/scripts/pkg-static-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$OUTDIR" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/docker-cli/scripts/pkg-deb-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$DISTRO_NAME" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/docker-cli/scripts/pkg-rpm-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$DISTRO_NAME" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/docker-cli/scripts/pkg-static-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$OUTDIR" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/docker-engine/scripts/pkg-deb-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$DISTRO_NAME" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/docker-engine/scripts/pkg-rpm-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$DISTRO_NAME" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/docker-engine/scripts/pkg-static-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$OUTDIR" ]; then
Expand Down
6 changes: 6 additions & 0 deletions pkg/model/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ ARG GO_IMAGE="golang"
ARG GO_VERSION=1.24.8
ARG GO_IMAGE_VARIANT="bookworm"

ARG TAGPREFIX="cmd/cli/"
Copy link
Member

@crazy-max crazy-max Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vvoland Should we also set TAGPREFIX in docker-engine Dockerfile as well to make it future proof?


# stage used as named context that mounts hack/scripts
# see pkg target in docker-bake.hcl
FROM scratch AS scripts
Expand Down Expand Up @@ -63,6 +65,7 @@ FROM src-base AS metadata-builder
ARG PKG_REPO
ARG PKG_REF
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 <<EOT
set -e
Expand Down Expand Up @@ -108,6 +111,7 @@ ARG PKG_DEB_BUILDFLAGS
ARG PKG_DEB_REVISION
ARG PKG_DEB_EPOCH
ARG SOURCE_DATE_EPOCH
ARG TAGPREFIX
RUN --mount=type=bind,source=scripts/pkg-deb-build.sh,target=/usr/local/bin/pkg-deb-build \
--mount=type=bind,from=scripts,source=gen-ver.sh,target=/usr/local/bin/gen-ver \
--mount=type=bind,from=scripts,source=gen-deb-changelog.sh,target=/usr/local/bin/gen-deb-changelog \
Expand Down Expand Up @@ -143,6 +147,7 @@ ARG PKG_PACKAGER
ARG PKG_RPM_BUILDFLAGS
ARG PKG_RPM_RELEASE
ARG SOURCE_DATE_EPOCH
ARG TAGPREFIX
RUN --mount=type=bind,source=scripts/pkg-rpm-build.sh,target=/usr/local/bin/pkg-rpm-build \
--mount=type=bind,from=scripts,source=gen-ver.sh,target=/usr/local/bin/gen-ver \
--mount=type=bind,from=scripts,source=fix-cc.sh,target=/usr/local/bin/fix-cc \
Expand All @@ -165,6 +170,7 @@ ENV CGO_ENABLED="0"
ARG PKG_NAME
ARG PKG_REF
ARG NIGHTLY_BUILD
ARG TAGPREFIX
WORKDIR /build
ARG TARGETPLATFORM
RUN --mount=type=bind,source=scripts/pkg-static-build.sh,target=/usr/local/bin/pkg-static-build \
Expand Down
2 changes: 2 additions & 0 deletions pkg/model/scripts/pkg-deb-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$DISTRO_NAME" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/model/scripts/pkg-rpm-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$DISTRO_NAME" ]; then
Expand Down
2 changes: 2 additions & 0 deletions pkg/model/scripts/pkg-static-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
: "${SRCDIR=/work/src}"
: "${OUTDIR=/out}"

: "${TAGPREFIX=}"

set -e

if [ -z "$OUTDIR" ]; then
Expand Down