Skip to content

Commit 4772e32

Browse files
authored
Merge pull request #1291 from elezar/switch-to-distroless
Switch to distroless golang image
2 parents b859768 + 964f9d6 commit 4772e32

File tree

5 files changed

+27
-137
lines changed

5 files changed

+27
-137
lines changed

.common-ci.yml

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,6 @@ trigger-pipeline:
6868
allow_failure: false
6969
- when: always
7070

71-
# The .dist- dummy steps set the DIST variable for the targeted distribution.
72-
.dist-ubi9:
73-
variables:
74-
DIST: "ubi9"
75-
7671
# Define the platform targets
7772
.platform-amd64:
7873
variables:
@@ -101,7 +96,7 @@ trigger-pipeline:
10196
.scan-base:
10297
stage: scan
10398
variables:
104-
IMAGE: "${CI_REGISTRY_IMAGE}/k8s-device-plugin:${CI_COMMIT_SHORT_SHA}-${DIST}"
99+
IMAGE: "${CI_REGISTRY_IMAGE}/k8s-device-plugin:${CI_COMMIT_SHORT_SHA}"
105100
IMAGE_ARCHIVE: "k8s-device-plugin.tar"
106101
except:
107102
variables:
@@ -119,22 +114,20 @@ trigger-pipeline:
119114
- .scan-base
120115

121116
# Define the scan targets
122-
scan-ubi9-amd64:
117+
scan-amd64:
123118
extends:
124119
- .scan
125-
- .dist-ubi9
126120
- .platform-amd64
127121
needs:
128-
- image-ubi9
122+
- image-pull
129123

130-
scan-ubi9-arm64:
124+
scan-arm64:
131125
extends:
132126
- .scan
133-
- .dist-ubi9
134127
- .platform-arm64
135128
needs:
136-
- image-ubi9
137-
- scan-ubi9-amd64
129+
- image-pull
130+
- scan-amd64
138131

139132
# Download the regctl binary for use in the release steps
140133
.regctl-setup:
@@ -177,7 +170,7 @@ scan-ubi9-arm64:
177170

178171
# Since OUT_IMAGE_NAME and OUT_IMAGE_VERSION are set, this will push the CI image to the
179172
# Target
180-
- make -f deployments/container/Makefile push-${DIST}
173+
- make -f deployments/container/Makefile push-image
181174

182175
# Define a staging release step that pushes an image to an internal "staging" repository
183176
# This is triggered for all pipelines (i.e. not only tags) to test the pipeline steps
@@ -204,9 +197,8 @@ scan-ubi9-arm64:
204197
variables:
205198
OUT_IMAGE_VERSION: "${DEVEL_RELEASE_IMAGE_VERSION}"
206199

207-
release:staging-ubi9:
200+
release:staging:
208201
extends:
209202
- .release:staging
210-
- .dist-ubi9
211203
needs:
212-
- image-ubi9
204+
- image-pull

.nvidia-ci.yml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,14 @@ variables:
6060
- !reference [.regctl-setup, before_script]
6161
- apk add --no-cache make bash
6262
- >
63-
regctl manifest get ${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST} --list > /dev/null && echo "${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST}" || ( echo "${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST} does not exist" && sleep infinity )
63+
regctl manifest get ${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION} --list > /dev/null && echo "${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}" || ( echo "${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION} does not exist" && sleep infinity )
6464
script:
6565
- regctl registry login "${OUT_REGISTRY}" -u "${OUT_REGISTRY_USER}" -p "${OUT_REGISTRY_TOKEN}"
66-
- make -f deployments/container/Makefile IMAGE=${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION}-${DIST} OUT_IMAGE=${OUT_IMAGE_NAME}:${CI_COMMIT_SHORT_SHA}-${DIST} push-${DIST}
66+
- make -f deployments/container/Makefile IMAGE=${IN_REGISTRY}/${IN_IMAGE_NAME}:${IN_VERSION} OUT_IMAGE=${OUT_IMAGE_NAME}:${CI_COMMIT_SHORT_SHA} push-image
6767

68-
image-ubi9:
68+
image-pull:
6969
extends:
7070
- .image-pull
71-
- .dist-ubi9
7271

7372
# We skip the integration tests for the internal CI:
7473
.integration:
@@ -113,10 +112,9 @@ image-ubi9:
113112

114113
# Define the external release targets
115114
# Release to NGC
116-
release:ngc-ubi9:
115+
release:ngc:
117116
extends:
118117
- .release:ngc
119-
- .dist-ubi9
120118

121119
# Define the external image signing steps for NGC
122120
# Download the ngc cli binary for use in the sign steps
@@ -144,7 +142,7 @@ release:ngc-ubi9:
144142
variables:
145143
NGC_CLI_API_KEY: "${NGC_REGISTRY_TOKEN}"
146144
IMAGE_NAME: "${NGC_REGISTRY_IMAGE}"
147-
IMAGE_TAG: "${CI_COMMIT_TAG}-${DIST}"
145+
IMAGE_TAG: "${CI_COMMIT_TAG}"
148146
retry:
149147
max: 2
150148
before_script:
@@ -156,17 +154,10 @@ release:ngc-ubi9:
156154
- 'echo "Signing the image ${IMAGE_NAME}:${IMAGE_TAG}"'
157155
- ngc-cli/ngc registry image publish --source ${IMAGE_NAME}:${IMAGE_TAG} ${IMAGE_NAME}:${IMAGE_TAG} --public --discoverable --allow-guest --sign --org nvidia
158156

