-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
279 lines (263 loc) · 6.72 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
image: docker:latest
stages:
- build
- release
- deploy
- canary
- clean
variables:
GIT_SUBMODULE_STRATEGY: recursive
PROD_STACK_NAME: archive
REVIEW_STACK_NAME: archive-review
IMAGE: recalbox/archive
.build_template: &build_definition
stage: build
script:
- export RECALBOX_VERSION="${CI_COMMIT_TAG:-${CI_COMMIT_REF_SLUG:0:12} (${CI_COMMIT_SHA:0:8}) ${CI_PIPELINE_ID} ${ARCH} $(date '+%Y/%m/%d %H:%M:%S')}"
- docker build -t "recalbox-${ARCH}" .
- docker run --rm -v `pwd`:/work -v /recalbox-builds/dl:/share/dl -v "/recalbox-builds/hosts/host-${ARCH}:/share/host" -v "/recalbox-builds/ccaches/ccache-${ARCH}:/share/ccache" -e "ARCH=${ARCH}" -e "RECALBOX_VERSION_LABEL=${RECALBOX_VERSION}" -e "RECALBOX_CCACHE_DIR=/share/ccache" "recalbox-${ARCH}" 2>&1 | tee build.log | grep '>>>' || tac build.log | grep '>>>' -m 1 -B 9999 | tac
- export DIST_DIR="updates/dist/v1/upgrade/${ARCH}"
- mkdir -p "${DIST_DIR}"
- cp output/images/recalbox/* "${DIST_DIR}"
- rm -rf output/
- for file in `ls "${DIST_DIR}"`;do sha1sum "${DIST_DIR}/${file}" > "${DIST_DIR}/${file}.sha1"; done
- tar tf "${DIST_DIR}/root.tar.xz" | sort > "${DIST_DIR}/root.list"
- echo "${RECALBOX_VERSION}" >> "${DIST_DIR}/recalbox.version"
- cp CHANGELOG.md "${DIST_DIR}/recalbox.changelog"
artifacts:
name: dist-${ARCH}-${CI_BUILD_ID}
when: always
paths:
- updates/dist/v1/upgrade/${ARCH}
- build.log
expire_in: 2 mos
build rpi1:
<<: *build_definition
only:
- master
- tags
variables:
ARCH: 'rpi1'
build rpi2:
<<: *build_definition
only:
- master
- tags
variables:
ARCH: 'rpi2'
build rpi3:
<<: *build_definition
only:
- master
- tags
variables:
ARCH: 'rpi3'
build x86_64:
<<: *build_definition
only:
- master
- tags
variables:
ARCH: 'x86_64'
build x86:
<<: *build_definition
only:
- master
- tags
variables:
ARCH: 'x86'
build odroidc2:
<<: *build_definition
only:
- master
- tags
variables:
ARCH: 'odroidc2'
build odroidxu4:
<<: *build_definition
only:
- master
- tags
variables:
ARCH: 'odroidxu4'
build rpi1 for test:
<<: *build_definition
when: manual
only:
- branches
except:
- master
variables:
ARCH: 'rpi1'
build rpi2 for test:
<<: *build_definition
when: manual
only:
- branches
except:
- master
variables:
ARCH: 'rpi2'
build rpi3 for test:
<<: *build_definition
when: manual
only:
- branches
except:
- master
variables:
ARCH: 'rpi3'
build x86_64 for test:
<<: *build_definition
when: manual
only:
- branches
except:
- master
variables:
ARCH: 'x86_64'
build x86 for test:
<<: *build_definition
when: manual
only:
- branches
except:
- master
variables:
ARCH: 'x86'
build odroidc2 for test:
<<: *build_definition
when: manual
only:
- branches
except:
- master
variables:
ARCH: 'odroidc2'
build odroidxu4 for test:
<<: *build_definition
when: manual
only:
- branches
except:
- master
variables:
ARCH: 'odroidxu4'
### Release
.release_template: &release_definition
stage: release
variables:
ARCHIVE_IMAGE: the image to build
RANCHER_DIRECTORY: type of the deployment (prod, review)
script:
- echo "Creating image ${ARCHIVE_IMAGE}"
- test -n "${SKIP_IMAGES}" && rm -rf updates/dist/v1/upgrade/*/*.img*
- env | grep "CI_\|GITLAB" > envfile && cat "updates/${RANCHER_DIRECTORY}.template.html" | docker run --rm --env-file envfile -i loicmahieu/alpine-envsubst > updates/dist/index.html
- cd updates
- docker build -t "${ARCHIVE_IMAGE}" .
- docker login -u "${DOCKER_IO_LOGIN}" -p "${DOCKER_IO_PASSWORD}"
- docker push "${ARCHIVE_IMAGE}"
release prod:
<<: *release_definition
variables:
ARCHIVE_IMAGE: ${IMAGE}:${CI_COMMIT_TAG}
RANCHER_DIRECTORY: prod
only:
- tags
release review:
<<: *release_definition
when: manual
variables:
ARCHIVE_IMAGE: ${IMAGE}:${CI_COMMIT_REF_SLUG}
RANCHER_DIRECTORY: review
SKIP_IMAGES: 'true'
except:
- tags
### Deploy
.deploy_template: &deploy_definition
stage: deploy
image: registry.gitlab.com/recalbox/ops/rancher-cli:0.6.2
dependencies: []
variables:
ARCHIVE_IMAGE: image to deploy
ARCHIVE_FQDN: fqdn of the service
RANCHER_DIRECTORY: the rancher directory to use
STACK: the stack to deploy on
script:
- cd "updates/rancher/${RANCHER_DIRECTORY}"
- sed "s/RANCHER_SERVICENAME/${SERVICENAME}/" -i docker-compose.yml rancher-compose.yml
- rancher up -s "$STACK" -u --force-upgrade --batch-size 50 -d
deploy prod:
<<: *deploy_definition
variables:
ARCHIVE_IMAGE: ${IMAGE}:${CI_COMMIT_TAG}
ARCHIVE_FQDN: lb-${PROD_STACK_NAME}-prod.recalbox.com
RANCHER_DIRECTORY: prod
RECALEUR_CANARY: ${RECALEUR_CANARY}
RECALEUR_RESPONSE: https://lb-${PROD_STACK_NAME}-prod.recalbox.com
RECALEUR_PATH: "/v1/upgrade"
RECALEUR_DELTA: ${RECALEUR_DELTA}
STACK: ${PROD_STACK_NAME}
before_script:
- export RECALEUR_EXPIRE=$(date -u -d "1970.01.01-00:00:$(date +"%s + 6 * 3600"|xargs expr)" +%Y-%m-%d-%H:%M)
only:
- tags
environment:
name: prod
url: https://lb-${PROD_STACK_NAME}-prod.recalbox.com
deploy review:
<<: *deploy_definition
when: manual
variables:
ARCHIVE_IMAGE: ${IMAGE}:${CI_COMMIT_REF_SLUG}
ARCHIVE_FQDN: ${CI_ENVIRONMENT_SLUG}-${REVIEW_STACK_NAME}-prod.recalbox.com
SERVICENAME: ${CI_ENVIRONMENT_SLUG}
RANCHER_DIRECTORY: review
STACK: ${REVIEW_STACK_NAME}
except:
- tags
environment:
name: review/${CI_COMMIT_REF_SLUG}
url: https://${CI_ENVIRONMENT_SLUG}-${REVIEW_STACK_NAME}-prod.recalbox.com
on_stop: clean review
validate release:
<<: *deploy_definition
stage: canary
when: manual
dependencies: []
variables:
RANCHER_DIRECTORY: recaleur
RECALEUR_CANARY: 256
RECALEUR_RESPONSE: https://lb-${PROD_STACK_NAME}-prod.recalbox.com
RECALEUR_PATH: "/v1/upgrade"
RECALEUR_DELTA: ${RECALEUR_DELTA}
STACK: ${PROD_STACK_NAME}
only:
- tags
emergency valve:
<<: *deploy_definition
stage: canary
when: manual
dependencies: []
variables:
RANCHER_DIRECTORY: recaleur
RECALEUR_CANARY: 0
RECALEUR_RESPONSE: https://lb-${PROD_STACK_NAME}-prod.recalbox.com
RECALEUR_PATH: "/v1/upgrade"
RECALEUR_DELTA: "0ms"
STACK: ${PROD_STACK_NAME}
only:
- tags
clean review:
image: registry.gitlab.com/recalbox/ops/rancher-cli:0.6.2
stage: clean
when: manual
dependencies: []
only:
- branches
script:
- echo "cleaning ${ARCHIVE_IMAGE} from ${REVIEW_STACK_NAME}/${CI_ENVIRONMENT_SLUG}"
- rancher rm "${REVIEW_STACK_NAME}/${CI_ENVIRONMENT_SLUG}"
environment:
name: review/${CI_COMMIT_REF_SLUG}
action: stop