Rewrite the packaging and add support for rpms

This commit is contained in:
Jonathan Calmels 2016-05-25 15:44:07 -07:00
parent 8e6ec6430a
commit 268f4bd746
27 changed files with 337 additions and 85 deletions

View file

@ -27,6 +27,9 @@ uninstall:
deb:
make -C $(CURDIR)/tools deb
rpm:
make -C $(CURDIR)/tools rpm
tarball:
make -C $(CURDIR)/tools tarball

View file

@ -10,8 +10,9 @@ RUN apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/r
echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64 /" > /etc/apt/sources.list.d/cuda.list
RUN apt-get update && apt-get install -y --no-install-recommends --force-yes \
cuda-cudart-dev-6-5=6.5-19 cuda-misc-headers-6-5=6.5-19 \
&& rm -rf /var/lib/apt/lists/*
cuda-cudart-dev-6-5=6.5-19 \
cuda-misc-headers-6-5=6.5-19 && \
rm -rf /var/lib/apt/lists/*
RUN objcopy --redefine-sym memcpy=memcpy@GLIBC_2.2.5 /usr/local/cuda-6.5/lib64/libcudart_static.a
@ -25,11 +26,19 @@ COPY src .
ENV CGO_CFLAGS "-I /usr/local/cuda-6.5/include -I /usr/include/nvidia/gdk"
ENV CGO_LDFLAGS "-L /usr/local/cuda-6.5/lib64"
RUN go get -v ./...
ARG UID
RUN useradd --non-unique --uid $UID build
USER build
ARG USER_ID
RUN useradd --non-unique --uid $USER_ID nvidia
USER nvidia
ARG CR_NAME
ARG CR_EMAIL
ARG PKG_NAME
ARG PKG_VERS
ARG PKG_REV
ARG PKG_ARCH
ENV VERSION $PKG_VERS
CMD go install -v -ldflags="-s -X main.Version=$VERSION" ./...

37
tools/Dockerfile.deb Normal file
View file

@ -0,0 +1,37 @@
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y --no-install-recommends --force-yes \
vim-nox \
dh-make \
dh-systemd \
fakeroot \
build-essential \
devscripts && \
rm -rf /var/lib/apt/lists/*
ARG USER_ID
ARG CR_NAME
ARG CR_EMAIL
ARG PKG_NAME
ARG PKG_VERS
ARG PKG_REV
ARG PKG_ARCH
VOLUME /dist
VOLUME /build
WORKDIR /tmp/$PKG_NAME-$PKG_VERS
ENV DEBFULLNAME $CR_NAME
ENV DEBEMAIL $CR_EMAIL
ENV REVISION $PKG_VERS-$PKG_REV
ENV ARCHITECTURE $PKG_ARCH
RUN useradd --non-unique --uid $USER_ID nvidia && chown nvidia: .
USER nvidia
CMD tar -xf /dist/*.tar.xz && \
read -p "Update changelog (y/n)? " yn && [ "$yn" = "y" ] && \
dch -c /build/deb/changelog -v $REVISION --no-auto-nmu ; \
dh_make -y -s -c bsd -d -t /build/deb -f /dist/*.tar.xz && \
debuild --preserve-env --dpkg-buildpackage-hook='sh debian/prepare' -i -us -uc -b && \
mv /tmp/*.deb /dist

47
tools/Dockerfile.rpm Normal file
View file

@ -0,0 +1,47 @@
FROM centos:7
RUN yum install -y \
vim \
rpm-build && \
rm -rf /var/cache/yum/*
RUN sed -i 's/include_release_info = 1/include_release_info = 0/' /usr/share/vim/vim74/ftplugin/spec.vim && \
echo 'let g:spec_chglog_format = "%a %b %d %Y ".$VENDOR." <".$EMAIL."> ".$VERSION."-".$REVISION' >> /etc/vimrc && \
echo 'autocmd VimEnter *.spec execute "normal \\c"' >> /etc/vimrc
ARG USER_ID
ARG CR_NAME
ARG CR_EMAIL
ARG PKG_NAME
ARG PKG_VERS
ARG PKG_REV
ARG PKG_ARCH
VOLUME /dist
VOLUME /build
WORKDIR /tmp/$PKG_NAME-$PKG_VERS
ENV VENDOR $CR_NAME
ENV EMAIL $CR_EMAIL
ENV NAME $PKG_NAME
ENV VERSION $PKG_VERS
ENV REVISION $PKG_REV
ENV ARCHITECTURE $PKG_ARCH
RUN useradd --non-unique --uid $USER_ID nvidia && chown nvidia: .
USER nvidia
CMD read -p "Update changelog (y/n)? " yn && [ "$yn" = "y" ] && \
vim /build/rpm/SPECS/$NAME.spec ; \
cp -Lr /build/rpm/* . && \
cp /dist/*.tar.xz SOURCES && \
rpmbuild --clean -bb \
-D "_topdir $PWD" \
-D "vendor $VENDOR" \
-D "email $EMAIL" \
-D "name $NAME" \
-D "version $VERSION" \
-D "revision $REVISION" \
-D "architecture $ARCHITECTURE" \
SPECS/$NAME.spec && \
mv RPMS/$ARCHITECTURE/*.rpm /dist

View file

@ -6,28 +6,40 @@ prefix ?= /usr/local
exec_prefix ?= $(prefix)
bindir ?= $(exec_prefix)/bin
BUILD_IMAGE := nvdocker-build
USER_ID := $(shell id -u)
BIN_DIR := $(CURDIR)/bin
CONF_DIR := $(CURDIR)/conf
DIST_DIR := $(CURDIR)/dist
DOCKER_BIN := $(BIN_DIR)/nvidia-docker
PLUGIN_BIN := $(BIN_DIR)/nvidia-docker-plugin
CR_NAME := NVIDIA CORPORATION
CR_EMAIL := digits@nvidia.com
PKG_NAME := nvidia-docker
PKG_VERS := 1.0.0~rc
PKG_REV := 1
ifneq ($(MAKECMDGOALS),rpm)
PKG_ARCH := amd64
PKG_DIR := $(DIST_DIR)/$(PKG_NAME)-$(PKG_VERS)
PKG_FILE := $(PKG_NAME)_$(PKG_VERS)_$(PKG_ARCH)
else
PKG_ARCH := x86_64
endif
BIN_DIR := $(CURDIR)/bin
DIST_DIR := $(CURDIR)/dist
BUILD_DIR := $(CURDIR)/build
DOCKER_BIN := $(BIN_DIR)/nvidia-docker
PLUGIN_BIN := $(BIN_DIR)/nvidia-docker-plugin
DOCKER_VERS := $(shell $(NV_DOCKER) version -f '{{.Client.Version}}')
DOCKER_VERS_MAJ := $(shell echo $(DOCKER_VERS) | cut -d. -f1)
DOCKER_VERS_MIN := $(shell echo $(DOCKER_VERS) | cut -d. -f2)
DOCKER_SUPPORTED := $(shell [ $(DOCKER_VERS_MAJ) -eq 1 -a $(DOCKER_VERS_MIN) -ge 9 ] && echo true)
.PHONY: all build install uninstall clean distclean tarball deb
DOCKER_RMI := $(NV_DOCKER) rmi
DOCKER_RUN := $(NV_DOCKER) run --rm --net=host
DOCKER_IMAGES := $(NV_DOCKER) images -q $(PKG_NAME)
DOCKER_BUILD := $(NV_DOCKER) build --build-arg USER_ID="$(shell id -u)" \
--build-arg CR_NAME="$(CR_NAME)" \
--build-arg CR_EMAIL="$(CR_EMAIL)" \
--build-arg PKG_NAME="$(PKG_NAME)" \
--build-arg PKG_VERS="$(PKG_VERS)" \
--build-arg PKG_REV="$(PKG_REV)" \
--build-arg PKG_ARCH="$(PKG_ARCH)"
.PHONY: all build install uninstall clean distclean tarball deb rpm
all: build
@ -35,20 +47,21 @@ build:
ifneq ($(DOCKER_SUPPORTED),true)
$(error Unsupported Docker version)
endif
@$(NV_DOCKER) build --build-arg UID=$(USER_ID) -t $(BUILD_IMAGE) -f Dockerfile.build $(CURDIR)
@mkdir -p $(BIN_DIR)
@$(NV_DOCKER) run --rm --net=host -e VERSION=$(PKG_VERS) -v $(BIN_DIR):/go/bin $(BUILD_IMAGE)
@$(DOCKER_BUILD) -t $(PKG_NAME):$@ -f Dockerfile.$@ $(CURDIR)
@$(DOCKER_RUN) -v $(BIN_DIR):/go/bin $(PKG_NAME):$@
install: all
install -D -T -m 755 $(DOCKER_BIN) $(bindir)/$(notdir $(DOCKER_BIN))
install -D -T -m 755 $(PLUGIN_BIN) $(bindir)/$(notdir $(PLUGIN_BIN))
install: build
install -D -m 755 -t $(bindir) $(DOCKER_BIN)
install -D -m 755 -t $(bindir) $(PLUGIN_BIN)
uninstall:
$(RM) $(bindir)/$(notdir $(DOCKER_BIN))
$(RM) $(bindir)/$(notdir $(PLUGIN_BIN))
clean:
-@$(NV_DOCKER) rmi -f $(BUILD_IMAGE) golang 2> /dev/null
-@$(DOCKER_IMAGES) | xargs $(DOCKER_RMI) 2> /dev/null
-@$(DOCKER_RMI) golang:1.5 ubuntu:14.04 centos:7 2> /dev/null
@rm -rf $(BIN_DIR)
distclean:
@ -56,17 +69,21 @@ distclean:
tarball: build distclean
@mkdir -p $(DIST_DIR)
tar --transform='s;.*/;nvidia-docker/;' -caf $(DIST_DIR)/$(PKG_FILE).tar.xz $(BIN_DIR)/*
tar --transform='s;.*/;$(PKG_NAME)/;' -caf $(DIST_DIR)/$(PKG_NAME)_$(PKG_VERS)_$(PKG_ARCH).tar.xz $(BIN_DIR)/*
@printf "\nFind tarball at $(DIST_DIR)\n\n"
deb: export DEBFULLNAME=NVIDIA CORPORATION
deb: export DEBEMAIL=digits@nvidia.com
deb: build distclean
@mkdir -p $(PKG_DIR)
@cp -r $(BIN_DIR) $(PKG_DIR)
@-read -p "Update changelog? " yn; [ "$$yn" = "y" ] && \
dch -c $(CONF_DIR)/debian/changelog -v $(PKG_VERS)-$(PKG_REV) --no-auto-nmu
cd $(PKG_DIR) && dh_make -y -s -c bsd -d -t $(CONF_DIR)/debian --createorig
cd $(PKG_DIR) && debuild -i -us -uc -b
deb: tarball
ifneq ($(DOCKER_SUPPORTED),true)
$(error Unsupported Docker version)
endif
@$(DOCKER_BUILD) -t $(PKG_NAME):$@ -f Dockerfile.$@ $(CURDIR)
@$(DOCKER_RUN) -ti -v $(DIST_DIR):/dist -v $(BUILD_DIR):/build $(PKG_NAME):$@
@printf "\nFind packages at $(DIST_DIR)\n\n"
rpm: tarball
ifneq ($(DOCKER_SUPPORTED),true)
$(error Unsupported Docker version)
endif
@$(DOCKER_BUILD) -t $(PKG_NAME):$@ -f Dockerfile.$@ $(CURDIR)
@$(DOCKER_RUN) -ti -v $(DIST_DIR):/dist -v $(BUILD_DIR):/build $(PKG_NAME):$@
@printf "\nFind packages at $(DIST_DIR)\n\n"

View file

@ -9,7 +9,7 @@ Environment="SOCK_DIR=/var/lib/nvidia-docker"
Environment="SOCK_FILE=unix:///var/lib/nvidia-docker/nvidia-docker.sock"
Environment="SPEC_FILE=/etc/docker/plugins/nvidia-docker.spec"
User=#PACKAGE#
User=nvidia-docker
PermissionsStartOnly=true
Restart=on-failure
RestartSec=1

View file

@ -2,14 +2,14 @@ Source: #PACKAGE#
Section: devel
Priority: optional
Maintainer: #USERNAME# <#EMAIL#>
Build-Depends: #BUILD_DEPS#
Build-Depends: #BUILD_DEPS#, dh-systemd
Standards-Version: #POLICY#
Homepage: https://github.com/NVIDIA/nvidia-docker/wiki
Vcs-Git: https://github.com/NVIDIA/nvidia-docker
Vcs-Browser: https://github.com/NVIDIA/nvidia-docker
Package: #PACKAGE#
Architecture: amd64
Architecture: #ARCHITECTURE#
Depends: ${misc:Depends}, ${shlibs:Depends}, adduser, docker-engine (>= 1.9.0)
Description: NVIDIA Docker container tools
NVIDIA Docker provides utilities to extend the Docker CLI allowing users

View file

@ -0,0 +1 @@
#PACKAGE#/* /usr/bin

View file

@ -8,8 +8,12 @@ NVIDIA_DOCKER_PLUGIN=/usr/bin/nvidia-docker-plugin
case "$1" in
configure)
adduser --system --no-create-home --home "$NVIDIA_DOCKER_ROOT" "$NVIDIA_DOCKER_USER"
chown "$NVIDIA_DOCKER_USER": "$NVIDIA_DOCKER_ROOT"
echo "Configuring user and permissions ..."
if [ -z "$2" ]; then
id -u "$NVIDIA_DOCKER_USER" >/dev/null 2>&1 || \
useradd -r -M -d "$NVIDIA_DOCKER_ROOT" -s /usr/sbin/nologin -c "NVIDIA Docker plugin" "$NVIDIA_DOCKER_USER"
chown "$NVIDIA_DOCKER_USER": "$NVIDIA_DOCKER_ROOT"
fi
setcap cap_fowner+pe "$NVIDIA_DOCKER_PLUGIN"
;;

View file

@ -0,0 +1,24 @@
#!/bin/sh
set -e
NVIDIA_DOCKER_USER=#PACKAGE#
case "$1" in
remove)
id -u "$NVIDIA_DOCKER_USER" >/dev/null 2>&1 && \
userdel "$NVIDIA_DOCKER_USER"
;;
upgrade|failed-upgrade|purge|abort-install|abort-upgrade|disappear)
;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#
exit 0

View file

@ -0,0 +1,26 @@
#!/bin/sh
set -e
NVIDIA_DOCKER_DRIVER=#PACKAGE#
NVIDIA_DOCKER_ROOT=/var/lib/nvidia-docker
case "$1" in
remove)
echo "Purging NVIDIA volumes ..."
docker volume ls | awk -v drv="$NVIDIA_DOCKER_DRIVER" '{if ($1 == drv) print $2}' | xargs -r docker volume rm
find "$NVIDIA_DOCKER_ROOT" ! -wholename "$NVIDIA_DOCKER_ROOT" -type d -empty -delete
;;
upgrade|deconfigure|failed-upgrade)
;;
*)
echo "prerm called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#
exit 0

View file

@ -0,0 +1 @@
../common/nvidia-docker.service

5
tools/build/deb/prepare Executable file
View file

@ -0,0 +1,5 @@
#! /bin/sh
set -e
sed -i "s/#ARCHITECTURE#/${ARCHITECTURE}/" debian/control

View file

@ -7,4 +7,4 @@ override_dh_shlibdeps:
dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
%:
dh $@
dh $@ --with=systemd

View file

@ -0,0 +1,25 @@
Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of NVIDIA CORPORATION nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``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 COPYRIGHT OWNER OR
CONTRIBUTORS 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.

View file

@ -0,0 +1 @@
../../common/nvidia-docker.service

View file

@ -0,0 +1,96 @@
Name: %{name}
Version: %{version}
Release: %{revision}
BuildArch: %{architecture}
Group: Development Tools
Vendor: %{vendor}
Packager: %{vendor} <%{email}>
Summary: NVIDIA Docker container tools
URL: https://github.com/NVIDIA/nvidia-docker
License: BSD
Source0: %{name}_%{version}_%{architecture}.tar.xz
Source1: %{name}.service
Source2: LICENSE
%{?systemd_requires}
BuildRequires: systemd
Requires: docker-engine
%define nvidia_docker_user %{name}
%define nvidia_docker_driver %{name}
%define nvidia_docker_root /var/lib/nvidia-docker
%description
NVIDIA Docker provides utilities to extend the Docker CLI allowing users
to build and run GPU applications as lightweight containers.
%prep
%autosetup -n %{name}
cp %{SOURCE1} %{SOURCE2} .
%install
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{_unitdir}
mkdir -p %{buildroot}%{nvidia_docker_root}
install -m 755 -t %{buildroot}%{_bindir} nvidia-docker
install -m 755 -t %{buildroot}%{_bindir} nvidia-docker-plugin
install -m 644 -t %{buildroot}%{_unitdir} %{name}.service
%files
%license LICENSE
%dir %{nvidia_docker_root}
%{_bindir}/*
%{_unitdir}/*
%post
if [ $1 -eq 1 ]; then
id -u %{nvidia_docker_user} >/dev/null 2>&1 || \
useradd -r -M -d %{nvidia_docker_root} -s /usr/sbin/nologin -c "NVIDIA Docker plugin" %{nvidia_docker_user}
chown %{nvidia_docker_user}: %{nvidia_docker_root}
fi
setcap cap_fowner+pe %{_bindir}/nvidia-docker-plugin
%systemd_post %{name}
%preun
if [ $1 -eq 0 ]; then
docker volume ls | awk -v drv=%{nvidia_docker_driver} '{if ($1 == drv) print $2}' | xargs -r docker volume rm || exit 1
find %{nvidia_docker_root} ! -wholename %{nvidia_docker_root} -type d -empty -delete
fi
%systemd_preun %{name}
%postun
if [ $1 -eq 0 ]; then
id -u %{nvidia_docker_user} >/dev/null 2>&1 && \
userdel %{nvidia_docker_user}
fi
%systemd_postun_with_restart %{name}
%changelog
* Tue May 03 2016 NVIDIA CORPORATION <digits@nvidia.com> 1.0.0~rc-1
- Add /docker/cli/json RestAPI endpoint (Closes: #39, #91)
- Fix support for Docker 1.9 (Closes: #83)
- Handle gracefully devices unsupported by NVML (Closes: #40)
- Improve error reporting
- Support for Docker 1.11 (Closes: #89, #84, #77, #73)
- Add NVIDIA Docker version output
- Improve init scripts and add support for systemd
- Query CPU affinity through sysfs instead of NVML (Closes: #65)
- Load UVM before anything else
* Mon Mar 28 2016 NVIDIA CORPORATION <digits@nvidia.com> 1.0.0~beta.3-1
- Remove driver hard dependency (NVML)
- Improve error handling and REST API output
- Support for 364 drivers
- Preventive removal of the plugin socket
* Mon Mar 07 2016 NVIDIA CORPORATION <digits@nvidia.com> 1.0.0~beta.2-1
- Support for Docker 1.10 (Closes: #46)
- Support for Docker plugin API v1.2
- Support for 361 drivers
- Add copy strategy for cross-device volumes (Closes: #47)
* Mon Feb 08 2016 NVIDIA CORPORATION <digits@nvidia.com> 1.0.0~beta-1
- Initial release (Closes: #33)

View file

@ -1 +0,0 @@
bin/* /usr/bin

View file

@ -1,20 +0,0 @@
#!/bin/sh
set -e
NVIDIA_DOCKER_USER=#PACKAGE#
case "$1" in
purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
deluser --quiet --system "$NVIDIA_DOCKER_USER"
;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#
exit 0

View file

@ -1,23 +0,0 @@
#!/bin/sh
set -e
NVIDIA_DOCKER_ROOT=/var/lib/nvidia-docker
case "$1" in
remove|upgrade|deconfigure)
find "$NVIDIA_DOCKER_ROOT" -type d -empty -delete
;;
failed-upgrade)
;;
*)
echo "prerm called with unknown argument \`$1'" >&2
exit 1
;;
esac
#DEBHELPER#
exit 0