forked from OS2borgerPC/os2borgerpc-admin-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
192 lines (167 loc) · 4.88 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# Copyright (C) 2021 Magenta ApS, http://magenta.dk.
# Contact: [email protected].
# For `docker push` to work, the following envionment variables have to be set
# in the Gitlab UI.
# RELEASE_REGISTRY_USER
# RELEASE_REGISTRY_PASSWORD
#
# For deployment via config-updater and saltbert these variables are needed as well:
# CONFIG_UPDATER_USERNAME
# CONFIG_UPDATER_PASSWORD
# SALTBERT_TEST_PASSWORD and SALBERT_PROD_PASSWORD
# (both are used as SALBERT_PASSWORD for test and prod servers respectively)
include:
- project: 'labs/salt-automation'
ref: 'master'
file:
- '/gitlab-ci-templates/common/rules.v1.yml'
- '/gitlab-ci-templates/common/config-updater-meta.v1.yml'
- '/gitlab-ci-templates/common/saltbert.v1.yml'
stages:
- lint
- build
- release
- deploy
variables:
# Project variables
IMAGE_SHA: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}
IMAGE_DEV: ${CI_REGISTRY_IMAGE}:dev
RELEASE_IMAGE: magentaaps/os2borgerpc-admin
RELEASE_IMAGE_TAG: ${RELEASE_IMAGE}:${CI_COMMIT_TAG}
RELEASE_IMAGE_LATEST: ${RELEASE_IMAGE}:latest
# Lint stage
############
.lint-default: &lint-default
stage: lint
needs: []
image: python:3.8
Lint Python:
<<: *lint-default
before_script:
- pip3 install -r admin_site/requirements.txt
- pip3 install black
script:
- cd admin_site
- black --version
- black --check --diff .
Lint Dockerfiles:
<<: *lint-default
image: hadolint/hadolint:latest-debian
before_script:
- apt-get -y update
- apt-get -y install --no-install-recommends git
script:
- git ls-files --exclude='Dockerfile*' --ignored | xargs --max-lines=1 hadolint
# Build stage
#############
Build app image:
stage: build
needs:
- Lint Python
- Lint Dockerfiles
dependencies: []
image:
name: gcr.io/kaniko-project/executor:debug-v0.16.0
entrypoint: [""]
script:
# Login to GitLab registry
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor
--cache
--context=$CI_PROJECT_DIR
--dockerfile=$CI_PROJECT_DIR/docker/Dockerfile
--destination=${IMAGE_SHA}
# Release stage
###############
.release-default: &release-default
stage: release
needs: ["Build app image"]
image: alpine
variables:
GIT_STRATEGY: none # We do not need the source code
dependencies: []
before_script:
# install skopeo
- apk add skopeo
Release dev:
<<: *release-default
only:
refs:
- develop
script:
- skopeo copy
--src-creds=${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}
--dest-creds=${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}
"docker://${IMAGE_SHA}"
"docker://${IMAGE_DEV}"
Release rc:
<<: *release-default
extends:
- .rules:semver-all
script:
- skopeo copy
--src-creds=${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}
--dest-creds=${RELEASE_REGISTRY_USER}:${RELEASE_REGISTRY_PASSWORD}
"docker://${IMAGE_SHA}"
"docker://${RELEASE_IMAGE_TAG}"
Release master:
<<: *release-default
extends:
- .rules:semver-core
script:
- skopeo copy
--src-creds=${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}
--dest-creds=${RELEASE_REGISTRY_USER}:${RELEASE_REGISTRY_PASSWORD}
"docker://${IMAGE_SHA}"
"docker://${RELEASE_IMAGE_TAG}"
- skopeo copy
--src-creds=${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}
--dest-creds=${RELEASE_REGISTRY_USER}:${RELEASE_REGISTRY_PASSWORD}
"docker://${IMAGE_SHA}"
"docker://${RELEASE_IMAGE_LATEST}"
# Deploy stage
##############
TESTING update version salt:
extends:
- .rules:semver-all
- .config:endpoint-with-tag
needs: ["Release rc"]
when: manual
variables:
ENDPOINT: os2bpc/salt/update-test
CONFIG_UPDATER_USERNAME: os2bpc
TESTING trigger salt deployment:
extends:
- .rules:semver-all
- .saltbert
needs: ["TESTING update version salt"]
when: manual
variables:
SALTBERT_ORCHESTRATION: os2bpc.test
SALTBERT_URL: https://saltmaster.os2borgerpc.magentahosted.dk
SALTBERT_PASSWORD: $SALTBERT_TEST_PASSWORD
environment:
name: os2borgerpc-test
url: https://os2borgerpc-test.magenta.dk
PROD update version salt:
extends:
- .rules:semver-core
- .config:endpoint-with-tag
needs: ["Release master", "TESTING trigger salt deployment"]
when: manual
variables:
ENDPOINT: os2bpc/salt/update-production
CONFIG_UPDATER_USERNAME: os2bpc
PROD trigger salt deployment:
extends:
- .rules:semver-core
- .saltbert
needs: ["PROD update version salt"]
when: manual
variables:
SALTBERT_ORCHESTRATION: os2bpc.production
SALTBERT_URL: https://saltmaster.os2borgerpc.magentahosted.dk
SALTBERT_PASSWORD: $SALTBERT_PROD_PASSWORD
environment:
name: os2borgerpc-admin
url: https://os2borgerpc-admin.magenta.dk