159-
sign:ngc-short-tag:
157+
sign:ngc:
160158
extends:
161159
- .sign:ngc
162160
needs:
163-
- release:ngc-ubi9
161+
- release:ngc
164162
variables:
165163
IMAGE_TAG: "${CI_COMMIT_TAG}"
166-
167-
sign:ngc-ubi9:
168-
extends:
169-
- .dist-ubi9
170-
- .sign:ngc
171-
needs:
172-
- release:ngc-ubi9

deployments/container/Dockerfile

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ RUN set -eux; \
3333
wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${ARCH}.tar.gz \
3434
| tar -C /usr/local -xz
3535

36-
ENV GOPATH /go
37-
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
36+
ENV GOPATH=/go
37+
ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH
3838

3939
WORKDIR /build
4040
COPY . .
@@ -50,22 +50,11 @@ FROM redhat/ubi9-minimal:latest AS minimal
5050
RUN rpm -qa --queryformat='^%{NAME}-\[0-9\].*\.%{ARCH}$\n' | sort -u > /tmp/package-names.minimal
5151
RUN rpm -qa | sort -u > /tmp/package-list.minimal
5252

53-
# We define the following image as a base image and remove unneeded packages.
54-
FROM nvcr.io/nvidia/cuda:12.9.1-base-ubi9 AS base
53+
FROM nvcr.io/nvidia/distroless/go:v3.1.9-dev
5554

56-
WORKDIR /cleanup
57-
58-
COPY --from=minimal /tmp/package-names.minimal package-names.minimal
59-
COPY --from=minimal /tmp/package-list.minimal package-list.minimal
60-
COPY deployments/container/cleanup/* .
61-
62-
RUN ./cleanup.sh
63-
64-
WORKDIR /
65-
66-
# We use the base images constructed above.
67-
# TODO: We will move to a shared base image once this implementation has been stabilized.
68-
FROM base
55+
USER 0:0
56+
SHELL ["/busybox/sh", "-c"]
57+
RUN ln -s /busybox/sh /bin/sh
6958

7059
ENV NVIDIA_DISABLE_REQUIRE="true"
7160
ENV NVIDIA_VISIBLE_DEVICES=all
@@ -83,7 +72,7 @@ LABEL release="N/A"
8372
LABEL summary="NVIDIA device plugin for Kubernetes"
8473
LABEL description="See summary"
8574

86-
RUN mkdir /licenses && mv /NGC-DL-CONTAINER-LICENSE /licenses/NGC-DL-CONTAINER-LICENSE
75+
COPY LICENSE /licenses/
8776

8877
COPY --from=build /artifacts/config-manager /usr/bin/config-manager
8978
COPY --from=build /artifacts/gpu-feature-discovery /usr/bin/gpu-feature-discovery

deployments/container/Makefile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ endif
2929

3030
IMAGE_VERSION := $(VERSION)
3131

32-
IMAGE_TAG ?= $(IMAGE_VERSION)-$(DIST)
32+
IMAGE_TAG ?= $(IMAGE_VERSION)
3333
IMAGE = $(IMAGE_NAME):$(IMAGE_TAG)
3434

3535
OUT_IMAGE_NAME ?= $(IMAGE_NAME)
3636
OUT_IMAGE_VERSION ?= $(IMAGE_VERSION)
37-
OUT_IMAGE_TAG = $(OUT_IMAGE_VERSION)-$(DIST)
37+
OUT_IMAGE_TAG = $(OUT_IMAGE_VERSION)
3838
OUT_IMAGE = $(OUT_IMAGE_NAME):$(OUT_IMAGE_TAG)
3939

4040
##### Public rules #####
41-
DEFAULT_PUSH_TARGET := ubi9
41+
DEFAULT_PUSH_TARGET := image
4242
DISTRIBUTIONS = $(DEFAULT_PUSH_TARGET)
4343

4444
IMAGE_TARGETS := $(patsubst %,image-%,$(DISTRIBUTIONS))
@@ -65,11 +65,8 @@ ifeq ($(PUSH_MULTIPLE_TAGS),true)
6565
push-$(DEFAULT_PUSH_TARGET): push-short
6666
endif
6767

68-
push-%: DIST = $(*)
69-
push-short: DIST = $(DEFAULT_PUSH_TARGET)
7068

71-
build-%: DIST = $(*)
72-
build-%: DOCKERFILE = $(CURDIR)/deployments/container/Dockerfile
69+
DOCKERFILE = $(CURDIR)/deployments/container/Dockerfile
7370

7471
# Use a generic build target to build the relevant images
7572
$(IMAGE_TARGETS): image-%:
@@ -90,7 +87,6 @@ $(IMAGE_TARGETS): image-%:
9087
.PHONY: build
9188
build: $(DEFAULT_PUSH_TARGET)
9289
$(DEFAULT_PUSH_TARGET): build-$(DEFAULT_PUSH_TARGET)
93-
$(DEFAULT_PUSH_TARGET): DIST = $(DEFAULT_PUSH_TARGET)
9490

9591
REGCTL ?= regctl
9692
$(PUSH_TARGETS): push-%:

deployments/container/cleanup/cleanup.sh

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)