mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-12-05 02:25:22 +00:00
Add dockerfile and makefile to build toolkit-container
This change adds platform-specific Dockerfiles and a Makefile
to build the toolkit-container images.
This image builds the container-config commands from the tools
directory and installs the components of the NVIDIA Container Toolkit
directly from the nvidia-container-toolkit and libnvidia-container*
packages in the dist directory.
This includes make targets for the centos7, centos8, ubuntu18.04,
and ubi8 container-toolkit images as well as the container tests
make targets implemented in the contianer-config repository.
Files adapted from:
383587f766
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
f2c93363ab
commit
0b3bc13b32
@ -1,2 +1,2 @@
|
|||||||
.git
|
.git
|
||||||
dist
|
/shared-*
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ dist
|
|||||||
/test/output/
|
/test/output/
|
||||||
/nvidia-container-runtime
|
/nvidia-container-runtime
|
||||||
/nvidia-container-toolkit
|
/nvidia-container-toolkit
|
||||||
|
/shared-*
|
||||||
|
75
build/container/Dockerfile.centos
Normal file
75
build/container/Dockerfile.centos
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
# Copyright (c) 2019-2021, 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.
|
||||||
|
|
||||||
|
ARG BASE_DIST
|
||||||
|
ARG CUDA_VERSION
|
||||||
|
ARG GOLANG_VERSION=x.x.x
|
||||||
|
ARG VERSION="N/A"
|
||||||
|
|
||||||
|
# NOTE: In cases where the libc version is a concern, we would have to use an
|
||||||
|
# image based on the target OS to build the golang executables here -- especially
|
||||||
|
# if cgo code is included.
|
||||||
|
FROM golang:${GOLANG_VERSION} as build
|
||||||
|
|
||||||
|
# We override the GOPATH to ensure that the binaries are installed to
|
||||||
|
# /artifacts/bin
|
||||||
|
ARG GOPATH=/artifacts
|
||||||
|
|
||||||
|
# Install the experiemental nvidia-container-runtime
|
||||||
|
# NOTE: This will be integrated into the nvidia-container-toolkit package / repo
|
||||||
|
ARG NVIDIA_CONTAINER_RUNTIME_EXPERIMENTAL_VERSION=experimental
|
||||||
|
RUN go install github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-container-runtime.experimental@${NVIDIA_CONTAINER_RUNTIME_EXPERIMENTAL_VERSION}
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# NOTE: Until the config utilities are properly integrated into the
|
||||||
|
# nvidia-container-toolkit repository, these are built from the `tools` folder
|
||||||
|
# and not `cmd`.
|
||||||
|
RUN go install -ldflags="-s -w -X 'main.Version=${VERSION}'" ./tools/...
|
||||||
|
|
||||||
|
|
||||||
|
FROM nvidia/cuda:${CUDA_VERSION}-base-${BASE_DIST}
|
||||||
|
|
||||||
|
ENV NVIDIA_DISABLE_REQUIRE="true"
|
||||||
|
ENV NVIDIA_VISIBLE_DEVICES=all
|
||||||
|
ENV NVIDIA_DRIVER_CAPABILITIES=utility
|
||||||
|
|
||||||
|
WORKDIR /artifacts/packages
|
||||||
|
|
||||||
|
ARG ARTIFACTS_DIR
|
||||||
|
COPY ${ARTIFACTS_DIR}/* /artifacts/packages
|
||||||
|
|
||||||
|
ARG PACKAGE_VERSION
|
||||||
|
RUN yum localinstall -y \
|
||||||
|
libnvidia-container1-${PACKAGE_VERSION}*.rpm \
|
||||||
|
libnvidia-container-tools-${PACKAGE_VERSION}*.rpm \
|
||||||
|
nvidia-container-toolkit-${PACKAGE_VERSION}*.rpm
|
||||||
|
|
||||||
|
WORKDIR /work
|
||||||
|
|
||||||
|
COPY --from=build /artifacts/bin /work
|
||||||
|
|
||||||
|
ENV PATH=/work:$PATH
|
||||||
|
|
||||||
|
LABEL io.k8s.display-name="NVIDIA Container Runtime Config"
|
||||||
|
LABEL name="NVIDIA Container Runtime Config"
|
||||||
|
LABEL vendor="NVIDIA"
|
||||||
|
LABEL version="${VERSION}"
|
||||||
|
LABEL release="N/A"
|
||||||
|
LABEL summary="Automatically Configure your Container Runtime for GPU support."
|
||||||
|
LABEL description="See summary"
|
||||||
|
|
||||||
|
COPY ./LICENSE /licenses/LICENSE
|
||||||
|
|
||||||
|
ENTRYPOINT ["/work/nvidia-toolkit"]
|
81
build/container/Dockerfile.ubuntu
Normal file
81
build/container/Dockerfile.ubuntu
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
# Copyright (c) 2019-2021, 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.
|
||||||
|
|
||||||
|
ARG BASE_DIST
|
||||||
|
ARG CUDA_VERSION
|
||||||
|
ARG GOLANG_VERSION=x.x.x
|
||||||
|
ARG VERSION="N/A"
|
||||||
|
|
||||||
|
# NOTE: In cases where the libc version is a concern, we would have to use an
|
||||||
|
# image based on the target OS to build the golang executables here -- especially
|
||||||
|
# if cgo code is included.
|
||||||
|
FROM golang:${GOLANG_VERSION} as build
|
||||||
|
|
||||||
|
# We override the GOPATH to ensure that the binaries are installed to
|
||||||
|
# /artifacts/bin
|
||||||
|
ARG GOPATH=/artifacts
|
||||||
|
|
||||||
|
# Install the experiemental nvidia-container-runtime
|
||||||
|
# NOTE: This will be integrated into the nvidia-container-toolkit package / repo
|
||||||
|
ARG NVIDIA_CONTAINER_RUNTIME_EXPERIMENTAL_VERSION=experimental
|
||||||
|
RUN go install github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-container-runtime.experimental@${NVIDIA_CONTAINER_RUNTIME_EXPERIMENTAL_VERSION}
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# NOTE: Until the config utilities are properly integrated into the
|
||||||
|
# nvidia-container-toolkit repository, these are built from the `tools` folder
|
||||||
|
# and not `cmd`.
|
||||||
|
RUN go install -ldflags="-s -w -X 'main.Version=${VERSION}'" ./tools/...
|
||||||
|
|
||||||
|
|
||||||
|
FROM nvidia/cuda:${CUDA_VERSION}-base-${BASE_DIST}
|
||||||
|
|
||||||
|
ARG DEBIAN_FRONTEND=noninteractive
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
libcap2 \
|
||||||
|
&& \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
ENV NVIDIA_DISABLE_REQUIRE="true"
|
||||||
|
ENV NVIDIA_VISIBLE_DEVICES=all
|
||||||
|
ENV NVIDIA_DRIVER_CAPABILITIES=utility
|
||||||
|
|
||||||
|
WORKDIR /artifacts/packages
|
||||||
|
|
||||||
|
ARG ARTIFACTS_DIR
|
||||||
|
COPY ${ARTIFACTS_DIR}/* /artifacts/packages
|
||||||
|
|
||||||
|
ARG PACKAGE_VERSION
|
||||||
|
RUN dpkg -i \
|
||||||
|
libnvidia-container1_${PACKAGE_VERSION}*.deb \
|
||||||
|
libnvidia-container-tools_${PACKAGE_VERSION}*.deb \
|
||||||
|
nvidia-container-toolkit_${PACKAGE_VERSION}*.deb
|
||||||
|
|
||||||
|
WORKDIR /work
|
||||||
|
|
||||||
|
COPY --from=build /artifacts/bin /work
|
||||||
|
|
||||||
|
ENV PATH=/work:$PATH
|
||||||
|
|
||||||
|
LABEL io.k8s.display-name="NVIDIA Container Runtime Config"
|
||||||
|
LABEL name="NVIDIA Container Runtime Config"
|
||||||
|
LABEL vendor="NVIDIA"
|
||||||
|
LABEL version="${VERSION}"
|
||||||
|
LABEL release="N/A"
|
||||||
|
LABEL summary="Automatically Configure your Container Runtime for GPU support."
|
||||||
|
LABEL description="See summary"
|
||||||
|
|
||||||
|
COPY ./LICENSE /licenses/LICENSE
|
||||||
|
|
||||||
|
ENTRYPOINT ["/work/nvidia-toolkit"]
|
108
build/container/Makefile
Normal file
108
build/container/Makefile
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
# Copyright (c) 2021, 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.
|
||||||
|
|
||||||
|
DOCKER ?= docker
|
||||||
|
MKDIR ?= mkdir
|
||||||
|
DIST_DIR ?= $(CURDIR)/dist
|
||||||
|
|
||||||
|
##### Global variables #####
|
||||||
|
|
||||||
|
# TODO: These should be defined ONCE and currently duplicate the version in the
|
||||||
|
# toolkit makefile.
|
||||||
|
LIB_VERSION := 1.6.0
|
||||||
|
LIB_TAG := rc.1
|
||||||
|
|
||||||
|
VERSION ?= $(LIB_VERSION)$(if $(LIB_TAG),-$(LIB_TAG))
|
||||||
|
|
||||||
|
CUDA_VERSION ?= 11.4.2
|
||||||
|
GOLANG_VERSION ?= 1.16.4
|
||||||
|
ifeq ($(IMAGE_NAME),)
|
||||||
|
REGISTRY ?= nvidia
|
||||||
|
IMAGE_NAME := $(REGISTRY)/container-toolkit
|
||||||
|
endif
|
||||||
|
|
||||||
|
IMAGE_TAG ?= $(VERSION)-$(DIST)
|
||||||
|
IMAGE = $(IMAGE_NAME):$(IMAGE_TAG)
|
||||||
|
|
||||||
|
##### Public rules #####
|
||||||
|
DEFAULT_PUSH_TARGET := ubuntu18.04
|
||||||
|
TARGETS := ubuntu20.04 ubuntu18.04 ubi8 centos7 centos8
|
||||||
|
|
||||||
|
BUILD_TARGETS := $(patsubst %, build-%, $(TARGETS))
|
||||||
|
# PUSH_TARGETS := $(patsubst %, push-%, $(TARGETS))
|
||||||
|
TEST_TARGETS := $(patsubst %, test-%, $(TARGETS))
|
||||||
|
|
||||||
|
.PHONY: $(TARGETS) $(PUSH_TARGETS) $(BUILD_TARGETS) $(TEST_TARGETS)
|
||||||
|
|
||||||
|
$(PUSH_TARGETS): push-%:
|
||||||
|
$(DOCKER) push "$(IMAGE_NAME):$(IMAGE_TAG)"
|
||||||
|
|
||||||
|
# For the default push target we also push a short tag equal to the version.
|
||||||
|
# We skip this for the development release
|
||||||
|
RELEASE_DEVEL_TAG ?= devel
|
||||||
|
ifneq ($(strip $(VERSION)),$(RELEASE_DEVEL_TAG))
|
||||||
|
push-$(DEFAULT_PUSH_TARGET): push-short
|
||||||
|
endif
|
||||||
|
push-short:
|
||||||
|
$(DOCKER) tag "$(IMAGE_NAME):$(VERSION)-$(DEFAULT_PUSH_TARGET)" "$(IMAGE_NAME):$(VERSION)"
|
||||||
|
$(DOCKER) push "$(IMAGE_NAME):$(VERSION)"
|
||||||
|
|
||||||
|
|
||||||
|
build-%: DIST = $(*)
|
||||||
|
build-%: DOCKERFILE = $(CURDIR)/build/container/Dockerfile.$(DOCKERFILE_SUFFIX)
|
||||||
|
|
||||||
|
# Use a generic build target to build the relevant images
|
||||||
|
$(BUILD_TARGETS): build-%: $(ARTIFACTS_DIR)
|
||||||
|
$(DOCKER) build --pull \
|
||||||
|
--tag $(IMAGE) \
|
||||||
|
--build-arg ARTIFACTS_DIR="$(ARTIFACTS_DIR)" \
|
||||||
|
--build-arg BASE_DIST="$(BASE_DIST)" \
|
||||||
|
--build-arg CUDA_VERSION="$(CUDA_VERSION)" \
|
||||||
|
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
|
||||||
|
--build-arg PACKAGE_VERSION="$(PACKAGE_VERSION)" \
|
||||||
|
--build-arg VERSION="$(VERSION)" \
|
||||||
|
-f $(DOCKERFILE) \
|
||||||
|
$(CURDIR)
|
||||||
|
|
||||||
|
|
||||||
|
build-ubuntu%: DOCKERFILE_SUFFIX := ubuntu
|
||||||
|
build-ubuntu%: ARTIFACTS_DIR = dist/$(*)/amd64
|
||||||
|
build-ubuntu%: PACKAGE_VERSION := $(LIB_VERSION)$(if $(LIB_TAG),~$(LIB_TAG))
|
||||||
|
|
||||||
|
build-ubuntu18.04: BASE_DIST := ubuntu18.04
|
||||||
|
build-ubuntu20.04: BASE_DIST := ubuntu20.04
|
||||||
|
|
||||||
|
build-ubi8: DOCKERFILE_SUFFIX := centos
|
||||||
|
# TODO: Update this to use the centos8 packages
|
||||||
|
build-ubi8: ARTIFACTS_DIR = dist/centos7/x86_64
|
||||||
|
build-ubi8: PACKAGE_VERSION := $(LIB_VERSION)-$(if $(LIB_TAG),0.1.$(LIB_TAG),1)
|
||||||
|
build-ubi8: BASE_DIST := ubi8
|
||||||
|
|
||||||
|
build-centos%: DOCKERFILE_SUFFIX := centos
|
||||||
|
build-centos%: ARTIFACTS_DIR = dist/$(*)/x86_64
|
||||||
|
build-centos%: PACKAGE_VERSION := $(LIB_VERSION)-$(if $(LIB_TAG),0.1.$(LIB_TAG),1)
|
||||||
|
|
||||||
|
build-centos7: BASE_DIST := centos7
|
||||||
|
build-centos8: BASE_DIST := centos8
|
||||||
|
|
||||||
|
# Test targets
|
||||||
|
test-%: DIST = $(*)
|
||||||
|
|
||||||
|
TEST_CASES ?= toolkit docker crio containerd
|
||||||
|
$(TEST_TARGETS): test-%:
|
||||||
|
TEST_CASES="$(TEST_CASES)" bash -x $(CURDIR)/test/container/main.sh run \
|
||||||
|
$(CURDIR)/shared-$(*) \
|
||||||
|
$(IMAGE) \
|
||||||
|
--no-cleanup-on-error
|
||||||
|
|
4
build/container/README.md
Normal file
4
build/container/README.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# NVIDIA Container Toolkit Container
|
||||||
|
|
||||||
|
This folder contains make and docker files for building the NVIDIA Container Toolkit Container.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user