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