Skip to content
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

Add minimal ubi8 container #61

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
32 changes: 32 additions & 0 deletions deployments/container/Dockerfile.ubi8
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2024 NVIDIA CORPORATION
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# We use the ubi8-minimal image as a reference image in removing unneeded dependencies.
FROM redhat/ubi8-minimal:latest AS minimal

RUN rpm -qa --queryformat='^%{NAME}-\[0-9\].*\.%{ARCH}$\n' | sort -u > /tmp/minimal-list.txt
tariq1890 marked this conversation as resolved.
Show resolved Hide resolved
RUN rpm -qa | sort -u > /tmp/minimal-list.versions

# We define the following image as a base image and remove unneeded packages.
FROM nvcr.io/nvidia/cuda:12.5.0-base-ubi8 AS base

WORKDIR /cleanup

COPY --from=minimal /tmp/minimal-list.txt minimal-list.txt
COPY --from=minimal /tmp/minimal-list.versions minimal-list.versions
COPY deployments/container/cleanup/* .

RUN ./cleanup.sh

WORKDIR /
110 changes: 110 additions & 0 deletions deployments/container/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Copyright (c) 2021-2022, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

BUILD_MULTI_ARCH_IMAGES ?= no
DOCKER ?= docker
BUILDX =
ifeq ($(BUILD_MULTI_ARCH_IMAGES),true)
BUILDX = buildx
endif
MKDIR ?= mkdir

##### Global variables #####
include $(CURDIR)/versions.mk

IMAGE_NAME ?= cnt-base-image

ifeq ($(IMAGE_NAME),)
IMAGE_NAME := $(REGISTRY)/$(DRIVER_NAME)
endif

IMAGE_VERSION := $(VERSION)

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

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

##### Public rules #####
DEFAULT_PUSH_TARGET := ubuntu22.04
DISTRIBUTIONS = $(DEFAULT_PUSH_TARGET) ubi8

IMAGE_TARGETS := $(patsubst %,image-%,$(DISTRIBUTIONS))
BUILD_TARGETS := $(patsubst %,build-%,$(DISTRIBUTIONS))
PUSH_TARGETS := $(patsubst %,push-%,$(DISTRIBUTIONS))
TEST_TARGETS := $(patsubst %,test-%, $(DISTRIBUTIONS))

.PHONY: $(DISTRIBUTIONS) $(PUSH_TARGETS) $(BUILD_TARGETS) $(TEST_TARGETS) $(BUILD_TARGETS)

ifneq ($(BUILD_MULTI_ARCH_IMAGES),true)
include $(CURDIR)/deployments/container/native-only.mk
else
include $(CURDIR)/deployments/container/multi-arch.mk
endif

# For the default push target we also push a short tag equal to the version.
# We skip this for the development release
DEVEL_RELEASE_IMAGE_VERSION ?= devel
PUSH_MULTIPLE_TAGS ?= true
ifeq ($(strip $(OUT_IMAGE_VERSION)),$(DEVEL_RELEASE_IMAGE_VERSION))
PUSH_MULTIPLE_TAGS = false
endif
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_SUFFIX)

# Use a generic build target to build the relevant images
$(IMAGE_TARGETS): image-%:
DOCKER_BUILDKIT=1 \
$(DOCKER) $(BUILDX) build --pull \
--provenance=false --sbom=false \
$(DOCKER_BUILD_OPTIONS) \
$(DOCKER_BUILD_PLATFORM_OPTIONS) \
--tag $(IMAGE) \
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
--build-arg VERSION="$(VERSION)" \
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
$(if $(LABEL_IMAGE_SOURCE),--label "org.opencontainers.image.source=$(LABEL_IMAGE_SOURCE)",) \
-f $(DOCKERFILE) \
$(CURDIR)

build-ubuntu%: DOCKERFILE_SUFFIX := ubuntu

build-ubi8: DOCKERFILE_SUFFIX := ubi8

# Handle the default build target.
.PHONY: build
build: $(DEFAULT_PUSH_TARGET)
$(DEFAULT_PUSH_TARGET): build-$(DEFAULT_PUSH_TARGET)
$(DEFAULT_PUSH_TARGET): DIST = $(DEFAULT_PUSH_TARGET)

REGCTL ?= regctl
$(PUSH_TARGETS): push-%:
$(REGCTL) \
image copy \
$(IMAGE) $(OUT_IMAGE)

push-short:
$(REGCTL) \
image copy \
$(IMAGE) $(OUT_IMAGE_NAME):$(OUT_IMAGE_VERSION)
48 changes: 48 additions & 0 deletions deployments/container/cleanup/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
# Copyright 2024 NVIDIA CORPORATION
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
# See the License for the specific language governing permissions and
# limitations under the License.

echo "install_weak_deps=False" >> /etc/dnf/dnf.conf
rm -f /etc/dnf/protected.d/*.conf

rm -f /etc/yum.repos.d/cuda.repo
rm -f /etc/ld.so.conf.d/nvidia.conf

dnf remove -y \
cuda* \
systemd

dnf clean all
rm -rf /var/cache/dnf

dnf install -y microdnf

microdnf remove $(rpm -q --whatrequires dnf)
rpm -e dnf

microdnf remove \
$(rpm -q --whatrequires /usr/libexec/platform-python) \
$(rpm -q --whatrequires 'python(abi)') \
python* \
dnf*

microdnf remove \

Choose a reason for hiding this comment

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

does this ensure there are no broken dependencies? i.e remaining packages in the cuda:12.5.0-base-ubi8 might have dependencies on packages removed with the minimal list as a reference?

Copy link
Member Author

Choose a reason for hiding this comment

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

In my testing, microdnf still respects package dependencies, meaning that if x depends on y, one cannot remove y.

For example, let's say we want to remove openssl we see the following in the image:

$ microdnf remove openssl*
error: Could not depsolve transaction; 1 problem detected:
 Problem: package curl-7.61.1-34.el8.x86_64 from @System requires libcrypto.so.1.1()(64bit), but none of the providers can be installed
  - package curl-7.61.1-34.el8.x86_64 from @System requires libssl.so.1.1()(64bit), but none of the providers can be installed
  - conflicting requests
  - problem with installed package curl-7.61.1-34.el8.x86_64

$(rpm -qa | sort | grep -v -f minimal-list.txt -e gpg-pubkey)

microdnf update

rpm -qa | sort -u > package-list.versions

microdnf clean all
rm -rf /var/cache/dnf
19 changes: 19 additions & 0 deletions deployments/container/multi-arch.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

PUSH_ON_BUILD ?= false
DOCKER_BUILD_OPTIONS = --output=type=image,push=$(PUSH_ON_BUILD)
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64,linux/arm64

$(BUILD_TARGETS): build-%: image-%
31 changes: 31 additions & 0 deletions deployments/container/native-only.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

PUSH_ON_BUILD ?= false
DOCKER_BUILD_PLATFORM_OPTIONS = --platform=linux/amd64

ifeq ($(PUSH_ON_BUILD),true)
$(BUILD_TARGETS): build-%: image-%
$(DOCKER) push "$(IMAGE)"
else
$(BUILD_TARGETS): build-%: image-%
endif

# For the default distribution we also retag the image.
# Note: This needs to be updated for multi-arch images.
ifeq ($(IMAGE_TAG),$(VERSION)-$(DIST))
$(DEFAULT_PUSH_TARGET):
$(DOCKER) image inspect $(IMAGE) > /dev/null || $(DOCKER) pull $(IMAGE)
$(DOCKER) tag $(IMAGE) $(subst :$(IMAGE_TAG),:$(VERSION),$(IMAGE))
endif
3 changes: 3 additions & 0 deletions versions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

VERSION ?= $(shell git describe --tags --always 2>/dev/null)

GOLANG_VERSION ?= 1.22.3