Skip to content

Commit 46de426

Browse files
author
Evan Lezar
committed
Merge branch 'CNT-1330/jenkins-ci' into 'master'
Add Jenkins file for CI build steps See merge request nvidia/container-toolkit/container-toolkit!28
2 parents ff44395 + 1c7d6a2 commit 46de426

File tree

4 files changed

+193
-15
lines changed

4 files changed

+193
-15
lines changed

.gitlab-ci.yml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright (c) 2019-2021, NVIDIA CORPORATION. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
# Build packages for all supported OS / ARCH combinations
216

317
stages:
@@ -37,42 +51,40 @@ lint:
3751
<<: *tests-setup
3852
stage: tests
3953
script:
40-
- go get -u golang.org/x/lint/golint
41-
- golint -set_exit_status ${PROJECT_GOPATH}/pkg
54+
- GO111MODULE=off go get -u golang.org/x/lint/golint
55+
- make lint
4256

4357
vet:
4458
<<: *tests-setup
4559
stage: tests
4660
script:
47-
- go vet ${PROJECT_GOPATH}/pkg
61+
- make vet
4862

4963
unit_test:
5064
<<: *tests-setup
5165
stage: tests
5266
script:
53-
- go test ${PROJECT_GOPATH}/pkg
67+
- make test
5468

