Skip to content

Commit 4ce97f9

Browse files
authored
fix: log the correct versions in CI built containers (#76)
After inspecting the test logs from CI it became apparent there are a few issues. On GHA built containers, the version looks like this: ``` [INFO 2025-09-19T09:37:46Z] (fact/src/lib.rs:53) fact version: 47c1a04-arm64 ``` There are two problems with that version: * It includes the architecture information as part of the version, which it shouldn't do. * The actual version is the commit SHA instead of the rev-parse digest. These are fixed by having independent FACT_TAG and FACT_VERSION variables in the build and checking out the full git history when determining the version respectively. On konflux built containers, the version looks like this: ``` [INFO 2025-09-19T09:46:00Z] (fact/src/lib.rs:53) fact version: ``` This is because the `FACT_TAG` argument is only being set on the final stage of the Containerfile.
1 parent 4cd363d commit 4ce97f9

6 files changed

Lines changed: 15 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ jobs:
8080
- uses: actions/checkout@v4
8181
with:
8282
submodules: true
83+
fetch-depth: 0
8384

8485
- id: vars
8586
run: |
@@ -100,6 +101,7 @@ jobs:
100101
runs-on: ${{ (matrix.arch == 'arm64' && 'ubuntu-24.04-arm') || 'ubuntu-24.04' }}
101102
env:
102103
FACT_TAG: ${{ needs.vars.outputs.tag }}-${{ matrix.arch }}
104+
FACT_VERSION: ${{ needs.vars.outputs.tag }}
103105
steps:
104106
- uses: actions/checkout@v4
105107
with:

Containerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ WORKDIR /app
1212

1313
COPY . .
1414

15-
ARG FACT_TAG
15+
ARG FACT_VERSION
1616
RUN --mount=type=cache,target=/root/.cargo/registry \
1717
--mount=type=cache,target=/app/target \
1818
cargo build --release && \

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ include constants.mk
33
tag:
44
@echo "$(FACT_TAG)"
55

6+
version:
7+
@echo "$(FACT_VERSION)"
8+
69
image-name:
710
@echo "$(FACT_IMAGE_NAME)"
811

@@ -12,7 +15,7 @@ mock-server:
1215
image:
1316
docker build \
1417
-f Containerfile \
15-
--build-arg FACT_TAG=$(FACT_TAG) \
18+
--build-arg FACT_VERSION=$(FACT_VERSION) \
1619
-t $(FACT_IMAGE_NAME) \
1720
$(CURDIR)
1821

constants.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FACT_TAG ?= $(shell git describe --always --tags --abbrev=10 --dirty)
2+
FACT_VERSION ?= $(FACT_TAG)
23
FACT_REGISTRY ?= quay.io/stackrox-io/fact
34
FACT_IMAGE_NAME ?= $(FACT_REGISTRY):$(FACT_TAG)
45

fact/build.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ fn main() -> anyhow::Result<()> {
77
let out_dir: PathBuf = std::env::var("OUT_DIR")
88
.context("Failed to interpret OUT_DIR environment variable")?
99
.into();
10-
let cmd = Command::new("make").args(["-sC", "..", "tag"]).output()?;
10+
let cmd = Command::new("make")
11+
.args(["-sC", "..", "version"])
12+
.output()?;
1113

1214
if !cmd.status.success() {
1315
eprintln!("Captured stdout: {}", String::from_utf8_lossy(&cmd.stdout));
1416
eprintln!("Captured stderr: {}", String::from_utf8_lossy(&cmd.stderr));
15-
bail!("Failed to run `make tag`: {:?}", cmd.status.code());
17+
bail!("Failed to run `make version`: {:?}", cmd.status.code());
1618
}
1719

1820
let version = String::from_utf8(cmd.stdout)?;

konflux.Containerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM registry.access.redhat.com/ubi9/ubi@sha256:7ff0b510498fa9f368a58e735e0c57f3497fd3205dbc2ea5e6e8ddf84f48752f AS builder
22

3+
ARG FACT_TAG
4+
RUN echo "Checking required FACT_TAG"; [[ "${FACT_TAG}" != "" ]]
5+
36
RUN dnf install -y \
47
clang \
58
libbpf-devel \
@@ -17,7 +20,6 @@ RUN cargo build --release
1720
FROM registry.access.redhat.com/ubi9/ubi-micro@sha256:f5c5213d2969b7b11a6666fc4b849d56b48d9d7979b60a37bb853dff0255c14b
1821

1922
ARG FACT_TAG
20-
RUN echo "Checking required FACT_TAG"; [[ "${FACT_TAG}" != "" ]]
2123

2224
LABEL \
2325
com.redhat.license_terms="https://www.redhat.com/agreements" \

0 commit comments

Comments
 (0)