Skip to content

Switch to distroless golang image #1291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions deployments/container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ RUN set -eux; \
wget -nv -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-${ARCH}.tar.gz \
| tar -C /usr/local -xz

ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
ENV GOPATH=/go
ENV PATH=$GOPATH/bin:/usr/local/go/bin:$PATH

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

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

WORKDIR /cleanup

COPY --from=minimal /tmp/package-names.minimal package-names.minimal
COPY --from=minimal /tmp/package-list.minimal package-list.minimal
COPY deployments/container/cleanup/* .

RUN ./cleanup.sh

WORKDIR /

# We use the base images constructed above.
# TODO: We will move to a shared base image once this implementation has been stabilized.
FROM base
USER 0:0
SHELL ["/busybox/sh", "-c"]
RUN ln -s /busybox/sh /bin/sh

ENV NVIDIA_DISABLE_REQUIRE="true"
ENV NVIDIA_VISIBLE_DEVICES=all
Expand All @@ -83,7 +72,7 @@ LABEL release="N/A"
LABEL summary="NVIDIA device plugin for Kubernetes"
LABEL description="See summary"

RUN mkdir /licenses && mv /NGC-DL-CONTAINER-LICENSE /licenses/NGC-DL-CONTAINER-LICENSE
COPY LICENSE /licenses/

COPY --from=build /artifacts/config-manager /usr/bin/config-manager
COPY --from=build /artifacts/gpu-feature-discovery /usr/bin/gpu-feature-discovery
Expand Down
12 changes: 4 additions & 8 deletions deployments/container/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ endif

IMAGE_VERSION := $(VERSION)

IMAGE_TAG ?= $(IMAGE_VERSION)-$(DIST)
IMAGE_TAG ?= $(IMAGE_VERSION)
IMAGE = $(IMAGE_NAME):$(IMAGE_TAG)

OUT_IMAGE_NAME ?= $(IMAGE_NAME)
OUT_IMAGE_VERSION ?= $(IMAGE_VERSION)
OUT_IMAGE_TAG = $(OUT_IMAGE_VERSION)-$(DIST)
OUT_IMAGE_TAG = $(OUT_IMAGE_VERSION)
OUT_IMAGE = $(OUT_IMAGE_NAME):$(OUT_IMAGE_TAG)

##### Public rules #####
DEFAULT_PUSH_TARGET := ubi9
DEFAULT_PUSH_TARGET := image
DISTRIBUTIONS = $(DEFAULT_PUSH_TARGET)

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

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

build-%: DIST = $(*)
build-%: DOCKERFILE = $(CURDIR)/deployments/container/Dockerfile
DOCKERFILE = $(CURDIR)/deployments/container/Dockerfile

# Use a generic build target to build the relevant images
$(IMAGE_TARGETS): image-%:
Expand All @@ -90,7 +87,6 @@ $(IMAGE_TARGETS): image-%:
.PHONY: build
build: $(DEFAULT_PUSH_TARGET)
$(DEFAULT_PUSH_TARGET): build-$(DEFAULT_PUSH_TARGET)
$(DEFAULT_PUSH_TARGET): DIST = $(DEFAULT_PUSH_TARGET)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the following image was pushed via the GitHub Actions: ghcr.io/nvidia/k8s-device-plugin:0ea49e43-. The culprit is likely the IMAGE_TAG variable defined on line 32:

IMAGE_TAG ?= $(IMAGE_VERSION)-$(DIST)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I was rushing this a bit.


REGCTL ?= regctl
$(PUSH_TARGETS): push-%:
Expand Down
78 changes: 0 additions & 78 deletions deployments/container/cleanup/cleanup.sh

This file was deleted.

Loading