From fae68d4cbf641be0ba635f08ee3d21b178f7bc2f Mon Sep 17 00:00:00 2001 From: Renaud Gaubert Date: Wed, 23 Oct 2019 15:30:25 -0700 Subject: [PATCH] Build the containers in the CI Signed-off-by: Renaud Gaubert --- .gitlab-ci.yml | 113 +++++++++++++++---------------------------------- Makefile | 26 +++++++----- 2 files changed, 48 insertions(+), 91 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2388805..8f0ea39 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,92 +1,45 @@ -variables: - LICENSE_TAG: $CI_REGISTRY_IMAGE:license - PACKAGE_PATH: /go/src/gitlab.com/${CI_PROJECT_PATH} - BUILDER: ${CI_REGISTRY_IMAGE}/builder:${CI_COMMIT_REF_NAME} - BASE: ${CI_REGISTRY_IMAGE}/base - DOCKER_HOST: tcp://docker:2375 +image: docker:latest + +services: + - docker:dind stages: - - docker_images - - unit - - integration - build -license-builder: - image: docker:stable - stage: docker_images - services: - - docker:stable-dind - only: - changes: - - license/Dockerfile +.build_template: &build_definition + stage: build script: + - OS="${CI_JOB_NAME#*:}" + - apk add make + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - - docker build -t $LICENSE_TAG ./license - - docker push $LICENSE_TAG + - make REGISTRY=${CI_REGISTRY_IMAGE} ${OS} + - make REGISTRY=${CI_REGISTRY_IMAGE} push${OS} + artifacts: + expire_in: 1 week + paths: + - dist/ -# Build the base images and store in gitlab registry -base-builder: - stage: docker_images - image: docker:stable - services: - - docker:stable-dind - only: - changes: - - base/* - before_script: - - docker login -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" "${CI_REGISTRY}" - - apk add --update make - script: - - make -C base base-push BASE=${BASE} +amd64:amzn1: + <<: *build_definition -gitlab-builder: - stage: docker_images - image: docker:stable - services: - - docker:stable-dind - before_script: - - docker login -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" "${CI_REGISTRY}" - script: - - docker build --build-arg PKG_PATH="${PACKAGE_PATH}" -t ${BUILDER} -f ./builder.Dockerfile . - - docker push ${BUILDER} +amd64:amzn2: + <<: *build_definition -license: - stage: unit - image: - name: $LICENSE_TAG - script: - - ./license/check.sh +amd64:centos7: + <<: *build_definition -code-check: - stage: unit - image: ${BUILDER} - script: - - cd ${PACKAGE_PATH} - - make verify +amd64:opensuse-leap15.1: + <<: *build_definition -shim-test: - stage: integration - image: ${BUILDER} - before_script: - - mkdir /etc/nvidia-container-runtime && echo "" > /etc/nvidia-container-runtime/config.toml # config for test - - echo "" > /usr/bin/nvidia-container-runtime-hook # hook for test - - chmod +x /usr/bin/nvidia-container-runtime-hook - - cd ${PACKAGE_PATH}/runtime/src - script: - - make test +amd64:debian9: + <<: *build_definition -build: - stage: build - image: docker:stable - services: - - docker:stable-dind - before_script: - - docker login -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" "${CI_REGISTRY}" - - apk add --update make - script: - - make runtime BASE=${BASE} # build all runtime packages - - make toolkit BASE=${BASE} # build all toolkit packages - artifacts: - expire_in: 1 week - paths: - - dist/ \ No newline at end of file +amd64:debian10: + <<: *build_definition + +amd64:ubuntu16.04: + <<: *build_definition + +amd64:ubuntu18.04: + <<: *build_definition diff --git a/Makefile b/Makefile index 36a0b3a..7b298ff 100644 --- a/Makefile +++ b/Makefile @@ -9,13 +9,17 @@ PKG_REV := 1 TOOLKIT_VERSION := 1.0.5 GOLANG_VERSION := 1.10.3 -DIST_DIR := $(CURDIR)/../dist +DIST_DIR := $(CURDIR)/dist +REGISTRY := nvidia .NOTPARALLEL: .PHONY: all all: ubuntu18.04 ubuntu16.04 debian10 debian9 centos7 amzn2 amzn1 opensuse-leap15.1 +push%: + $(DOCKER) push "$(REGISTRY)/runtime/$*" + ubuntu%: ARCH := amd64 ubuntu%: $(DOCKER) build --pull \ @@ -24,10 +28,10 @@ ubuntu%: --build-arg PKG_VERS="$(VERSION)" \ --build-arg PKG_REV="$(PKG_REV)" \ --build-arg TOOLKIT_VERSION="$(TOOLKIT_VERSION)" \ - --tag "nvidia/runtime/ubuntu:$*" \ + --tag "$(REGISTRY)/runtime/ubuntu$*" \ --file docker/Dockerfile.ubuntu . $(MKDIR) -p "$(DIST_DIR)/ubuntu$*/$(ARCH)" - $(DOCKER) run --cidfile $@.cid "nvidia/runtime/ubuntu:$*" + $(DOCKER) run --cidfile $@.cid "$(REGISTRY)/runtime/ubuntu$*" $(DOCKER) cp $$(cat $@.cid):/dist/. "$(DIST_DIR)/ubuntu$*/$(ARCH)/" $(DOCKER) rm $$(cat $@.cid) && rm $@.cid @@ -39,10 +43,10 @@ debian%: --build-arg PKG_VERS="$(VERSION)" \ --build-arg PKG_REV="$(PKG_REV)" \ --build-arg TOOLKIT_VERSION="$(TOOLKIT_VERSION)" \ - --tag "nvidia/runtime/debian:$*" \ + --tag "$(REGISTRY)/runtime/debian$*" \ --file docker/Dockerfile.debian . $(MKDIR) -p "$(DIST_DIR)/debian$*/$(ARCH)" - $(DOCKER) run --cidfile $@.cid "nvidia/runtime/debian:$*" + $(DOCKER) run --cidfile $@.cid "$(REGISTRY)/runtime/debian$*" $(DOCKER) cp $$(cat $@.cid):/dist/. "$(DIST_DIR)/debian$*/$(ARCH)/" $(DOCKER) rm $$(cat $@.cid) && rm $@.cid @@ -54,10 +58,10 @@ centos%: --build-arg PKG_VERS="$(VERSION)" \ --build-arg PKG_REV="$(PKG_REV)" \ --build-arg TOOLKIT_VERSION="$(TOOLKIT_VERSION)" \ - --tag "nvidia/runtime/centos:$*" \ + --tag "$(REGISTRY)/runtime/centos$*" \ --file docker/Dockerfile.centos . $(MKDIR) -p "$(DIST_DIR)/centos$*/$(ARCH)" - $(DOCKER) run --cidfile $@.cid "nvidia/runtime/centos:$*" + $(DOCKER) run --cidfile $@.cid "$(REGISTRY)/runtime/centos$*" $(DOCKER) cp $$(cat $@.cid):/dist/. "$(DIST_DIR)/centos$*/$(ARCH)/" $(DOCKER) rm $$(cat $@.cid) && rm $@.cid @@ -69,10 +73,10 @@ amzn%: --build-arg PKG_VERS="$(VERSION)" \ --build-arg PKG_REV="$(PKG_REV)" \ --build-arg TOOLKIT_VERSION="$(TOOLKIT_VERSION)" \ - --tag "nvidia/runtime/amzn:$*" \ + --tag "$(REGISTRY)/runtime/amzn$*" \ --file docker/Dockerfile.amzn . $(MKDIR) -p "$(DIST_DIR)/amzn$*/$(ARCH)" - $(DOCKER) run --cidfile $@.cid "nvidia/runtime/amzn:$*" + $(DOCKER) run --cidfile $@.cid "$(REGISTRY)/runtime/amzn$*" $(DOCKER) cp $$(cat $@.cid):/dist/. "$(DIST_DIR)/amzn$*/$(ARCH)/" $(DOCKER) rm $$(cat $@.cid) && rm $@.cid @@ -84,9 +88,9 @@ opensuse-leap%: --build-arg PKG_VERS="$(VERSION)" \ --build-arg PKG_REV="$(PKG_REV)" \ --build-arg TOOLKIT_VERSION="$(TOOLKIT_VERSION)" \ - --tag "nvidia/runtime/opensuse-leap:$*" \ + --tag "$(REGISTRY)/runtime/opensuse-leap$*" \ --file docker/Dockerfile.opensuse-leap . $(MKDIR) -p $(DIST_DIR)/opensuse-leap$*/$(ARCH) - $(DOCKER) run --cidfile $@.cid "nvidia/runtime/opensuse-leap:$*" + $(DOCKER) run --cidfile $@.cid "$(REGISTRY)/runtime/opensuse-leap$*" $(DOCKER) cp $$(cat $@.cid):/dist/. $(DIST_DIR)/opensuse-leap$*/$(ARCH)/ $(DOCKER) rm $$(cat $@.cid) && rm $@.cid -- GitLab