5569
fmt:
5670
<<: *tests-setup
5771
stage: tests
5872
script:
59-
- res=$(gofmt -l pkg/*.go)
60-
- echo "$res"
61-
- test -z "$res"
73+
- make assert-fmt
6274

6375
ineffassign:
6476
<<: *tests-setup
6577
stage: tests
6678
script:
67-
- go get -u github.com/gordonklaus/ineffassign
68-
- ineffassign pkg/*.go
79+
- GO111MODULE=off go get -u github.com/gordonklaus/ineffassign
80+
- make ineffassign
6981

7082
misspell:
7183
<<: *tests-setup
7284
stage: tests
7385
script:
74-
- go get -u github.com/client9/misspell/cmd/misspell
75-
- misspell pkg/*.go
86+
- GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell
87+
- make misspell
7688

7789
# build-one jobs build packages for a single OS / ARCH combination.
7890
#

Jenkinsfile

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
*/
16+
17+
podTemplate (cloud:'sw-gpu-cloudnative',
18+
containers: [
19+
containerTemplate(name: 'docker', image: 'docker:dind', ttyEnabled: true, privileged: true),
20+
containerTemplate(name: 'golang', image: 'golang:1.14.2', ttyEnabled: true)
21+
]) {
22+
node(POD_LABEL) {
23+
stage('checkout') {
24+
checkout scm
25+
}
26+
stage('dependencies') {
27+
container('golang') {
28+
sh 'GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell'
29+
sh 'GO111MODULE=off go get -u github.com/gordonklaus/ineffassign'
30+
sh 'GO111MODULE=off go get -u golang.org/x/lint/golint'
31+
}
32+
container('docker') {
33+
sh 'apk add --no-cache make bash'
34+
}
35+
}
36+
stage('check') {
37+
parallel (
38+
getGolangStages(["assert-fmt", "lint", "vet", "ineffassign", "misspell"])
39+
)
40+
}
41+
stage('test') {
42+
parallel (
43+
getGolangStages(["test"])
44+
)
45+
}
46+
stage('build-one') {
47+
parallel (
48+
getSingleBuildForArchitectures(["amd64", "ppc64le", "arm64"])
49+
)
50+
}
51+
stage('build-all') {
52+
parallel (
53+
getAllBuildForArchitectures(["amd64", "ppc64le", "arm64", "x86_64", "aarch64"])
54+
)
55+
}
56+
}
57+
}
58+
59+
def getGolangStages(def targets) {
60+
stages = [:]
61+
62+
for (t in targets) {
63+
stages[t] = getLintClosure(t)
64+
}
65+
66+
return stages
67+
}
68+
69+
def getSingleBuildForArchitectures(def architectures) {
70+
return getBuildStagesForArchitectures(architectures, "make", "ubuntu18.04")
71+
}
72+
73+
def getAllBuildForArchitectures(def architectures) {
74+
// TODO: For the time being we only echo the command for the "all" stages
75+
return getBuildStagesForArchitectures(architectures, "echo make", "docker")
76+
}
77+
78+
def getBuildStagesForArchitectures(def architectures, def makeCommand, def makeTargetPrefix) {
79+
stages = [:]
80+
81+
for (a in architectures) {
82+
stages[a] = getBuildClosure(a, makeCommand, "${makeTargetPrefix}-${a}")
83+
}
84+
85+
return stages
86+
}
87+
88+
def getBuildClosure(def architecture, def makeCommand, def makeTarget) {
89+
return {
90+
container('docker') {
91+
stage(architecture) {
92+
sh "${makeCommand} ${makeTarget}"
93+
}
94+
}
95+
}
96+
}
97+
98+
def getLintClosure(def target) {
99+
return {
100+
container('golang') {
101+
stage(target) {
102+
sh "make ${target}"
103+
}
104+
}
105+
}
106+
}

Makefile

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
# Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
1+
# Copyright (c) 2017-2021, NVIDIA CORPORATION. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
214

315
DOCKER ?= docker
416
MKDIR ?= mkdir
@@ -13,7 +25,43 @@ GOLANG_PKG_PATH := github.com/NVIDIA/nvidia-container-toolkit/pkg
1325

1426
# By default run all native docker-based targets
1527
docker-native:
16-
include $(CURDIR)/docker.mk
28+
include $(CURDIR)/docker/docker.mk
1729

1830
binary:
1931
go build -ldflags "-s -w" -o "$(LIB_NAME)" $(GOLANG_PKG_PATH)
32+
33+
# Define the check targets for the Golang codebase
34+
MODULE := .
35+
.PHONY: check fmt assert-fmt ineffassign lint misspell vet
36+
check: assert-fmt lint misspell vet
37+
fmt:
38+
go list -f '{{.Dir}}' $(MODULE)/... \
39+
| xargs gofmt -s -l -w
40+
41+
assert-fmt:
42+
go list -f '{{.Dir}}' $(MODULE)/... \
43+
| xargs gofmt -s -l > fmt.out
44+
@if [ -s fmt.out ]; then \
45+
echo "\nERROR: The following files are not formatted:\n"; \
46+
cat fmt.out; \
47+
rm fmt.out; \
48+
exit 1; \
49+
else \
50+
rm fmt.out; \
51+
fi
52+
53+
ineffassign:
54+
ineffassign $(MODULE)/...
55+
56+
lint:
57+
# We use `go list -f '{{.Dir}}' $(GOLANG_PKG_PATH)/...` to skip the `vendor` folder.
58+
go list -f '{{.Dir}}' $(MODULE)/... | xargs golint -set_exit_status
59+
60+
misspell:
61+
misspell $(MODULE)/...
62+
63+
vet:
64+
go vet $(MODULE)/...
65+
66+
test:
67+
go test $(MODULE)/...

docker.mk renamed to docker/docker.mk

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
# Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved.
1+
# Copyright (c) 2017-2021, NVIDIA CORPORATION. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
214

315
# Supported OSs by architecture
416
AMD64_TARGETS := ubuntu20.04 ubuntu18.04 ubuntu16.04 debian10 debian9
@@ -108,7 +120,7 @@ docker-build-%:
108120
DOCKER_BUILDKIT=1 \
109121
$(DOCKER) build \
110122
--progress=plain \
111-
--build-arg BASEIMAGE=$(BASEIMAGE) \
123+
--build-arg BASEIMAGE="$(BASEIMAGE)" \
112124
--build-arg GOLANG_VERSION="$(GOLANG_VERSION)" \
113125
--build-arg PKG_VERS="$(LIB_VERSION)" \
114126
--build-arg PKG_REV="$(PKG_REV)" \

0 commit comments

Comments
 (0)