-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
122 lines (114 loc) · 5.77 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
image: registry.gitlab.com/nso-developer/ci-runner-image:latest
# Stages for our CI jobs
# Gitlab only allows the specification of one progression of stages. We use two
# different "modes" for running our jobs, which are essentially mutually
# exclusive. In the special CI_MODE=mirror, there is only a single mirror job
# that runs in the mirror stage. For a normal CI run, the other stages are used.
stages:
- mirror
- build
# The before script makes sure that docker is installed, since that is a
# prerequisite for most jobs. If the jobs are run with a standard debian or
# Ubuntu image, docker isn't installed. To speed up the build, this install step
# can be skipped by running an image that already has docker installed, for
# example registry.gitlab.com/nso-developer/ci-runner-image:latest
#
# We also define the helper functions mark_section_start/end that help us mark
# out the start and end of a "section" in a CI job. Each section can be folded
# and gets a duration timestamp in the CI job view making it easy to see how
# long it took to run.
before_script:
- |
function mark_section_start() {
echo -e "section_start:0:$1\r\e[0K$2"
SECONDS=0
}
function mark_section_end() {
echo -e "section_end:${SECONDS}:$1\r\e[0K"
}
- mark_section_start initialize Initializing
- which curl docker expect gpg2 sshpass xmlstarlet >/dev/null || (echo "Installing prerequisites..." && apt-get -y update && DEBIAN_FRONTEND=noninteractive apt-get install -qy apt-transport-https ca-certificates curl expect gnupg2 software-properties-common sshpass xmlstarlet; which docker || (echo "Installing docker..." && curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && apt-key fingerprint 0EBFCD88 && add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" && apt-get -y update && apt-get -qy install -qy docker-ce docker-ce-cli containerd.io))
- mark_section_end initialize
# Template for the standard build job
.build:
stage: build
except:
variables:
- $CI_MODE == "mirror"
script:
- if [ -n "${CI_DOCKER_USER}" ]; then echo "Using provided credentials for authentication with docker registry"; docker login -u ${CI_DOCKER_USER} -p ${CI_DOCKER_PASSWORD} ${CI_REGISTRY}; else docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY}; fi
- echo "Building for NSO version ${NSO_VERSION}"
- mark_section_start build Building
- make build
- mark_section_end build
- mark_section_start test-start "Starting testenv"
- make testenv-start
- mark_section_end test-start
- mark_section_start test-run "Running tests"
- make testenv-test
- mark_section_end test-run
- mark_section_start test-stop "Stopping testenv"
- make testenv-stop
- mark_section_end test-stop
- mark_section_start image-push "Pushing images"
- echo "Using Gitlab CI token to authenticate with Docker registry for pushing image"
- docker login -u gitlab-ci-token -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
- if [ "${DOCKER_PUSH}" != "false" ]; then make push; fi
- if [ "${CI_COMMIT_REF_NAME}" = "master" ]; then make tag-release; fi
- if [ "${CI_COMMIT_REF_NAME}" = "master" ] && [ "${DOCKER_PUSH}" != "false" ]; then make push-release; fi
- mark_section_end image-push
after_script:
- make testenv-stop
# Special CI job for running a mirroring job that pulls in the latest changes
# from upstream. Unlike normal GitLab mirroring, which fails whenever the local
# repository has diverged (has changes), this job uses a normal 'git pull' which
# means merge commits are used when necessary. It essentially allows local
# modifications.
mirror:
stage: mirror
only:
variables:
- $CI_MODE == "mirror"
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install -y openssh-client )'
- 'which git || ( apt-get update -y && apt-get install -y git )'
- eval $(ssh-agent -s)
- ssh-add <(echo "${GIT_SSH_PRIV_KEY}")
- mkdir -p ~/.ssh
- echo "${GITLAB_HOSTKEY}" >> ~/.ssh/known_hosts
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git config --global user.name "${GITLAB_USER_NAME}"
script:
- "git clone git@${CI_SERVER_HOST}:${CI_PROJECT_PATH}.git"
- cd "${CI_PROJECT_NAME}"
- git remote add upstream "${MIRROR_REMOTE}"
- if [ "${MIRROR_PULL_MODE}" = "rebase" ]; then git pull --rebase upstream master; else git pull upstream master; fi
- if [ "${MIRROR_PULL_MODE}" = "rebase" ]; then git push --force origin master; else git push origin master; fi
# Version set to include. These file contain the actual jobs that instantiate
# the templates above for various version of NSO. The default is to build for
# all supported NSO versions by including a CI config file from the upstream
# nso-docker repository. It is normal to build your own version set for the NSO
# versions you are interested in and include that here.
#include: 'https://gitlab.com/nso-developer/nso-docker/-/raw/master/version-sets/supported-nso/build-tot.yaml'
# For example, replace it with the URL to your mirror of the nso-docker repo and
# the version-set you use;
# include: 'https://example.com/foo/nso-docker/-/raw/master/version-sets/bar/build-tot.yaml'
#
# Or if it is hosted on the same GitLab instance as this repo, you can use a
# relative link:
# include: 'foo/nso-docker/-/raw/master/version-sets/bar/build-tot.yaml'
#
# An alternative is to specify the build jobs manually, like so:
#
# build-5.3.1:
# extends: .build
# variables:
# NSO_VERSION: "5.3.1"
#
# This isn't recommended other than perhaps for a quick test. It is much better
# to build a version-set on your main NSO system repo and include it so you
# build all your repositories for a consistent set of versions.
build-5.4:
extends: .build
variables:
NSO_VERSION: "5.4"