-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
328 lines (299 loc) · 7.28 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# SPDX-FileCopyrightText: 2020-2024 Technostructures
# SPDX-License-Identifier: AGPL-3.0-only
stages:
- setup
- deploy_staging
- analysis
- deploy_production
- docs
image: elixir:1.17-otp-27-alpine
cache: &global_cache
key: cache-test
when: always
policy: pull
paths:
- _build
- deps
variables:
MIX_ENV: test
GIT_SUBMODULE_STRATEGY: recursive
### setup
.prepare:
stage: setup
interruptible: true
script:
- apk update
- apk add git cmake g++
- mix local.hex --force
- mix local.rebar --force
- mix deps.get
- mix compile
prepare_test:
extends: .prepare
cache:
<<: *global_cache
policy: pull-push
build_plt:
stage: setup
interruptible: true
rules:
- changes:
- matrix_app_service
- activity_pub
- polyjuice_client
if: '$CI_PIPELINE_SOURCE != "merge_request_event"'
script:
- apk update
- apk add git cmake g++
- mix local.hex --force
- mix local.rebar --force
- mix deps.get
- mix compile
- mix dialyzer.clean
- mix dialyzer.build
cache:
<<: *global_cache
policy: pull-push
prepare_dev:
extends: .prepare
only:
- main
variables:
MIX_ENV: dev
cache:
<<: *global_cache
policy: pull-push
key: cache-dev
.docker:
stage: setup
image: ezkrg/buildx:v0.11.2
services:
- name: docker:dind
command: ["dockerd", "--host=tcp://0.0.0.0:2375"]
alias: 'docker'
variables:
- DOCKER_DRIVER: overlay2
- DOCKER_HOST: tcp://docker:2375/
- DOCKER_BUILDKIT: 1
before_script:
- echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
variables:
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
.docker_tag:
extends: .docker
needs:
- build_docker_image
script:
- docker pull $IMAGE_TAG
- docker tag $IMAGE_TAG $IMAGE_NEW_TAG
- docker push $IMAGE_NEW_TAG
variables:
GIT_STRATEGY: none
build_docker_image:
extends: .docker
interruptible: true
before_script:
- docker buildx create --driver=docker-container --name=buildkit-builder --use
- echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
script:
- docker pull $CI_REGISTRY_IMAGE:latest || true
- echo $IMAGE_TAG
- >
docker buildx build
-f Dockerfile.prod
--pull
--build-arg VCS_REF=$CI_COMMIT_SHA
--build-arg VCS_URL=$CI_PROJECT_URL
--tag $IMAGE_TAG
--cache-from type=registry,ref=$CI_REGISTRY_IMAGE:cache
--cache-to type=registry,ref=$CI_REGISTRY_IMAGE:cache,mode=max
--push
.
tag_image_latest:
extends: .docker_tag
only:
refs:
- main
variables:
IMAGE_NEW_TAG: $CI_REGISTRY_IMAGE:latest
tag_image_branches:
extends: .docker_tag
only:
refs:
- branches
variables:
IMAGE_NEW_TAG: $CI_REGISTRY_IMAGE:CI_COMMIT_REF_NAME
tag_image_prerelease:
extends: .docker
rules:
- if: $CI_COMMIT_TAG =~ /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
needs:
- build_docker_image
script:
- docker pull $IMAGE_TAG
- |
export PRERELEASE_TAG=$CI_REGISTRY_IMAGE:$(echo $CI_COMMIT_TAG | sed 's/^v//')
docker tag $IMAGE_TAG $PRERELEASE_TAG
- docker push --all-tags $CI_REGISTRY_IMAGE
variables:
GIT_STRATEGY: none
tag_image_release:
extends: .docker
rules:
- if: $CI_COMMIT_TAG =~ /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
needs:
- build_docker_image
script:
- docker pull $IMAGE_TAG
- |
export PATCH_TAG=$CI_REGISTRY_IMAGE:$(echo $CI_COMMIT_TAG | sed -E 's/^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/\1\.\2\.\3/')
docker tag $IMAGE_TAG $PATCH_TAG
- |
export MINOR_TAG=$CI_REGISTRY_IMAGE:$(echo $CI_COMMIT_TAG | sed -E 's/^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/\1\.\2/')
docker tag $IMAGE_TAG $MINOR_TAG
- |
export MAJOR_TAG=$CI_REGISTRY_IMAGE:$(echo $CI_COMMIT_TAG | sed -E 's/^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/\1/')
docker tag $IMAGE_TAG $MAJOR_TAG
- docker push --all-tags $CI_REGISTRY_IMAGE
variables:
GIT_STRATEGY: none
### deploy_staging
deploy_staging:
stage: deploy_staging
needs:
- build_docker_image
when: manual
environment:
name: "staging"
url: "https://staging.kazar.ma"
variables:
KAZARMA_TAG: $CI_COMMIT_SHA
image: dwdraju/alpine-curl-jq
# amazing hack from
# https://gitlab.com/davebarr/multi-pipeline-project-1/-/blob/100f7dbfb881b5ae5e87d8d89407c0970f1bcd42/.gitlab-ci.yml
script:
- iid=$(curl -X POST -F "token=$CI_JOB_TOKEN" -F ref=main -F "variables[ENV]=staging" -F "variables[KAZARMA_TAG]=$CI_COMMIT_SHA" "https://gitlab.com/api/v4/projects/36494803/trigger/pipeline" | jq -r .id)
- >
curl -X GET -H "PRIVATE-TOKEN: $API_TOKEN" "https://gitlab.com/api/v4/projects/36494803/pipelines/$iid"
- exit 0
# unfortunately it doesn't seem to work without a user or group token?
# - |
# while true; do
# pipeline_status=$(curl -X GET -H "PRIVATE-TOKEN: $API_TOKEN" "https://gitlab.com/api/v4/projects/36494803/pipelines/$iid" | jq -r .status)
# echo $pipeline_status
# case "$pipeline_status" in
# success)
# exit 0
# ;;
# canceled | failed | skipped | manual | scheduled)
# exit 1
# ;;
# esac
# sleep 5
# done
### analysis
.analysis:
stage: analysis
interruptible: true
.mix:
before_script:
- apk update
- apk add git cmake g++
- mix local.hex --force
- mix deps.get
- mix compile
test:
extends: .analysis
needs:
- prepare_test
services:
- postgres:latest
variables:
POSTGRES_DB: kazarma_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_HOST: postgres
POSTGRES_HOST_AUTH_METHOD: trust
MIX_ENV: test
before_script:
- apk update
- apk add git cmake g++
- mix local.hex --force
- mix deps.get
- mix compile
- mix ecto.create
- mix ecto.migrate
script:
- mix coveralls.cobertura
coverage: '/\[TOTAL\]\s+(\d+\.\d+)%/'
artifacts:
when: always
reports:
junit: _build/test/lib/kazarma/test-junit-report.xml
coverage_report:
coverage_format: cobertura
path: cover/cobertura.xml
format:
extends:
- .analysis
- .mix
needs:
- prepare_test
script:
- mix format --check-formatted
credo:
extends:
- .analysis
- .mix
needs:
- prepare_test
script:
- mix credo suggest | tee credo.log
artifacts:
when: always
paths:
- "credo.log"
dialyzer:
extends:
- .analysis
- .mix
needs:
- job: prepare_test
- job: build_plt
optional: true
script:
- mix dialyzer
cache:
<<: *global_cache
policy: pull-push
paths:
- _build
- deps
- priv/plts
reuse:
extends: .analysis
needs: []
image:
name: fsfe/reuse:latest
entrypoint: [""]
script:
- reuse lint
### docs
pages:
extends: .mix
stage: docs
only:
- main
needs:
- prepare_dev
variables:
MIX_ENV: dev
interruptible: true
script:
- mix docs -o public
cache:
<<: *global_cache
key: cache-dev
artifacts:
paths:
- public