Skip to content

Commit 02ca9c6

Browse files
authored
Feature/csi node docker build in CI pipeline (#27)
Build csi node as docker image and trigger it as part of the build pipeline in jenkins. So from now on there is ready csi node image in the internal artifactory after every push in github (together with csi controller image which already there). The pipeline also has a unit testing phase for csi node (runs as a container).
1 parent b25a5ca commit 02ca9c6

8 files changed

+112
-13
lines changed

.dockerignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
# ignore .git and .cache folders
2-
.git
1+
# ignore .cache folder
32
.cache

Dockerfile-csi-node

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright IBM Corporation 2019.
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+
15+
# Build stage
16+
FROM golang:1.12.6 as builder
17+
18+
WORKDIR /go/src/github.com/ibm/ibm-block-csi-driver
19+
ENV GO111MODULE=on
20+
21+
# Populate the module cache based on the go.{mod,sum} files.
22+
COPY go.mod .
23+
COPY go.sum .
24+
RUN go mod download
25+
26+
COPY . .
27+
RUN make ibm-block-csi-driver
28+
29+
# Final stage
30+
FROM centos:7
31+
WORKDIR /root
32+
COPY --from=builder /go/src/github.com/ibm/ibm-block-csi-driver/common/config.yaml .
33+
COPY --from=builder /go/src/github.com/ibm/ibm-block-csi-driver/bin/ibm-block-csi-node-driver .
34+
35+
ENTRYPOINT ["/root/ibm-block-csi-node-driver"]

Dockerfile-csi-node.test

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright IBM Corporation 2019.
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+
15+
# Build stage
16+
FROM golang:1.12.6 as builder
17+
18+
WORKDIR /go/src/github.com/ibm/ibm-block-csi-driver
19+
ENV GO111MODULE=on
20+
21+
# Populate the module cache based on the go.{mod,sum} files.
22+
COPY go.mod .
23+
COPY go.sum .
24+
RUN go mod download
25+
RUN go get github.com/tebeka/go2xunit # when GO111MODULE=on the module will not become executable, so get it here to run it as binary.
26+
27+
COPY . .
28+
ENTRYPOINT ["make", "test-xunit"]

Makefile

+18-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# limitations under the License.
1515
#
1616

17+
# Note: this Makefile currently applicable responsible for CSI compile, test and build image. Later will should add csi-controller to the makefile party.
18+
1719
PKG=github.com/ibm/ibm-block-csi-driver
1820
IMAGE=ibmcom/ibm-block-csi-driver
1921
GIT_COMMIT?=$(shell git rev-parse HEAD)
@@ -33,17 +35,26 @@ ibm-block-csi-driver:
3335
test:
3436
go test -v -race ./node/...
3537

38+
.PHONY: test-xunit
39+
test-xunit:
40+
mkdir -p ./build/reports
41+
go test -v -race ./node/... | go2xunit -output build/reports/csi-node-unitests.xml
42+
go test -v -race ./node/... # run again so the makefile will fail in case tests failing
43+
44+
.PHONY: test-xunit-in-container
45+
test-xunit-in-container:
46+
# Run make test-xunit inside csi node container for testing (to avoid go and other testing utils on your laptop).
47+
docker build -f Dockerfile-csi-node.test -t csi-node-unitests .
48+
docker run --rm -t -v $(CURDIR)/build/reports/:/go/src/github.com/ibm/ibm-block-csi-driver/build/reports/ csi-node-unitests
49+
50+
3651
.PHONY: gofmt
3752
gofmt:
3853
gofmt -w .
3954

40-
#.PHONY: image-release
41-
#image-release:
42-
# docker build -t $(IMAGE):$(VERSION) .
43-
#
44-
#.PHONY: push-release
45-
#push-release:
46-
# docker push $(IMAGE):$(VERSION)
55+
.PHONY: csi-build-images-and-push-artifactory
56+
csi-build-images-and-push-artifactory:
57+
./scripts/ci/build_push_images.sh
4758

4859
.PHONY: list
4960
list:

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.12
55
require (
66
github.com/container-storage-interface/spec v1.1.0
77
github.com/golang/mock v1.1.1
8+
github.com/tebeka/go2xunit v1.4.10
89
google.golang.org/grpc v1.21.1
910
gopkg.in/yaml.v2 v2.2.2
1011
k8s.io/klog v0.3.3

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM
1010
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
1111
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
1212
github.com/ibm/ibm-block-csi-driver v0.0.0-20190617074002-4a2be9926496 h1:9SV9CXMhrlXiiK8kYe35FnX7pns4zMeNm6UfhrCh8Dw=
13+
github.com/tebeka/go2xunit v1.4.10/go.mod h1:wmc9jKT7KlU4QLU6DNTaIXNnYNOjKKNlp6mjOS0UrqY=
1314
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
1415
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
1516
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=

scripts/ci/build_push_images.sh

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash -xe
22

33
# Validations
4-
MANDATORY_ENVS="IMAGE_VERSION BUILD_NUMBER DOCKER_REGISTRY CSI_CONTROLLER_IMAGE GIT_BRANCH"
4+
MANDATORY_ENVS="IMAGE_VERSION BUILD_NUMBER DOCKER_REGISTRY CSI_NODE_IMAGE CSI_CONTROLLER_IMAGE GIT_BRANCH"
55
for envi in $MANDATORY_ENVS; do
66
[ -z "${!envi}" ] && { echo "Error - Env $envi is mandatory for the script."; exit 1; } || :
77
done
@@ -12,6 +12,10 @@ specific_tag="${IMAGE_VERSION}_b${BUILD_NUMBER}_${branch}"
1212

1313
# Set latest tag only if its from develop branch or master and prepare tags
1414
[ "$GIT_BRANCH" = "develop" -o "$GIT_BRANCH" = "origin/develop" -o "$GIT_BRANCH" = "master" ] && tag_latest="true" || tag_latest="false"
15+
16+
17+
# CSI controller
18+
# --------------
1519
ctl_registry="${DOCKER_REGISTRY}/${CSI_CONTROLLER_IMAGE}"
1620
ctl_tag_specific="${ctl_registry}:${specific_tag}"
1721
ctl_tag_latest=${ctl_registry}:latest
@@ -22,12 +26,26 @@ docker build -t ${ctl_tag_specific} $taglatestflag -f Dockerfile-csi-controller
2226
docker push ${ctl_tag_specific}
2327
[ "$tag_latest" = "true" ] && docker push ${ctl_tag_latest} || :
2428

29+
# CSI node
30+
# --------
31+
node_registry="${DOCKER_REGISTRY}/${CSI_NODE_IMAGE}"
32+
node_tag_specific="${node_registry}:${specific_tag}"
33+
node_tag_latest=${node_registry}:latest
34+
[ "$tag_latest" = "true" ] && taglatestflag="-t ${node_tag_latest}"
35+
36+
echo "Build and push the CSI node image"
37+
docker build -t ${node_tag_specific} $taglatestflag -f Dockerfile-csi-node .
38+
docker push ${node_tag_specific}
39+
[ "$tag_latest" = "true" ] && docker push ${node_tag_latest} || :
40+
41+
2542
set +x
2643
echo ""
2744
echo "Image ready:"
2845
echo " ${ctl_tag_specific}"
29-
[ "$tag_latest" = "true" ] && echo " ${ctl_tag_latest}" || :
46+
echo " ${node_tag_specific}"
47+
[ "$tag_latest" = "true" ] && { echo " ${ctl_tag_latest}"; echo " ${node_tag_latest}"; } || :
3048

3149
# if param $1 given the script echo the specific tag
32-
[ -n "$1" ] && echo ${ctl_tag_specific} > $1 || :
50+
[ -n "$1" ] && printf "${ctl_tag_specific}\n${node_tag_specific}\n" > $1 || :
3351

scripts/ci/jenkins_pipeline_csi

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@ pipeline {
2020

2121
}
2222
}
23+
stage ('CSI-node: go Unit testing') {
24+
steps {
25+
sh 'mkdir -p build/reports && chmod 777 build/reports'
26+
sh 'make test-xunit-in-container'
27+
}
28+
}
2329
stage ('CSI-deployment: k8s yamls validation') {
2430
steps {
2531
sh './scripts/run_yamlcheck.sh'
2632
}
2733
}
28-
stage ('CSI-controller: Build and push image') {
34+
stage ('CSI-controller & node: Build and push images') {
2935
steps {
3036
sh './scripts/ci/build_push_images.sh build/reports/images_url'
3137
}

0 commit comments

Comments
 (0)