diff --git a/test/release/Makefile b/test/release/Makefile new file mode 100644 index 00000000..7c58c518 --- /dev/null +++ b/test/release/Makefile @@ -0,0 +1,59 @@ +# 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. + +WORKFLOW ?= nvidia-docker +TEST_REPO ?= elezar.github.io + +DISTRIBUTIONS := ubuntu18.04 centos8 + +IMAGE_TARGETS := $(patsubst %,image-%, $(DISTRIBUTIONS)) +RUN_TARGETS := $(patsubst %,run-%, $(DISTRIBUTIONS)) +RELEASE_TARGETS := $(patsubst %,release-%, $(DISTRIBUTIONS)) +LOCAL_TARGETS := $(patsubst %,local-%, $(DISTRIBUTIONS)) + +.PHONY: $(IMAGE_TARGETS) + +image-%: DOCKERFILE = docker/$(*)/Dockerfile + +images: $(IMAGE_TARGETS) +$(IMAGE_TARGETS): image-%: + docker build \ + --build-arg WORKFLOW="$(WORKFLOW)" \ + --build-arg TEST_REPO="$(TEST_REPO)" \ + -t nvidia-container-toolkit-repo-test:$(*) \ + -f $(DOCKERFILE) \ + $(shell dirname $(DOCKERFILE)) + + +%-ubuntu18.04: ARCH = amd64 +%-centos8: ARCH = x86_64 + +RELEASE_TEST_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))) +PROJECT_ROOT := $(RELEASE_TEST_DIR)/../.. + +LOCAL_PACKAGE_ROOT := $(PROJECT_ROOT)/dist + +local-%: DIST = $(*) +local-%: LOCAL_REPO_ARGS = -v $(LOCAL_PACKAGE_ROOT)/$(DIST)/$(ARCH):/local-repository +$(LOCAL_TARGETS): local-%: release-% run-% | release-% + +run-%: DIST = $(*) +$(RUN_TARGETS): run-%: + docker run --rm -ti \ + $(LOCAL_REPO_ARGS) \ + nvidia-container-toolkit-repo-test:$(*) + +# Ensure that the local package root exists +$(RELEASE_TARGETS): release-%: $(LOCAL_PACKAGE_ROOT)/$(*)/$(ARCH) + $(PROJECT_ROOT)/scripts/release.sh $(*)-$(ARCH) \ No newline at end of file diff --git a/test/release/README.md b/test/release/README.md new file mode 100644 index 00000000..ca998a77 --- /dev/null +++ b/test/release/README.md @@ -0,0 +1,107 @@ +# Testing Packaging Workflows + +## Building the Docker images: + +```bash +make images +``` + +This assumes that the `nvidia-docker` workflow is being tested and that the test packages have been published to the `elezar.github.io` GitHub pages page. These can be overridden +using make variables. + +Valid values for `workflow` are: +* `nvidia-docker` +* `nvidia-container-runtime` + +This follows the instructions for setting up the [`nvidia-docker` repostitory](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#setting-up-nvidia-container-toolkit). + + +## Testing local package changes + +Running: +```bash +make local-ubuntu18.04 +``` +will build the `ubuntu18.04-amd64` packages for release and launch a docker container with these packages added to a local APT repository. + +The various `apt` workflows can then be tested as if the packages were released to the `libnvidia-container` experimental repository. + +The `local-centos8` make target is available for testing the `centos8-x86_64` workflows as representative of `yum`-based installation workflows. + + +### Example + +In the `centos8`-based container above we see the following `nvidia-docker2` packages available with the `local-repository` disabled: + +```bash +$ yum list --showduplicates nvidia-docker2 | tail -2 +nvidia-docker2.noarch 2.5.0-1 nvidia-docker +nvidia-docker2.noarch 2.6.0-1 nvidia-docker +``` + +Installing `nvidia-docker2` shows: +```bash +$ yum install -y nvidia-docker2 +``` + +installs the following packages: +```bash +$ yum list installed | grep nvidia +libnvidia-container-tools.x86_64 1.5.1-1 @libnvidia-container +libnvidia-container1.x86_64 1.5.1-1 @libnvidia-container +nvidia-container-runtime.x86_64 3.5.0-1 @nvidia-container-runtime +nvidia-container-toolkit.x86_64 1.5.1-2 @nvidia-container-runtime +nvidia-docker2.noarch 2.6.0-1 @nvidia-docker +``` +Note the repositories where these packages were installed from. + +We now enable the `local-repository` to simulate the new packages being published to the `libnvidia-container` experimental repository and check the available `nvidia-docker2` versions: +```bash +$ yum-config-manager --enable local-repository +$ yum list --showduplicates nvidia-docker2 | tail -2 +nvidia-docker2.noarch 2.6.0-1 nvidia-docker +nvidia-docker2.noarch 2.6.1-0.1.rc.1 local-repository +``` +Showing the new version available in the local repository. + +Running: +``` +$ yum install nvidia-docker2 +Last metadata expiration check: 0:01:15 ago on Fri Sep 24 12:49:20 2021. +Package nvidia-docker2-2.6.0-1.noarch is already installed. +Dependencies resolved. +=============================================================================================================================== + Package Architecture Version Repository Size +=============================================================================================================================== +Upgrading: + libnvidia-container-tools x86_64 1.6.0-0.1.rc.1 local-repository 48 k + libnvidia-container1 x86_64 1.6.0-0.1.rc.1 local-repository 95 k + nvidia-container-toolkit x86_64 1.6.0-0.1.rc.1 local-repository 1.5 M + replacing nvidia-container-runtime.x86_64 3.5.0-1 + nvidia-docker2 noarch 2.6.1-0.1.rc.1 local-repository 13 k + +Transaction Summary +=============================================================================================================================== +Upgrade 4 Packages + +Total size: 1.7 M +``` +Showing that all the components of the stack will be updated with versions from the `local-repository`. + +After installation the installed packages are shown as: +```bash +$ yum list installed | grep nvidia +libnvidia-container-tools.x86_64 1.6.0-0.1.rc.1 @local-repository +libnvidia-container1.x86_64 1.6.0-0.1.rc.1 @local-repository +nvidia-container-toolkit.x86_64 1.6.0-0.1.rc.1 @local-repository +nvidia-docker2.noarch 2.6.1-0.1.rc.1 @local-repository +``` +Showing that: +1. All versions have been installed from the same repository +2. The `nvidia-container-runtime` package was removed as it is no longer required. + +The `nvidia-container-runtime` executable is, however, still present on the system: +```bash +# ls -l /usr/bin/nvidia-container-runtime +-rwxr-xr-x 1 root root 2256280 Sep 24 12:42 /usr/bin/nvidia-container-runtime +``` diff --git a/test/release/docker/centos8/Dockerfile b/test/release/docker/centos8/Dockerfile new file mode 100644 index 00000000..e0947bbe --- /dev/null +++ b/test/release/docker/centos8/Dockerfile @@ -0,0 +1,35 @@ +FROM centos:8 + +RUN yum install -y \ + yum-utils \ + ruby-devel \ + gcc \ + make \ + rpm-build \ + rubygems \ + createrepo + +RUN gem install --no-document fpm + +# We create and install a dummy docker package since these dependencies are out of +# scope for the tests performed here. +RUN fpm -s empty \ + -t rpm \ + --description "A dummy package for docker-ce_18.06.3.ce-3.el7" \ + -n docker-ce --version 18.06.3.ce-3.el7 \ + -p /tmp/docker.rpm \ + && \ + yum localinstall -y /tmp/docker.rpm \ + && \ + rm -f /tmp/docker.rpm + + +ARG WORKFLOW=nvidia-docker +ARG TEST_REPO=nvidia.github.io +ENV TEST_REPO ${TEST_REPO} +RUN curl -s -L https://nvidia.github.io/${WORKFLOW}/centos8/nvidia-docker.repo \ + | tee /etc/yum.repos.d/nvidia-docker.repo + +COPY entrypoint.sh / + +ENTRYPOINT [ "/entrypoint.sh" ] \ No newline at end of file diff --git a/test/release/docker/centos8/entrypoint.sh b/test/release/docker/centos8/entrypoint.sh new file mode 100755 index 00000000..9dd4de0e --- /dev/null +++ b/test/release/docker/centos8/entrypoint.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# 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. + +# This script is used to build the packages for the components of the NVIDIA +# Container Stack. These include the nvidia-container-toolkit in this repository +# as well as the components included in the third_party folder. +# All required packages are generated in the specified dist folder. + +: ${LOCAL_REPO_DIRECTORY:=/local-repository} +if [[ -d ${LOCAL_REPO_DIRECTORY} ]]; then + echo "Setting up local-repository" + createrepo /local-repository + + cat >/etc/yum.repos.d/local.repo < /etc/apt/sources.list.d/local.list + $(cd /local-repository && apt-ftparchive packages . > Packages) + apt-get update +else + echo "Setting up TEST repo: ${TEST_REPO}" + sed -i -e 's#nvidia\.github\.io/libnvidia-container#${TEST_REPO}/libnvidia-container#g' /etc/apt/sources.list.d/nvidia-docker.list + sed -i -e '/experimental/ s/^#//g' /etc/apt/sources.list.d/nvidia-docker.list + apt-get update +fi + +exec bash $@