Container: set the composer git revision during the build

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 <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2023-10-05 16:58:27 +02:00 committed by Tomáš Hozza
parent 21e09c75bc
commit ebc256b073
3 changed files with 11 additions and 2 deletions

View file

@ -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 =<value> in <pattern>=<value>
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

View file

@ -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" \
.

View file

@ -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