From ebc256b073a2b7c204ccd7241e220c077067b04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Thu, 5 Oct 2023 16:58:27 +0200 Subject: [PATCH] Container: set the composer git revision during the build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the container with osbuild-composer gets built in our CI or by AppSRE, we do not set the composer version to any value (as we do when we built RPMs). As a result, the version reported by composer is always "devel". This is not useful for debugging and determining the used version of composer. In addition, this information now gets exposed in Koji builds, therefore it makes sense to make it useful. Signed-off-by: Tomáš Hozza --- distribution/Dockerfile-ubi | 9 ++++++++- schutzbot/containerbuild.sh | 1 + tools/appsre-build-deploy.sh | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/distribution/Dockerfile-ubi b/distribution/Dockerfile-ubi index d5467e851..fb6053f46 100644 --- a/distribution/Dockerfile-ubi +++ b/distribution/Dockerfile-ubi @@ -9,8 +9,15 @@ USER 1001 # Otherwise, VCS stamping will fail because git >= 2.35.2 refuses to work in # a repository owned by a different user. COPY --chown=1001 . . +ARG COMMIT +ENV LDFLAGS="${COMMIT:+-X \'github.com/osbuild/osbuild-composer/internal/common.GitRev=${COMMIT}\'}" +ENV LDFLAGS="${LDFLAGS:+-ldflags=\"${LDFLAGS}\"}" ENV GOFLAGS=-mod=vendor -RUN go install ./cmd/osbuild-composer/ +# if run without "sh -c", podman for some reason executes the command in a way, +# which results in the following error: +# [1/3] STEP 12/12: RUN go install ${LDFLAGS} ./cmd/osbuild-composer/ +# invalid value "\"-X" for flag -ldflags: missing = in = +RUN /usr/bin/sh -c "go install ${LDFLAGS} ./cmd/osbuild-composer/" FROM registry.access.redhat.com/ubi9/go-toolset:latest AS builder2 RUN go install github.com/jackc/tern@latest diff --git a/schutzbot/containerbuild.sh b/schutzbot/containerbuild.sh index cc690969b..8fd5a0866 100755 --- a/schutzbot/containerbuild.sh +++ b/schutzbot/containerbuild.sh @@ -14,6 +14,7 @@ podman \ build \ --file="distribution/Dockerfile-ubi" \ --tag="${IMAGE_NAME}:${IMAGE_TAG}" \ + --build-arg="COMMIT=${IMAGE_TAG}" \ --label="quay.expires-after=1w" \ . diff --git a/tools/appsre-build-deploy.sh b/tools/appsre-build-deploy.sh index acb206029..3cfcfe318 100755 --- a/tools/appsre-build-deploy.sh +++ b/tools/appsre-build-deploy.sh @@ -4,6 +4,7 @@ set -exv IMAGE_NAME="quay.io/app-sre/composer" IMAGE_TAG=$(git rev-parse --short=7 HEAD) +COMMIT=$(git rev-parse HEAD) if [[ -z "$QUAY_USER" || -z "$QUAY_TOKEN" ]]; then echo "QUAY_USER and QUAY_TOKEN must be set" @@ -13,7 +14,7 @@ fi DOCKER_CONF="$PWD/.docker" mkdir -p "$DOCKER_CONF" docker --config="$DOCKER_CONF" login -u="$QUAY_USER" -p="$QUAY_TOKEN" quay.io -docker --config="$DOCKER_CONF" build -f distribution/Dockerfile-ubi -t "${IMAGE_NAME}:${IMAGE_TAG}" . +docker --config="$DOCKER_CONF" build -f distribution/Dockerfile-ubi --build-arg="COMMIT=${COMMIT}" -t "${IMAGE_NAME}:${IMAGE_TAG}" . docker --config="$DOCKER_CONF" push "${IMAGE_NAME}:${IMAGE_TAG}" # Maintenance image