提交 be507e6c 编写于 作者: F Felix Abecassis

Initial commit

上级
FROM centos:7
# Install a more version of git (for vndr)
RUN yum install -y \
gcc \
make \
gettext-devel \
openssl-devel \
perl-CPAN \
perl-devel \
zlib-devel \
curl-devel && \
rm -rf /var/cache/yum/*
RUN GIT_DOWNLOAD_SUM=e19d450648d6d100eb93abaa5d06ffbc778394fb502354b7026d73e9bcbc3160 && \
curl -fsSL https://www.kernel.org/pub/software/scm/git/git-2.13.2.tar.gz -O && \
echo "$GIT_DOWNLOAD_SUM git-2.13.2.tar.gz" | sha256sum -c --strict - && \
tar --no-same-owner -xzf git-2.13.2.tar.gz -C /tmp && \
cd /tmp/git-2.13.2 && \
./configure && make -j"$(nproc)" install
# runc dependencies
RUN yum install -y \
ca-certificates \
wget \
pkgconfig \
gcc \
libseccomp-devel \
libselinux-devel && \
rm -rf /var/cache/yum/*
ENV GOLANG_VERSION 1.8.3
RUN wget -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz \
| tar -v -C /usr/local -xz
ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
RUN go get github.com/LK4D4/vndr
# packaging dependencies
RUN yum install -y \
rpm-build && \
rm -rf /var/cache/yum/*
# packaging
ARG PKG_VERS
ARG PKG_REV
ARG PKG_ARCH
ENV VERSION $PKG_VERS
ENV RELEASE $PKG_REV
ENV ARCHITECTURE $PKG_ARCH
# output directory
ENV DIST_DIR=/tmp/nvidia-container-runtime-$PKG_VERS/SOURCES
RUN mkdir -p $DIST_DIR
# runc
WORKDIR $GOPATH/src/github.com/opencontainers/runc
ARG RUNC_COMMIT
COPY runc/$RUNC_COMMIT/ /tmp/patches/runc
RUN git clone https://github.com/docker/runc.git . && \
git checkout $RUNC_COMMIT && \
git apply /tmp/patches/runc/* && \
if [ -f vendor.conf ]; then vndr; fi && \
make BUILDTAGS="seccomp selinux" && \
mv runc $DIST_DIR/nvidia-container-runtime
# nvidia-container-runtime-hook
COPY nvidia-container-runtime-hook/ $GOPATH/src/nvidia-container-runtime-hook
RUN go get -v nvidia-container-runtime-hook && \
mv $GOPATH/bin/nvidia-container-runtime-hook $DIST_DIR/nvidia-container-runtime-hook
COPY config.toml.centos7 $DIST_DIR/config.toml
WORKDIR $DIST_DIR/..
COPY rpm .
CMD rpmbuild --clean --target=$ARCHITECTURE -bb \
-D "_topdir $PWD" \
-D "version $VERSION" \
-D "release $RELEASE" \
SPECS/nvidia-container-runtime.spec && \
mv RPMS/$ARCHITECTURE/*.rpm /dist
FROM ubuntu:xenial
# runc dependencies
RUN apt-get update && apt-get install -y \
wget \
git \
make \
pkg-config \
gcc \
libseccomp-dev \
libapparmor-dev \
libselinux1-dev && \
rm -rf /var/lib/apt/lists/*
ENV GOLANG_VERSION 1.8.3
RUN wget -O - https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz \
| tar -v -C /usr/local -xz
ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
RUN go get github.com/LK4D4/vndr
# packaging dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
dh-make \
fakeroot \
devscripts && \
rm -rf /var/lib/apt/lists/*
# packaging
ARG PKG_VERS
ARG PKG_REV
ARG PKG_ARCH
ENV DEBFULLNAME "NVIDIA CORPORATION"
ENV DEBEMAIL "cudatools@nvidia.com"
ENV REVISION "$PKG_VERS-$PKG_REV"
# output directory
ENV DIST_DIR=/tmp/nvidia-container-runtime-$PKG_VERS
RUN mkdir -p $DIST_DIR
# runc
WORKDIR $GOPATH/src/github.com/opencontainers/runc
ARG RUNC_COMMIT
COPY runc/$RUNC_COMMIT/ /tmp/patches/runc
RUN git clone https://github.com/docker/runc.git . && \
git checkout $RUNC_COMMIT && \
git apply /tmp/patches/runc/* && \
if [ -f vendor.conf ]; then vndr; fi && \
make BUILDTAGS="seccomp apparmor selinux" && \
mv runc $DIST_DIR/nvidia-container-runtime
# nvidia-container-runtime-hook
COPY nvidia-container-runtime-hook/ $GOPATH/src/nvidia-container-runtime-hook
RUN go get -v nvidia-container-runtime-hook && \
mv $GOPATH/bin/nvidia-container-runtime-hook $DIST_DIR/nvidia-container-runtime-hook
COPY config.toml.xenial $DIST_DIR/config.toml
WORKDIR $DIST_DIR
COPY debian ./debian
RUN dch --create --package nvidia-container-runtime -v "$REVISION" "v$REVISION" && \
dch -r ""
CMD debuild -i -us -uc -b && \
mv /tmp/*.deb /dist
# Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
DOCKER ?= docker
VERSION := 1.0.0
PKG_REV := 1
DIST_DIR := $(CURDIR)/dist
.NOTPARALLEL:
.PHONY: all
all: xenial centos7
xenial: 17.06.1-xenial 17.03.2-xenial 1.13.1-xenial 1.12.6-xenial
centos7: 17.06.1-centos7 17.03.2-centos7
17.06.1-xenial:
$(DOCKER) build --build-arg RUNC_COMMIT="810190ceaa507aa2727d7ae6f4790c76ec150bd2" \
--build-arg PKG_VERS="$(VERSION)+docker17.06.1" \
--build-arg PKG_REV="$(PKG_REV)" \
-t nvidia-container-runtime:$@ -f Dockerfile.xenial .
$(DOCKER) run --rm -v $(DIST_DIR)/xenial:/dist:Z nvidia-container-runtime:$@
17.03.2-xenial:
$(DOCKER) build --build-arg RUNC_COMMIT="54296cf40ad8143b62dbcaa1d90e520a2136ddfe" \
--build-arg PKG_VERS="$(VERSION)+docker17.03.2" \
--build-arg PKG_REV="$(PKG_REV)" \
-t nvidia-container-runtime:$@ -f Dockerfile.xenial .
$(DOCKER) run --rm -v $(DIST_DIR)/xenial:/dist:Z nvidia-container-runtime:$@
1.13.1-xenial:
$(DOCKER) build --build-arg RUNC_COMMIT="9df8b306d01f59d3a8029be411de015b7304dd8f" \
--build-arg PKG_VERS="$(VERSION)+docker1.13.1" \
--build-arg PKG_REV="$(PKG_REV)" \
-t nvidia-container-runtime:$@ -f Dockerfile.xenial .
$(DOCKER) run --rm -v $(DIST_DIR)/xenial:/dist:Z nvidia-container-runtime:$@
1.12.6-xenial:
$(DOCKER) build --build-arg RUNC_COMMIT="50a19c6ff828c58e5dab13830bd3dacde268afe5" \
--build-arg PKG_VERS="$(VERSION)+docker1.12.6" \
--build-arg PKG_REV="$(PKG_REV)" \
-t nvidia-container-runtime:$@ -f Dockerfile.xenial .
$(DOCKER) run --rm -v $(DIST_DIR)/xenial:/dist:Z nvidia-container-runtime:$@
17.06.1-centos7:
$(DOCKER) build --build-arg PKG_ARCH="x86_64" \
--build-arg RUNC_COMMIT="810190ceaa507aa2727d7ae6f4790c76ec150bd2" \
--build-arg PKG_VERS="$(VERSION)" \
--build-arg PKG_REV="17.06.1.$(PKG_REV)" \
-t nvidia-container-runtime:$@ -f Dockerfile.centos7 .
$(DOCKER) run --rm -v $(DIST_DIR)/centos7:/dist:Z nvidia-container-runtime:$@
17.03.2-centos7:
$(DOCKER) build --build-arg PKG_ARCH="x86_64" \
--build-arg RUNC_COMMIT="54296cf40ad8143b62dbcaa1d90e520a2136ddfe" \
--build-arg PKG_VERS="$(VERSION)" \
--build-arg PKG_REV="17.03.2.$(PKG_REV)" \
-t nvidia-container-runtime:$@ -f Dockerfile.centos7 .
$(DOCKER) run --rm -v $(DIST_DIR)/centos7:/dist:Z nvidia-container-runtime:$@
# nvidia-container-runtime
**Warning: This project is an alpha release, it is not intended to be used in production systems.**
A modified version of [runc](https://github.com/opencontainers/runc) adding a custom [pre-start hook](https://github.com/opencontainers/runtime-spec/blob/master/config.md#prestart) to all containers.
If environment variable `NVIDIA_VISIBLE_DEVICES` is set in the OCI spec, the hook will configure GPU access for the container by leveraging `nvidia-container-cli` from project [libnvidia-container](https://github.com/NVIDIA/libnvidia-container).
#path = "/usr/bin/nvidia-container-cli"
environment = []
load-kmods = true
#debug = "/var/log/nvidia-container-runtime-hook.log"
[configure]
ldconfig = "@/sbin/ldconfig"
#path = "/usr/bin/nvidia-container-cli"
environment = []
load-kmods = true
#debug = "/var/log/nvidia-container-runtime-hook.log"
[configure]
ldconfig = "@/sbin/ldconfig.real"
Source: nvidia-container-runtime
Section: devel
Priority: optional
Maintainer: NVIDIA CORPORATION <cudatools@nvidia.com>
Standards-Version: 3.9.8
Homepage: https://github.com/NVIDIA/nvidia-container-runtime/wiki
Vcs-Git: https://github.com/NVIDIA/nvidia-container-runtime
Vcs-Browser: https://github.com/NVIDIA/nvidia-container-runtime
Build-Depends: debhelper (>= 9)
Package: nvidia-container-runtime
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libnvidia-container-tools, libapparmor1, libseccomp2
Description: NVIDIA container tools
Provides a modified version of runc allowing users to run GPU enabled
containers.
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: nvidia-container-runtime
Source: https://github.com/NVIDIA/nvidia-container-runtime
Files: *
Copyright: 2017 NVIDIA CORPORATION <cudatools@nvidia.com>
License: BSD-3-Clause
Files: runc/*
Copyright: 2017 NVIDIA CORPORATION <cudatools@nvidia.com>
License: Apache-2
Comment: https://github.com/opencontainers/runc/blob/master/NOTICE
License: Apache-2
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.
.
On Debian systems, the complete text of the Apache License 2.0 can
be found in "/usr/share/common-licenses/Apache-2.0"
License: BSD-3-clause
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 the copyright holder 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 AND CONTRIBUTORS "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
HOLDER 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.
config.toml /etc/nvidia-container-runtime
nvidia-* /usr/bin
\ No newline at end of file
new-package-should-close-itp-bug
binary-without-manpage
statically-linked-binary
#!/usr/bin/make -f
# -*- makefile -*-
#export DH_VERBOSE=1
%:
dh $@
package main
import (
"log"
"os"
"os/exec"
"github.com/BurntSushi/toml"
)
const (
configPath = "/etc/nvidia-container-runtime/config.toml"
)
type ConfigureOptions struct {
Ldconfig *string
}
type CLIConfig struct {
Path string
Environment []string
LoadKmods bool `toml:"load-kmods"`
Debug *string
Configure ConfigureOptions
}
func getDefaultCLIConfig() (config *CLIConfig) {
return &CLIConfig{
Path: "",
Environment: []string{},
LoadKmods: true,
Debug: nil,
Configure: ConfigureOptions{
Ldconfig: nil,
},
}
}
func getCLIConfig() (config *CLIConfig) {
config = getDefaultCLIConfig()
_, err := toml.DecodeFile(configPath, &config)
if err != nil && !os.IsNotExist(err) {
log.Fatalln("couldn't open configuration file:", err)
}
if len(config.Path) == 0 {
config.Path, err = exec.LookPath("nvidia-container-cli")
if err != nil {
log.Fatalln("couldn't find binary nvidia-container-cli:", err)
}
}
return config
}
package main
import (
"encoding/json"
"log"
"os"
"path"
"strings"
)
const (
// envSwarmGPU = "DOCKER_RESOURCE_GPU"
envNVGPU = "NVIDIA_VISIBLE_DEVICES"
envNVDriverCaps = "NVIDIA_DRIVER_CAPABILITIES"
envLegacyCUDAVersion = "CUDA_VERSION"
envNVCUDAVersion = "NVIDIA_CUDA_VERSION"
allCaps = "compute,compat32,graphics,utility,video"
)
type nvidiaConfig struct {
devices string
caps string
cudaVersion string
}
type containerConfig struct {
pid int
rootfs string
env map[string]string
nvidia *nvidiaConfig
}
// github.com/opencontainers/runtime-spec/blob/v1.0.0-rc5/specs-go/config.go#L94-L100
type Root struct {
Path string `json:"path"`
}
// github.com/opencontainers/runtime-spec/blob/v1.0.0-rc5/specs-go/config.go#L32-L57
type Process struct {
Env []string `json:"env,omitempty"`
}
// We use pointers to structs, similarly to the latest version of runtime-spec:
// https://github.com/opencontainers/runtime-spec/blob/v1.0.0-rc6/specs-go/config.go
type Spec struct {
Process *Process `json:"process,omitempty"`
Root *Root `json:"root,omitempty"`
}
type HookState struct {
Pid int `json:"pid"`
// In branch 17.06, runc is using the runtime spec:
// github.com/docker/runc/blob/17.06/libcontainer/configs/config.go#L262-L263
// github.com/opencontainers/runtime-spec/blob/v1.0.0-rc5/specs-go/state.go#L3-L17
Bundle string `json:"bundle"`
// Before 17.06, runc used a custom struct that didn't conform to the spec:
// github.com/docker/runc/blob/17.03.x/libcontainer/configs/config.go#L245-L252
BundlePath string `json:"bundlePath"`
}
func getEnvMap(e []string) (m map[string]string) {
m = make(map[string]string)
for _, s := range e {
p := strings.SplitN(s, "=", 2)
if len(p) != 2 {
log.Fatalln("environment error")
}
m[p[0]] = p[1]
}
return
}
func loadSpec(path string) (spec *Spec) {
f, err := os.Open(path)
if err != nil {
log.Fatalln("could not open OCI spec:", err)
}
defer f.Close()
if err = json.NewDecoder(f).Decode(&spec); err != nil {
log.Fatalln("could not decode OCI spec:", err)
}
if spec.Process == nil {
log.Fatalln("Process is empty in OCI spec")
}
if spec.Root == nil {
log.Fatalln("Root is empty in OCI spec")
}
return
}
// Mimic the new CUDA images if no caps or devices are specified.
func getNvidiaConfigLegacy(env map[string]string) *nvidiaConfig {
devices := env[envNVGPU]
if len(devices) == 0 {
devices = "all"
}
if devices == "none" {
devices = ""
}
caps := env[envNVDriverCaps]
if len(caps) == 0 || caps == "all" {
caps = allCaps
}
cudaVersion := env[envLegacyCUDAVersion]
return &nvidiaConfig{
devices: devices,
caps: caps,
cudaVersion: cudaVersion,
}
}
func getNvidiaConfig(env map[string]string) *nvidiaConfig {
legacyCudaVersion := env[envLegacyCUDAVersion]
cudaVersion := env[envNVCUDAVersion]
if len(legacyCudaVersion) > 0 && len(cudaVersion) == 0 {
// Legacy CUDA image detected.
return getNvidiaConfigLegacy(env)
}
devices, ok := env[envNVGPU]
if !ok {
// envNVGPU is unset: not a GPU container.
return nil
}
if devices == "none" {
devices = ""
}
caps := env[envNVDriverCaps]
if caps == "all" {
caps = allCaps
}
return &nvidiaConfig{
devices: devices,
caps: caps,
cudaVersion: cudaVersion,
}
}
func getContainerConfig() (config *containerConfig) {
var h HookState
d := json.NewDecoder(os.Stdin)
if err := d.Decode(&h); err != nil {
log.Fatalln("could not decode container state:", err)
}
b := h.Bundle
if len(b) == 0 {
b = h.BundlePath
}
s := loadSpec(path.Join(b, "config.json"))
env := getEnvMap(s.Process.Env)
return &containerConfig{
pid: h.Pid,
rootfs: s.Root.Path,
env: env,
nvidia: getNvidiaConfig(env),
}
}
package main
import (
"flag"
"fmt"
"log"
"os"
"strconv"
"strings"
"syscall"
)
var (
prestart = flag.Bool("prestart", false, "run the prestart hook")
)
func capToCLI(cap string) string {
switch cap {
case "compute":
return "--compute"
case "compat32":
return "--compat32"
case "graphics":
return "--graphics"
case "utility":
return "--utility"
case "video":
return "--video"
default:
log.Fatalln("unknown driver capability:", cap)
}
return ""
}
func doPrestart() {
log.SetFlags(0)
cli := getCLIConfig()
config := getContainerConfig()
nvidia := config.nvidia
if nvidia == nil {
// Not a GPU container, nothing to do.
return
}
args := []string{cli.Path}
if cli.LoadKmods {
args = append(args, "--load-kmods")
}
if cli.Debug != nil {
args = append(args, fmt.Sprintf("--debug=%s", *cli.Debug))
}
args = append(args, "configure")
if cli.Configure.Ldconfig != nil {
args = append(args, fmt.Sprintf("--ldconfig=%s", *cli.Configure.Ldconfig))
}
if len(nvidia.devices) > 0 {
args = append(args, fmt.Sprintf("--device=%s", nvidia.devices))
}
for _, cap := range strings.Split(nvidia.caps, ",") {
if len(cap) == 0 {
break
}
args = append(args, capToCLI(cap))
}
if len(nvidia.cudaVersion) > 0 {
var vmaj, vmin int
if _, err := fmt.Sscanf(nvidia.cudaVersion, "%d.%d", &vmaj, &vmin); err != nil {
log.Fatalln("invalid CUDA version:", nvidia.cudaVersion)
}
args = append(args, fmt.Sprintf("--require=cuda>=%d.%d", vmaj, vmin))
}
args = append(args, fmt.Sprintf("--pid=%s", strconv.FormatUint(uint64(config.pid), 10)))
args = append(args, config.rootfs)
log.Printf("exec command: %v", args)
env := append(os.Environ(), cli.Environment...)
err := syscall.Exec(cli.Path, args, env)
log.Fatalln("exec failed:", err)
}
func main() {
flag.Parse()
if *prestart {
doPrestart()
}
}
Copyright (c) 2017, 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.
For runc/*:
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
Copyright 2017 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.
Name: nvidia-container-runtime
Version: %{version}
Release: %{release}
Group: Development Tools
Vendor: NVIDIA CORPORATION
Packager: NVIDIA CORPORATION <cudatools@nvidia.com>
Summary: NVIDIA container runtime
URL: https://github.com/NVIDIA/nvidia-container-runtime
# The entire source code is BSD except runc/* which is ASL 2.0
# runc NOTICE file: https://github.com/opencontainers/runc/blob/master/NOTICE
License: BSD and ASL 2.0
Source0: nvidia-container-runtime
Source1: nvidia-container-runtime-hook
Source2: config.toml
Source3: LICENSE
Requires: libnvidia-container-tools
Requires: libseccomp
%description
Provides a modified version of runc allowing users to run GPU enabled
containers.
%prep
cp %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} .
%install
mkdir -p %{buildroot}%{_bindir}
install -m 755 -t %{buildroot}%{_bindir} nvidia-container-runtime
install -m 755 -t %{buildroot}%{_bindir} nvidia-container-runtime-hook
mkdir -p %{buildroot}/etc/nvidia-container-runtime
install -m 644 -t %{buildroot}/etc/nvidia-container-runtime config.toml
%files
%license LICENSE
%{_bindir}/nvidia-container-runtime-hook
%{_bindir}/nvidia-container-runtime
/etc/nvidia-container-runtime/config.toml
%changelog
From 7d357d021d53831c7acb01e5ae85e7d46f6620c9 Mon Sep 17 00:00:00 2001
From: Felix Abecassis <fabecassis@nvidia.com>
Date: Wed, 28 Jun 2017 14:18:45 -0700
Subject: [PATCH 1/2] Fix setup cgroup before prestart hook
---
libcontainer/process_linux.go | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/libcontainer/process_linux.go b/libcontainer/process_linux.go
index 5b81317..c3293b4 100644
--- a/libcontainer/process_linux.go
+++ b/libcontainer/process_linux.go
@@ -287,9 +287,6 @@ loop:
}
switch procSync.Type {
case procReady:
- if err := p.manager.Set(p.config.Config); err != nil {
- return newSystemErrorWithCause(err, "setting cgroup config for ready process")
- }
// set oom_score_adj
if err := setOomScoreAdj(p.config.Config.OomScoreAdj, p.pid()); err != nil {
return newSystemErrorWithCause(err, "setting oom score for ready process")
@@ -301,6 +298,9 @@ loop:
}
// call prestart hooks
if !p.config.Config.Namespaces.Contains(configs.NEWNS) {
+ if err := p.manager.Set(p.config.Config); err != nil {
+ return newSystemErrorWithCause(err, "setting cgroup config for ready process")
+ }
if p.config.Config.Hooks != nil {
s := configs.HookState{
Version: p.container.config.Version,
@@ -321,6 +321,9 @@ loop:
}
sentRun = true
case procHooks:
+ if err := p.manager.Set(p.config.Config); err != nil {
+ return newSystemErrorWithCause(err, "setting cgroup config for procHooks process")
+ }
if p.config.Config.Hooks != nil {
s := configs.HookState{
Version: p.container.config.Version,
--
2.7.4
From 4eb04f3f5a59d29cbd6043203e79507b223f00ee Mon Sep 17 00:00:00 2001
From: Felix Abecassis <fabecassis@nvidia.com>
Date: Mon, 7 Aug 2017 11:45:22 -0700
Subject: [PATCH 2/2] Add prestart hook nvidia-container-runtime-hook to the
config
---
utils.go | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/utils.go b/utils.go
index 55a7e9d..b398ebd 100644
--- a/utils.go
+++ b/utils.go
@@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
+ "os/exec"
"github.com/Sirupsen/logrus"
"github.com/opencontainers/runtime-spec/specs-go"
@@ -30,6 +31,20 @@ func setupSpec(context *cli.Context) (*specs.Spec, error) {
if err != nil {
return nil, err
}
+
+ path, err := exec.LookPath("nvidia-oci-hook")
+ if err != nil {
+ return nil, err
+ }
+ args := []string{path, "-prestart"}
+ if context.GlobalBool("debug") {
+ args = append(args, "-debug")
+ }
+ spec.Hooks.Prestart = append(spec.Hooks.Prestart, specs.Hook{
+ Path: path,
+ Args: args,
+ })
+
notifySocket := os.Getenv("NOTIFY_SOCKET")
if notifySocket != "" {
setupSdNotify(spec, notifySocket)
--
2.7.4
50a19c6ff828c58e5dab13830bd3dacde268afe5
\ No newline at end of file
From f1db2f8c3ee6026460e152990bb5d8676869aa92 Mon Sep 17 00:00:00 2001
From: Wentao Zhang <zhangwentao234@huawei.com>
Date: Tue, 20 Dec 2016 06:21:10 -0500
Subject: [PATCH 1/2] Fix setup cgroup before prestart hook
* User Case:
User could use prestart hook to add block devices to container. so the
hook should have a way to set the permissions of the devices.
Just move cgroup config operation before prestart hook will work.
Signed-off-by: Wentao Zhang <zhangwentao234@huawei.com>
---
libcontainer/process_linux.go | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/libcontainer/process_linux.go b/libcontainer/process_linux.go
index bfe9955..323ba72 100644
--- a/libcontainer/process_linux.go
+++ b/libcontainer/process_linux.go
@@ -280,9 +280,6 @@ func (p *initProcess) start() error {
ierr := parseSync(p.parentPipe, func(sync *syncT) error {
switch sync.Type {
case procReady:
- if err := p.manager.Set(p.config.Config); err != nil {
- return newSystemErrorWithCause(err, "setting cgroup config for ready process")
- }
// set rlimits, this has to be done here because we lose permissions
// to raise the limits once we enter a user-namespace
if err := setupRlimits(p.config.Rlimits, p.pid()); err != nil {
@@ -290,6 +287,11 @@ func (p *initProcess) start() error {
}
// call prestart hooks
if !p.config.Config.Namespaces.Contains(configs.NEWNS) {
+ // Setup cgroup before prestart hook, so that the prestart hook could apply cgroup permissions.
+ if err := p.manager.Set(p.config.Config); err != nil {
+ return newSystemErrorWithCause(err, "setting cgroup config for ready process")
+ }
+
if p.config.Config.Hooks != nil {
s := configs.HookState{
Version: p.container.config.Version,
@@ -310,6 +312,10 @@ func (p *initProcess) start() error {
}
sentRun = true
case procHooks:
+ // Setup cgroup before prestart hook, so that the prestart hook could apply cgroup permissions.
+ if err := p.manager.Set(p.config.Config); err != nil {
+ return newSystemErrorWithCause(err, "setting cgroup config for procHooks process")
+ }
if p.config.Config.Hooks != nil {
s := configs.HookState{
Version: p.container.config.Version,
--
2.7.4
From d79d778fa16c7990e68a8ac14024c3fb8d607a06 Mon Sep 17 00:00:00 2001
From: Felix Abecassis <fabecassis@nvidia.com>
Date: Mon, 7 Aug 2017 11:42:44 -0700
Subject: [PATCH 2/2] Add prestart hook nvidia-container-runtime-hook to the
config
---
utils.go | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/utils.go b/utils.go
index 98f93a4..a74f472 100644
--- a/utils.go
+++ b/utils.go
@@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
+ "os/exec"
"path/filepath"
"github.com/Sirupsen/logrus"
@@ -63,6 +64,23 @@ func setupSpec(context *cli.Context) (*specs.Spec, error) {
if err != nil {
return nil, err
}
+
+ path, err := exec.LookPath("nvidia-container-runtime-hook")
+ if err != nil {
+ return nil, err
+ }
+ args := []string{path, "-prestart"}
+ if context.GlobalBool("debug") {
+ args = append(args, "-debug")
+ }
+ if spec.Hooks == nil {
+ spec.Hooks = &specs.Hooks{}
+ }
+ spec.Hooks.Prestart = append(spec.Hooks.Prestart, specs.Hook{
+ Path: path,
+ Args: args,
+ })
+
return spec, nil
}
--
2.7.4
50a19c6ff828c58e5dab13830bd3dacde268afe5/
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册