Skip to content

Commit ce2dd2b

Browse files
committed
feat(ci): auto-update distroless base images and fix operator version
- Fix operator binary version embedding by correcting ldflags import path - Add dynamic distroless version fetching from NVIDIA versions.json CDN - Upgrade both agent and operator to v4 distroless images - Agent: Python 3.12 (v3.5.2 -> v4.0.1) - Operator: Go (v4.0.1, now auto-updates) - Add fetch-distroless-versions job to both agent-ci and operator-ci This ensures builds always use the latest secure base images and fixes the issue where production operator binaries showed version: "dev"
1 parent 776c906 commit ce2dd2b

File tree

6 files changed

+75
-23
lines changed

6 files changed

+75
-23
lines changed

.github/workflows/agent-ci.yaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,26 @@ on:
3535
env:
3636
REGISTRY: ghcr.io
3737
IMAGE_NAME: ${{ github.repository }}
38+
PYTHON_VERSION: 3.12
3839
jobs:
40+
fetch-distroless-versions:
41+
name: Fetch Latest Distroless Versions
42+
runs-on: ubuntu-latest
43+
outputs:
44+
distroless-version: ${{ steps.fetch.outputs.distroless-version }}
45+
steps:
46+
- name: Fetch versions from NVIDIA CDN
47+
id: fetch
48+
run: |
49+
# Fetch the versions.json file
50+
VERSIONS_JSON=$(curl -fsSL https://developer.download.nvidia.com/distroless-oss/versions.json)
51+
52+
# Extract latest Python v4 version (format: "v4.0.1" -> "4.0.1")
53+
DISTROLESS_VERSION=$(echo "$VERSIONS_JSON" | jq -r ".v4.python.\"${PYTHON_VERSION}\"" | sed 's/^v//')
54+
55+
echo "distroless-version=${DISTROLESS_VERSION}" >> $GITHUB_OUTPUT
56+
echo "📦 Python ${PYTHON_VERSION} v4 Distroless Version: ${DISTROLESS_VERSION}"
57+
3958
compute-metadata:
4059
name: Compute Image Metadata
4160
runs-on: ubuntu-latest
@@ -108,7 +127,7 @@ jobs:
108127
cat test-summary.md >> $GITHUB_STEP_SUMMARY
109128
build-and-push-agent:
110129
runs-on: ubuntu-latest
111-
needs: [test, compute-metadata] # Don't run the build and push if the unit tests fail
130+
needs: [test, compute-metadata, fetch-distroless-versions] # Don't run the build and push if the unit tests fail
112131
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
113132
permissions:
114133
contents: read
@@ -149,6 +168,8 @@ jobs:
149168
echo "🏷️ Tags: ${TAGS}"
150169
export REGISTRY=${REGISTRY@L}
151170
export BUILD_ARGS="--push"
171+
export DISTROLESS_VERSION=${{ needs.fetch-distroless-versions.outputs.distroless-version }}
172+
export PYTHON_VERSION=${{ env.PYTHON_VERSION }}
152173
make docker-build-only agent_version=${AGENT_VERSION}
153174
cat metadata.json
154175
echo "digest=$(cat metadata.json | jq -r .\"containerimage.digest\")" >> $GITHUB_OUTPUT

.github/workflows/operator-ci.yaml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ env:
4545
PLATFORMS: linux/amd64,linux/arm64
4646

4747
jobs:
48+
fetch-distroless-versions:
49+
name: Fetch Latest Distroless Versions
50+
runs-on: ubuntu-latest
51+
outputs:
52+
go-version: ${{ steps.fetch.outputs.go-version }}
53+
steps:
54+
- name: Fetch versions from NVIDIA CDN
55+
id: fetch
56+
run: |
57+
# Fetch the versions.json file
58+
VERSIONS_JSON=$(curl -fsSL https://developer.download.nvidia.com/distroless-oss/versions.json)
59+
60+
# Extract latest Go v4 version (format: "v4.0.1" -> "4.0.1")
61+
GO_DISTROLESS_VERSION=$(echo "$VERSIONS_JSON" | jq -r '.v4.go.go' | sed 's/^v//')
62+
63+
echo "go-version=${GO_DISTROLESS_VERSION}" >> $GITHUB_OUTPUT
64+
echo "📦 Go v4 Distroless Version: ${GO_DISTROLESS_VERSION}"
65+
4866
# Test operator across supported Kubernetes versions and test suites
4967
tests:
5068
runs-on: ubuntu-latest
@@ -179,7 +197,7 @@ jobs:
179197
# Compute image tags and version metadata once for reuse
180198
compute-metadata:
181199
runs-on: ubuntu-latest
182-
needs: [tests]
200+
needs: [tests, fetch-distroless-versions]
183201
outputs:
184202
git-sha: ${{ steps.meta.outputs.git-sha }}
185203
version: ${{ steps.meta.outputs.version }}
@@ -217,7 +235,7 @@ jobs:
217235
# Build container images on native architecture runners (much faster than QEMU)
218236
build-operator:
219237
runs-on: ${{ matrix.runner }}
220-
needs: [compute-metadata]
238+
needs: [compute-metadata, fetch-distroless-versions]
221239
strategy:
222240
matrix:
223241
include:
@@ -271,6 +289,7 @@ jobs:
271289
--build-arg GIT_SHA=${GIT_SHA} \
272290
--build-arg VERSION=${VERSION} \
273291
--build-arg GO_VERSION=${{ env.GO_VERSION }} \
292+
--build-arg DISTROLESS_VERSION=${{ needs.fetch-distroless-versions.outputs.go-version }} \
274293
--push \
275294
--platform ${{ matrix.platform }} \
276295
--provenance=false \

agent/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ docker-build-only:
6363
@echo "Building skyhook-agent $(DOCKER_CMD) image with tags: $(ACTUAL_TAGS)"
6464
$(DOCKER_CMD) buildx build $(BUILD_ARGS) --build-arg AGENT_VERSION=$(AGENT_VERSION) \
6565
--build-arg GIT_SHA=$(GIT_SHA) \
66+
--build-arg DISTROLESS_VERSION=$(DISTROLESS_VERSION) \
67+
--build-arg PYTHON_VERSION=$(PYTHON_VERSION) \
6668
--platform linux/amd64,linux/arm64 $(ACTUAL_TAGS) --metadata-file=metadata.json -f ../containers/agent.Dockerfile .
6769

6870
##@ Vendor

containers/agent.Dockerfile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
FROM python:3.12-bookworm AS builder
1818

19-
ARG AGENT_VERSION
19+
ARG AGENT_VERSION
2020

2121
COPY . /code
2222
WORKDIR /code
@@ -36,17 +36,24 @@ RUN make build build_version=${AGENT_VERSION}
3636
# Install the wheel in the builder stage
3737
RUN python3 -m venv venv && ./venv/bin/pip install /code/skyhook-agent/dist/skyhook_agent*.whl
3838

39-
FROM nvcr.io/nvidia/distroless/python:3.12-v3.5.2
39+
ARG DISTROLESS_VERSION \
40+
PYTHON_VERSION
4041

41-
ARG AGENT_VERSION
42-
ARG GIT_SHA
42+
FROM nvcr.io/nvidia/distroless/python:${PYTHON_VERSION}-v${DISTROLESS_VERSION}
43+
44+
ARG AGENT_VERSION \
45+
GIT_SHA \
46+
DISTROLESS_VERSION \
47+
PYTHON_VERSION
4348

4449
## https://github.com/opencontainers/image-spec/blob/main/annotations.md
45-
LABEL org.opencontainers.image.base.name="nvcr.io/nvidia/distroless/python:3.12-v3.5.2" \
50+
LABEL org.opencontainers.image.base.name="nvcr.io/nvidia/distroless/python:${PYTHON_VERSION}-v${DISTROLESS_VERSION}" \
4651
org.opencontainers.image.licenses="Apache-2.0" \
4752
org.opencontainers.image.title="skyhook-agent" \
4853
org.opencontainers.image.version="${AGENT_VERSION}" \
4954
org.opencontainers.image.revision="${GIT_SHA}"
55+
python.version="${PYTHON_VERSION}" \
56+
distroless.version="${DISTROLESS_VERSION}"
5057

5158
# Copy the installed packages and scripts from builder
5259
COPY --from=builder /code/venv/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages

containers/operator.Dockerfile

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
#
44
#
@@ -19,11 +19,11 @@ ARG GO_VERSION
1919

2020
FROM golang:${GO_VERSION}-bookworm as builder
2121

22-
ARG TARGETOS
23-
ARG TARGETARCH
24-
ARG VERSION
25-
ARG GIT_SHA
26-
ARG GO_VERSION
22+
ARG TARGETOS \
23+
TARGETARCH \
24+
VERSION \
25+
GIT_SHA \
26+
GO_VERSION
2727

2828
WORKDIR /workspace
2929

@@ -35,25 +35,28 @@ COPY ./ ./
3535
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
3636
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
3737
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -mod=vendor \
38-
-ldflags "-X github.com/NVIDIA/skyhook/internal/version.GIT_SHA=${GIT_SHA}\
39-
-X github.com/NVIDIA/skyhook/internal/version.VERSION=${VERSION}" \
38+
-ldflags "-X github.com/NVIDIA/skyhook/operator/internal/version.GIT_SHA=${GIT_SHA}\
39+
-X github.com/NVIDIA/skyhook/operator/internal/version.VERSION=${VERSION}" \
4040
-a -o manager cmd/manager/main.go
4141

42+
ARG DISTROLESS_VERSION
4243
# Use distroless as minimal base image to package the manager binary
4344
# Refer to https://github.com/GoogleContainerTools/distroless/tree/main/base for more
44-
FROM nvcr.io/nvidia/distroless/go:v3.2.2
45+
FROM nvcr.io/nvidia/distroless/go:v${DISTROLESS_VERSION}
4546

4647
ARG VERSION
47-
ARG GIT_SHA
48-
ARG GO_VERSION
48+
GIT_SHA \
49+
GO_VERSION \
50+
DISTROLESS_VERSION
4951

5052
## https://github.com/opencontainers/image-spec/blob/main/annotations.md
51-
LABEL org.opencontainers.image.base.name="nvcr.io/nvidia/distroless/go:v3.2.2" \
53+
LABEL org.opencontainers.image.base.name="nvcr.io/nvidia/distroless/go:v${DISTROLESS_VERSION}" \
5254
org.opencontainers.image.licenses="Apache-2.0" \
5355
org.opencontainers.image.title="skyhook-operator" \
5456
org.opencontainers.image.version="${VERSION}" \
5557
org.opencontainers.image.revision="${GIT_SHA}" \
56-
go.version="${GO_VERSION}"
58+
go.version="${GO_VERSION}" \
59+
distroless.version="${DISTROLESS_VERSION}"
5760

5861
WORKDIR /
5962
COPY --from=builder /workspace/manager .

operator/api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)