From a6d5b664aa26fa32b4596cea5f747a8e3804204a Mon Sep 17 00:00:00 2001 From: Chris Walker Date: Tue, 19 Mar 2024 11:58:32 +0700 Subject: [PATCH] development/nvidia-container-toolkit: Added (NVidia container toolkit). Signed-off-by: Willy Sudiarto Raharjo --- development/nvidia-container-toolkit/README | 7 ++ .../nvidia-container-toolkit/config.toml.new | 32 +++++ .../nvidia-container-toolkit/doinst.sh | 99 ++++++++++++++++ .../nvidia-container-toolkit.SlackBuild | 112 ++++++++++++++++++ .../nvidia-container-toolkit.info | 10 ++ .../oci-nvidia-hook.json.new | 15 +++ .../nvidia-container-toolkit/slack-desc | 19 +++ 7 files changed, 294 insertions(+) create mode 100644 development/nvidia-container-toolkit/README create mode 100644 development/nvidia-container-toolkit/config.toml.new create mode 100644 development/nvidia-container-toolkit/doinst.sh create mode 100644 development/nvidia-container-toolkit/nvidia-container-toolkit.SlackBuild create mode 100644 development/nvidia-container-toolkit/nvidia-container-toolkit.info create mode 100644 development/nvidia-container-toolkit/oci-nvidia-hook.json.new create mode 100644 development/nvidia-container-toolkit/slack-desc diff --git a/development/nvidia-container-toolkit/README b/development/nvidia-container-toolkit/README new file mode 100644 index 0000000000..39b84bf31e --- /dev/null +++ b/development/nvidia-container-toolkit/README @@ -0,0 +1,7 @@ +The NVIDIA Container Toolkit allows user to build and run GPU accelerated +containers. The toolkit includes a container runtime library and utilities +to automatically configure containers to leverage NVIDIA GPUs. + +Warning: This SlackBuild requires network access when it runs, meaning +it downloads files from the Internet with root access. You should +decide for yourself whether or not you think this is a good idea. diff --git a/development/nvidia-container-toolkit/config.toml.new b/development/nvidia-container-toolkit/config.toml.new new file mode 100644 index 0000000000..86fd962ba6 --- /dev/null +++ b/development/nvidia-container-toolkit/config.toml.new @@ -0,0 +1,32 @@ +disable-require = false +#swarm-resource = "DOCKER_RESOURCE_GPU" +#accept-nvidia-visible-devices-envvar-when-unprivileged = true +#accept-nvidia-visible-devices-as-volume-mounts = false + +[nvidia-container-cli] +#root = "/run/nvidia/driver" +#path = "/usr/bin/nvidia-container-cli" +environment = [] +#debug = "/var/log/nvidia-container-toolkit.log" +#ldcache = "/etc/ld.so.cache" +load-kmods = true +#no-cgroups = false +user = "root:video" +ldconfig = "@/sbin/ldconfig" + +[nvidia-container-runtime] +#debug = "/var/log/nvidia-container-runtime.log" +log-level = "info" + +# Specify the runtimes to consider. This list is processed in order and the PATH +# searched for matching executables unless the entry is an absolute path. +runtimes = [ + "docker-runc", + "runc", +] + +mode = "auto" + +[nvidia-container-runtime.modes.csv] + +mount-spec-path = "/etc/nvidia-container-runtime/host-files-for-container.d" diff --git a/development/nvidia-container-toolkit/doinst.sh b/development/nvidia-container-toolkit/doinst.sh new file mode 100644 index 0000000000..50529497e7 --- /dev/null +++ b/development/nvidia-container-toolkit/doinst.sh @@ -0,0 +1,99 @@ +# $RCSfile: doinst.sh,v $ +# $Revision: 1.9 $ +# $Date: 2023-05-11 07:58:15+01 $ +# DW + +# NOTE DO: +# PLEASE only keep the functions/sections/commands that you need. +# PLEASE delete EVERYTHING else (including these comments). +# PLEASE let us know in the comment section of the upload form if including +# custom functions or commands. + +# NOTE PLEASE DO NOT: +# Add or change user or group accounts. +# Change any of the default system settings files. +# Add commands that take forever to complete. +# Use applications like checkinstall or installwatch, that 'touch' every file +# on the system. + + +# NOTE on paths +# Most commands do not have an initial '/' in directory path arguments so that +# they work correctly when using pkgtools --root or $ROOT options. +# Installpkg and friends chdir to $ROOT or --root before installing packages. +# The exceptions are the 'chroot' commands which do use an initial '/'. +# The chroot command is used to avoid files on the host being changed when +# using --root or $ROOT. +# +# Example: /usr/bin/update-desktop-database -q usr/share/applications +# ^Full path for command^ ^No initial slash^ + +# NOTE on tests +# [ -e ] => Tests if a directory or file exists. +# [ -x ] => Tests if command is executable. +# Will also fail silently if not -e too. + +# NOTE on redirections +# Most commands redirect stdout and stderr to /dev/null to keep down the noise. +# If you need to see error messages while testing, the easiest way is to +# temporarily comment out 2>&1. + +# FUNCTION: config() +# DESCRIPTION: Discards identical copies of config and rc.INIT files. +# ARGUMENTS: A single filename. +# NOTE +# Files should be installed with a .new extension. +# Example: etc/rc.d/rc.myshinynewdaemon.new +# We don't clobber if it's avoidable. +# "slackpkg new-config" is one way that users can list+process .new files. + +config() { + NEW="$1" + OLD="$(dirname $NEW)/$(basename $NEW .new)" + # If there's no config file by that name, mv it over: + if [ ! -r $OLD ]; then + mv $NEW $OLD + elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then + # toss the redundant copy + rm $NEW + fi + # Otherwise, we leave the .new copy for the admin to consider... +} + +# FUNCTION: preserve_perms() +# DESCRIPTION: Keeps the executable bit that a user may have set (or unset) on +# an rc.INIT or config file since she first installed a package. +# ARGUMENTS: A single filename. +# NOTE +# This calls the above config() function to discard identical copies. +# Files should be installed with a .new extension. +# Use for files in etc/rc.d/ and etc/profile.d/ +# Other config files may also need this. + +preserve_perms() { + NEW="$1" + OLD="$(dirname $NEW)/$(basename $NEW .new)" + if [ -e $OLD ]; then + cp -a $OLD ${NEW}.incoming + cat $NEW > ${NEW}.incoming + mv ${NEW}.incoming $NEW + fi + config $NEW +} + +# FUNCTION: schema_install() +# DESCRIPTION: Installs options (schemas) to the gnome config database. +# ARGUMENTS: A single filename. +# NOTE Not to be confused with glib schemas + +schema_install() { + SCHEMA="$1" + GCONF_CONFIG_SOURCE="xml::etc/gconf/gconf.xml.defaults" \ + chroot . gconftool-2 --makefile-install-rule \ + /etc/gconf/schemas/$SCHEMA \ + 1>/dev/null +} + +config etc/nvidia-container-runtime/config.toml.new +config usr/share/containers/oci/hooks.d/oci-nvidia-hook.json.new + diff --git a/development/nvidia-container-toolkit/nvidia-container-toolkit.SlackBuild b/development/nvidia-container-toolkit/nvidia-container-toolkit.SlackBuild new file mode 100644 index 0000000000..f5a2e500c7 --- /dev/null +++ b/development/nvidia-container-toolkit/nvidia-container-toolkit.SlackBuild @@ -0,0 +1,112 @@ +#!/bin/bash + +# Slackware build script for nvidia-container-toolkit + +# Copyright 2024 Chris Walker Kempner, TX +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +cd $(dirname $0) ; CWD=$(pwd) + +PRGNAM=nvidia-container-toolkit +VERSION=${VERSION:-1.14.6} +BUILD=${BUILD:-1} +TAG=${TAG:-_SBo} +PKGTYPE=${PKGTYPE:-tgz} + +if [ -z "$ARCH" ]; then + case "$( uname -m )" in + i?86) ARCH=i586 ;; + arm*) ARCH=arm ;; + *) ARCH=$( uname -m ) ;; + esac +fi + +if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then + echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE" + exit 0 +fi + +TMP=${TMP:-/tmp/SBo} +PKG=$TMP/package-$PRGNAM +OUTPUT=${OUTPUT:-/tmp} + +if [ "$ARCH" = "i586" ]; then + SLKCFLAGS="-O2 -march=i586 -mtune=i686" + LIBDIRSUFFIX="" +elif [ "$ARCH" = "i686" ]; then + SLKCFLAGS="-O2 -march=i686 -mtune=i686" + LIBDIRSUFFIX="" +elif [ "$ARCH" = "x86_64" ]; then + SLKCFLAGS="-O2 -fPIC" + LIBDIRSUFFIX="64" +elif [ "$ARCH" = "aarch64" ]; then + SLKCFLAGS="-O2 -fPIC" + LIBDIRSUFFIX="64" +else + SLKCFLAGS="-O2" + LIBDIRSUFFIX="" +fi + +set -e + +rm -rf $PKG +mkdir -p $TMP $PKG $OUTPUT +cd $TMP +rm -rf $PRGNAM-$VERSION +tar xvf $CWD/$PRGNAM-$VERSION.tar.gz +cd $PRGNAM-$VERSION +chown -R root:root . +find -L . \ + \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \ + -o -perm 511 \) -exec chmod 755 {} \; -o \ + \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \ + -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \; + +CFLAGS="" \ +CPPFLAGS="" \ +LDLIBS="" \ +make binaries + +mkdir -p $PKG/usr/bin +install -m 755 -t $PKG/usr/bin nvidia-container-runtime-hook +install -m 755 -t $PKG/usr/bin nvidia-container-runtime +install -m 755 -t $PKG/usr/bin nvidia-container-runtime.cdi +install -m 755 -t $PKG/usr/bin nvidia-container-runtime.legacy +install -m 755 -t $PKG/usr/bin nvidia-ctk + +mkdir -p $PKG/etc/nvidia-container-runtime/host-files-for-container.d +cat $CWD/config.toml.new > $PKG/etc/nvidia-container-runtime/config.toml.new + +mkdir -p $PKG/usr/share/containers/oci/hooks.d +cat $CWD/oci-nvidia-hook.json.new > $PKG/usr/share/containers/oci/hooks.d/oci-nvidia-hook.json.new + +#find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \ +# | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true + +mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION +cp LICENSE $PKG/usr/doc/$PRGNAM-$VERSION +cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild + +mkdir -p $PKG/install +cat $CWD/slack-desc > $PKG/install/slack-desc +cat $CWD/doinst.sh > $PKG/install/doinst.sh + +cd $PKG +/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE diff --git a/development/nvidia-container-toolkit/nvidia-container-toolkit.info b/development/nvidia-container-toolkit/nvidia-container-toolkit.info new file mode 100644 index 0000000000..671c54c2ab --- /dev/null +++ b/development/nvidia-container-toolkit/nvidia-container-toolkit.info @@ -0,0 +1,10 @@ +PRGNAM="nvidia-container-toolkit" +VERSION="1.14.6" +HOMEPAGE="https://github.com/NVIDIA/nvidia-container-toolkit" +DOWNLOAD="UNSUPPORTED" +MD5SUM="" +DOWNLOAD_x86_64="https://github.com/NVIDIA/nvidia-container-toolkit/archive/v1.14.6/nvidia-container-toolkit-1.14.6.tar.gz" +MD5SUM_x86_64="0f26467a05b623f744a1433e04f359ff" +REQUIRES="google-go-lang libnvidia-container" +MAINTAINER="Chris Walker" +EMAIL="kris240376@gmail.com" diff --git a/development/nvidia-container-toolkit/oci-nvidia-hook.json.new b/development/nvidia-container-toolkit/oci-nvidia-hook.json.new new file mode 100644 index 0000000000..6cbbe5cfa6 --- /dev/null +++ b/development/nvidia-container-toolkit/oci-nvidia-hook.json.new @@ -0,0 +1,15 @@ +{ + "version": "1.0.0", + "hook": { + "path": "/usr/bin/nvidia-container-runtime-hook", + "args": ["nvidia-container-runtime-hook", "prestart"], + "env": [ + "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + ] + }, + "when": { + "always": true, + "commands": [".*"] + }, + "stages": ["prestart"] +} diff --git a/development/nvidia-container-toolkit/slack-desc b/development/nvidia-container-toolkit/slack-desc new file mode 100644 index 0000000000..f823a8facc --- /dev/null +++ b/development/nvidia-container-toolkit/slack-desc @@ -0,0 +1,19 @@ +# HOW TO EDIT THIS FILE: +# The "handy ruler" below makes it easier to edit a package description. +# Line up the first '|' above the ':' following the base package name, and +# the '|' on the right side marks the last column you can put a character in. +# You must make exactly 11 lines for the formatting to be correct. It's also +# customary to leave one space after the ':' except on otherwise blank lines. + + |-----handy-ruler------------------------------------------------------| +nvidia-container-toolkit: nvidia-container-toolkit (NVIDIA container toolkit) +nvidia-container-toolkit: +nvidia-container-toolkit: The NVIDIA Container Toolkit allows user to build and run GPU +nvidia-container-toolkit: accelerated containers. The toolkit includes a container runtime +nvidia-container-toolkit: library and utilities to automatically configure containers to +nvidia-container-toolkit: leverage NVIDIA GPUs. +nvidia-container-toolkit: +nvidia-container-toolkit: Homepage: https://github.com/NVIDIA/nvidia-container-toolkit +nvidia-container-toolkit: +nvidia-container-toolkit: +nvidia-container-toolkit: