diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..c58ffcd4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.git +dist diff --git a/Makefile b/Makefile index 034446ac..e0189e89 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,24 @@ -# Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. +# Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved. DOCKER ?= docker MKDIR ?= mkdir -REGISTRY ?= nvidia/toolkit +REGISTRY ?= nvidia/container-toolkit -GOLANG_VERSION := 1.10.3 +GOLANG_VERSION := 1.14.2 VERSION := 1.0.5 DIST_DIR := $(CURDIR)/dist -.NOTPARALLEL: +TOOLKIT=nvidia-container-toolkit + +include $(CURDIR)/docker.mk + .PHONY: all all: ubuntu18.04 ubuntu16.04 debian10 debian9 centos7 amzn2 amzn1 opensuse-leap15.1 +binary: + go build -ldflags "-s -w" -o "$(TOOLKIT)" github.com/NVIDIA/container-toolkit/pkg + push%: docker push "$(REGISTRY)/$*" diff --git a/docker.mk b/docker.mk new file mode 100644 index 00000000..c9df9eb2 --- /dev/null +++ b/docker.mk @@ -0,0 +1,74 @@ +# Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved. + +push%: + docker push "$(REGISTRY)/$*" + +ubuntu%: ARCH := amd64 +ubuntu%: + $(DOCKER) build --pull \ + --build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \ + --build-arg VERSION_ID="$*" \ + --build-arg PKG_VERS="$(VERSION)" \ + --build-arg PKG_REV="1" \ + --tag "$(REGISTRY)/ubuntu$*" \ + --file docker/Dockerfile.ubuntu . + $(MKDIR) -p $(DIST_DIR)/$@/$(ARCH) + $(DOCKER) run --cidfile $@.cid "$(REGISTRY)/ubuntu$*" + $(DOCKER) cp $$(cat $@.cid):/dist/. $(DIST_DIR)/$@/$(ARCH)/ + $(DOCKER) rm $$(cat $@.cid) && rm $@.cid + +debian%: ARCH := amd64 +debian%: + $(DOCKER) build --pull \ + --build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \ + --build-arg VERSION_ID="$*" \ + --build-arg PKG_VERS="$(VERSION)" \ + --build-arg PKG_REV="1" \ + --tag "$(REGISTRY)/debian$*" \ + --file docker/Dockerfile.debian . + $(MKDIR) -p $(DIST_DIR)/$@/$(ARCH) + $(DOCKER) run --cidfile $@.cid "$(REGISTRY)/debian$*" + $(DOCKER) cp $$(cat $@.cid):/dist/. $(DIST_DIR)/$@/$(ARCH)/ + $(DOCKER) rm $$(cat $@.cid) && rm $@.cid + +centos%: ARCH := x86_64 +centos%: + $(DOCKER) build --pull \ + --build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \ + --build-arg VERSION_ID="$*" \ + --build-arg PKG_VERS="$(VERSION)" \ + --build-arg PKG_REV="2" \ + --tag "$(REGISTRY)/centos$*" \ + --file docker/Dockerfile.centos . + $(MKDIR) -p $(DIST_DIR)/$@/$(ARCH) + $(DOCKER) run --cidfile $@.cid "$(REGISTRY)/centos$*" + $(DOCKER) cp $$(cat $@.cid):/dist/. $(DIST_DIR)/$@/$(ARCH)/ + $(DOCKER) rm $$(cat $@.cid) && rm $@.cid + +amzn%: ARCH := x86_64 +amzn%: + $(DOCKER) build --pull \ + --build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \ + --build-arg VERSION_ID="$*" \ + --build-arg PKG_VERS="$(VERSION)" \ + --build-arg PKG_REV="2.amzn$*" \ + --tag "$(REGISTRY)/amzn$*" \ + --file docker/Dockerfile.amzn . + $(MKDIR) -p $(DIST_DIR)/$@/$(ARCH) + $(DOCKER) run --cidfile $@.cid "$(REGISTRY)/amzn$*" + $(DOCKER) cp $$(cat $@.cid):/dist/. $(DIST_DIR)/$@/$(ARCH)/ + $(DOCKER) rm $$(cat $@.cid) && rm $@.cid + +opensuse-leap%: ARCH := x86_64 +opensuse-leap%: + $(DOCKER) build --pull \ + --build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \ + --build-arg VERSION_ID="$*" \ + --build-arg PKG_VERS="$(VERSION)" \ + --build-arg PKG_REV="1" \ + --tag "$(REGISTRY)/opensuse-leap$*" \ + --file docker/Dockerfile.opensuse-leap . + $(MKDIR) -p $(DIST_DIR)/$@/$(ARCH) + $(DOCKER) run --cidfile $@.cid "$(REGISTRY)/opensuse-leap$*" + $(DOCKER) cp $$(cat $@.cid):/dist/. $(DIST_DIR)/$@/$(ARCH)/ + $(DOCKER) rm $$(cat $@.cid) && rm $@.cid diff --git a/docker/Dockerfile.amzn b/docker/Dockerfile.amzn index 24b4a236..1337405f 100644 --- a/docker/Dockerfile.amzn +++ b/docker/Dockerfile.amzn @@ -37,10 +37,11 @@ ENV DIST_DIR=/tmp/nvidia-container-toolkit-$PKG_VERS/SOURCES RUN mkdir -p $DIST_DIR /dist # nvidia-container-toolkit -COPY nvidia-container-toolkit/ $GOPATH/src/nvidia-container-toolkit +WORKDIR $GOPATH/src/nvidia-container-toolkit +COPY . . -RUN go get -ldflags "-s -w" -v nvidia-container-toolkit && \ - mv $GOPATH/bin/nvidia-container-toolkit $DIST_DIR/nvidia-container-toolkit +RUN make binary && \ + mv ./nvidia-container-toolkit $DIST_DIR/nvidia-container-toolkit COPY config/config.toml.amzn $DIST_DIR/config.toml @@ -53,7 +54,7 @@ COPY oci-nvidia-hook $DIST_DIR/oci-nvidia-hook COPY oci-nvidia-hook.json $DIST_DIR/oci-nvidia-hook.json WORKDIR $DIST_DIR/.. -COPY pkg/rpm . +COPY packaging/rpm . CMD arch=$(uname -m) && \ rpmbuild --clean --target=$arch -bb \ diff --git a/docker/Dockerfile.centos b/docker/Dockerfile.centos index 82601a9e..bbe72cb1 100644 --- a/docker/Dockerfile.centos +++ b/docker/Dockerfile.centos @@ -5,6 +5,7 @@ RUN yum install -y \ ca-certificates \ wget \ git \ + make \ rpm-build && \ rm -rf /var/cache/yum/* @@ -36,10 +37,11 @@ ENV DIST_DIR=/tmp/nvidia-container-toolkit-$PKG_VERS/SOURCES RUN mkdir -p $DIST_DIR /dist # nvidia-container-toolkit -COPY nvidia-container-toolkit/ $GOPATH/src/nvidia-container-toolkit +WORKDIR $GOPATH/src/nvidia-container-toolkit +COPY . . -RUN go get -ldflags "-s -w" -v nvidia-container-toolkit && \ - mv $GOPATH/bin/nvidia-container-toolkit $DIST_DIR/nvidia-container-toolkit +RUN make binary && \ + mv ./nvidia-container-toolkit $DIST_DIR/nvidia-container-toolkit COPY config/config.toml.centos $DIST_DIR/config.toml @@ -50,7 +52,7 @@ COPY oci-nvidia-hook $DIST_DIR/oci-nvidia-hook COPY oci-nvidia-hook.json $DIST_DIR/oci-nvidia-hook.json WORKDIR $DIST_DIR/.. -COPY pkg/rpm . +COPY packaging/rpm . CMD arch=$(uname -m) && \ rpmbuild --clean --target=$arch -bb \ diff --git a/docker/Dockerfile.debian b/docker/Dockerfile.debian index b6296405..3b073c2f 100644 --- a/docker/Dockerfile.debian +++ b/docker/Dockerfile.debian @@ -44,10 +44,11 @@ ENV DIST_DIR=/tmp/nvidia-container-toolkit-$PKG_VERS RUN mkdir -p $DIST_DIR /dist # nvidia-container-toolkit -COPY nvidia-container-toolkit/ $GOPATH/src/nvidia-container-toolkit +WORKDIR $GOPATH/src/nvidia-container-toolkit +COPY . . -RUN go get -ldflags "-s -w" -v nvidia-container-toolkit && \ - mv $GOPATH/bin/nvidia-container-toolkit $DIST_DIR/nvidia-container-toolkit +RUN make binary && \ + mv ./nvidia-container-toolkit $DIST_DIR/nvidia-container-toolkit COPY config/config.toml.debian $DIST_DIR/config.toml @@ -57,7 +58,7 @@ RUN if [ "$(lsb_release -cs)" = "jessie" ]; then \ fi WORKDIR $DIST_DIR -COPY pkg/debian ./debian +COPY packaging/debian ./debian RUN sed -i "s;@VERSION@;${REVISION};" debian/changelog && \ if [ "$REVISION" != "$(dpkg-parsechangelog --show-field=Version)" ]; then exit 1; fi diff --git a/docker/Dockerfile.opensuse-leap b/docker/Dockerfile.opensuse-leap index a0c4260f..ef7a71ee 100644 --- a/docker/Dockerfile.opensuse-leap +++ b/docker/Dockerfile.opensuse-leap @@ -36,7 +36,11 @@ ENV DIST_DIR=/tmp/nvidia-container-toolkit-$PKG_VERS/SOURCES RUN mkdir -p $DIST_DIR /dist # nvidia-container-toolkit -COPY nvidia-container-toolkit/ $GOPATH/src/nvidia-container-toolkit +WORKDIR $GOPATH/src/nvidia-container-toolkit +COPY . . + +RUN make binary && \ + mv ./nvidia-container-toolkit $DIST_DIR/nvidia-container-toolkit # Hook for Project Atomic's fork of Docker: https://github.com/projectatomic/docker/tree/docker-1.13.1-rhel#add-dockerhooks-exec-custom-hooks-for-prestartpoststop-containerspatch COPY oci-nvidia-hook $DIST_DIR/oci-nvidia-hook @@ -44,13 +48,10 @@ COPY oci-nvidia-hook $DIST_DIR/oci-nvidia-hook # Hook for libpod/CRI-O: https://github.com/containers/libpod/blob/v0.8.5/pkg/hooks/docs/oci-hooks.5.md COPY oci-nvidia-hook.json $DIST_DIR/oci-nvidia-hook.json -RUN go get -ldflags "-s -w" -v nvidia-container-toolkit && \ - mv $GOPATH/bin/nvidia-container-toolkit $DIST_DIR/nvidia-container-toolkit - COPY config/config.toml.opensuse-leap $DIST_DIR/config.toml WORKDIR $DIST_DIR/.. -COPY pkg/rpm . +COPY packaging/rpm . CMD arch=$(uname -m) && \ rpmbuild --clean --target=$arch -bb \ diff --git a/docker/Dockerfile.ubuntu b/docker/Dockerfile.ubuntu index 72f03c37..45577028 100644 --- a/docker/Dockerfile.ubuntu +++ b/docker/Dockerfile.ubuntu @@ -42,15 +42,16 @@ ENV DIST_DIR=/tmp/nvidia-container-toolkit-$PKG_VERS RUN mkdir -p $DIST_DIR /dist # nvidia-container-toolkit -COPY nvidia-container-toolkit/ $GOPATH/src/nvidia-container-toolkit +WORKDIR $GOPATH/src/nvidia-container-toolkit +COPY . . -RUN go get -ldflags "-s -w" -v nvidia-container-toolkit && \ - mv $GOPATH/bin/nvidia-container-toolkit $DIST_DIR/nvidia-container-toolkit +RUN make binary && \ + mv ./nvidia-container-toolkit $DIST_DIR/nvidia-container-toolkit COPY config/config.toml.ubuntu $DIST_DIR/config.toml WORKDIR $DIST_DIR -COPY pkg/debian ./debian +COPY packaging/debian ./debian RUN sed -i "s;@VERSION@;${REVISION};" debian/changelog && \ if [ "$REVISION" != "$(dpkg-parsechangelog --show-field=Version)" ]; then exit 1; fi diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..94d3b92a --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/NVIDIA/container-toolkit + +go 1.14 + +require github.com/BurntSushi/toml v0.3.1 diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..9cb2df8e --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= diff --git a/pkg/debian/changelog b/packaging/debian/changelog similarity index 100% rename from pkg/debian/changelog rename to packaging/debian/changelog diff --git a/pkg/debian/changelog.old b/packaging/debian/changelog.old similarity index 100% rename from pkg/debian/changelog.old rename to packaging/debian/changelog.old diff --git a/pkg/debian/compat b/packaging/debian/compat similarity index 100% rename from pkg/debian/compat rename to packaging/debian/compat diff --git a/pkg/debian/control b/packaging/debian/control similarity index 100% rename from pkg/debian/control rename to packaging/debian/control diff --git a/pkg/debian/copyright b/packaging/debian/copyright similarity index 100% rename from pkg/debian/copyright rename to packaging/debian/copyright diff --git a/pkg/debian/nvidia-container-toolkit.install b/packaging/debian/nvidia-container-toolkit.install similarity index 100% rename from pkg/debian/nvidia-container-toolkit.install rename to packaging/debian/nvidia-container-toolkit.install diff --git a/pkg/debian/nvidia-container-toolkit.lintian-overrides b/packaging/debian/nvidia-container-toolkit.lintian-overrides similarity index 100% rename from pkg/debian/nvidia-container-toolkit.lintian-overrides rename to packaging/debian/nvidia-container-toolkit.lintian-overrides diff --git a/pkg/debian/nvidia-container-toolkit.postinst b/packaging/debian/nvidia-container-toolkit.postinst similarity index 100% rename from pkg/debian/nvidia-container-toolkit.postinst rename to packaging/debian/nvidia-container-toolkit.postinst diff --git a/pkg/debian/nvidia-container-toolkit.postrm b/packaging/debian/nvidia-container-toolkit.postrm similarity index 100% rename from pkg/debian/nvidia-container-toolkit.postrm rename to packaging/debian/nvidia-container-toolkit.postrm diff --git a/pkg/debian/prepare b/packaging/debian/prepare similarity index 100% rename from pkg/debian/prepare rename to packaging/debian/prepare diff --git a/pkg/debian/rules b/packaging/debian/rules similarity index 100% rename from pkg/debian/rules rename to packaging/debian/rules diff --git a/pkg/rpm/SOURCES/LICENSE b/packaging/rpm/SOURCES/LICENSE similarity index 100% rename from pkg/rpm/SOURCES/LICENSE rename to packaging/rpm/SOURCES/LICENSE diff --git a/pkg/rpm/SPECS/nvidia-container-toolkit.spec b/packaging/rpm/SPECS/nvidia-container-toolkit.spec similarity index 100% rename from pkg/rpm/SPECS/nvidia-container-toolkit.spec rename to packaging/rpm/SPECS/nvidia-container-toolkit.spec diff --git a/nvidia-container-toolkit/Godeps/Godeps.json b/pkg/Godeps/Godeps.json similarity index 100% rename from nvidia-container-toolkit/Godeps/Godeps.json rename to pkg/Godeps/Godeps.json diff --git a/nvidia-container-toolkit/capabilities.go b/pkg/capabilities.go similarity index 100% rename from nvidia-container-toolkit/capabilities.go rename to pkg/capabilities.go diff --git a/pkg/container-toolkit b/pkg/container-toolkit new file mode 100755 index 00000000..1a8af0de Binary files /dev/null and b/pkg/container-toolkit differ diff --git a/nvidia-container-toolkit/container_config.go b/pkg/container_config.go similarity index 100% rename from nvidia-container-toolkit/container_config.go rename to pkg/container_config.go diff --git a/nvidia-container-toolkit/hook_config.go b/pkg/hook_config.go similarity index 100% rename from nvidia-container-toolkit/hook_config.go rename to pkg/hook_config.go diff --git a/nvidia-container-toolkit/hook_test.go b/pkg/hook_test.go similarity index 100% rename from nvidia-container-toolkit/hook_test.go rename to pkg/hook_test.go diff --git a/nvidia-container-toolkit/main.go b/pkg/main.go similarity index 100% rename from nvidia-container-toolkit/main.go rename to pkg/main.go diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/.gitignore b/vendor/github.com/BurntSushi/toml/.gitignore similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/.gitignore rename to vendor/github.com/BurntSushi/toml/.gitignore diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/.travis.yml b/vendor/github.com/BurntSushi/toml/.travis.yml similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/.travis.yml rename to vendor/github.com/BurntSushi/toml/.travis.yml diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/COMPATIBLE b/vendor/github.com/BurntSushi/toml/COMPATIBLE similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/COMPATIBLE rename to vendor/github.com/BurntSushi/toml/COMPATIBLE diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/COPYING b/vendor/github.com/BurntSushi/toml/COPYING similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/COPYING rename to vendor/github.com/BurntSushi/toml/COPYING diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/Makefile b/vendor/github.com/BurntSushi/toml/Makefile similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/Makefile rename to vendor/github.com/BurntSushi/toml/Makefile diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/README.md b/vendor/github.com/BurntSushi/toml/README.md similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/README.md rename to vendor/github.com/BurntSushi/toml/README.md diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/decode.go b/vendor/github.com/BurntSushi/toml/decode.go similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/decode.go rename to vendor/github.com/BurntSushi/toml/decode.go diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/decode_meta.go b/vendor/github.com/BurntSushi/toml/decode_meta.go similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/decode_meta.go rename to vendor/github.com/BurntSushi/toml/decode_meta.go diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/doc.go b/vendor/github.com/BurntSushi/toml/doc.go similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/doc.go rename to vendor/github.com/BurntSushi/toml/doc.go diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/encode.go b/vendor/github.com/BurntSushi/toml/encode.go similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/encode.go rename to vendor/github.com/BurntSushi/toml/encode.go diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/encoding_types.go b/vendor/github.com/BurntSushi/toml/encoding_types.go similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/encoding_types.go rename to vendor/github.com/BurntSushi/toml/encoding_types.go diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/encoding_types_1.1.go b/vendor/github.com/BurntSushi/toml/encoding_types_1.1.go similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/encoding_types_1.1.go rename to vendor/github.com/BurntSushi/toml/encoding_types_1.1.go diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/lex.go b/vendor/github.com/BurntSushi/toml/lex.go similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/lex.go rename to vendor/github.com/BurntSushi/toml/lex.go diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/parse.go b/vendor/github.com/BurntSushi/toml/parse.go similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/parse.go rename to vendor/github.com/BurntSushi/toml/parse.go diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/session.vim b/vendor/github.com/BurntSushi/toml/session.vim similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/session.vim rename to vendor/github.com/BurntSushi/toml/session.vim diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/type_check.go b/vendor/github.com/BurntSushi/toml/type_check.go similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/type_check.go rename to vendor/github.com/BurntSushi/toml/type_check.go diff --git a/nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/type_fields.go b/vendor/github.com/BurntSushi/toml/type_fields.go similarity index 100% rename from nvidia-container-toolkit/vendor/github.com/BurntSushi/toml/type_fields.go rename to vendor/github.com/BurntSushi/toml/type_fields.go diff --git a/vendor/modules.txt b/vendor/modules.txt new file mode 100644 index 00000000..65ca3c92 --- /dev/null +++ b/vendor/modules.txt @@ -0,0 +1,3 @@ +# github.com/BurntSushi/toml v0.3.1 +## explicit +github.com/BurntSushi/toml