Merge branch 'tag-gun-erratic' into 'develop'
[akkoma] / .gitlab-ci.yml
1 image: elixir:1.9.4
2
3 variables: &global_variables
4 POSTGRES_DB: pleroma_test
5 POSTGRES_USER: postgres
6 POSTGRES_PASSWORD: postgres
7 DB_HOST: postgres
8 MIX_ENV: test
9
10 cache: &global_cache_policy
11 key:
12 files:
13 - mix.lock
14 paths:
15 - deps
16 - _build
17
18 stages:
19 - build
20 - test
21 - benchmark
22 - deploy
23 - release
24 - docker
25
26 before_script:
27 - echo $MIX_ENV
28 - rm -rf _build/*/lib/pleroma
29 - apt-get update && apt-get install -y cmake
30 - mix local.hex --force
31 - mix local.rebar --force
32 - mix deps.get
33 - apt-get -qq update
34 - apt-get install -y libmagic-dev
35
36 after_script:
37 - rm -rf _build/*/lib/pleroma
38
39 build:
40 stage: build
41 only:
42 changes:
43 - "**/*.ex"
44 - "**/*.exs"
45 - "mix.lock"
46 script:
47 - mix compile --force
48
49 spec-build:
50 stage: test
51 only:
52 changes:
53 - "lib/pleroma/web/api_spec/**/*.ex"
54 - "lib/pleroma/web/api_spec.ex"
55 artifacts:
56 paths:
57 - spec.json
58 script:
59 - mix pleroma.openapi_spec spec.json
60
61 benchmark:
62 stage: benchmark
63 when: manual
64 variables:
65 MIX_ENV: benchmark
66 services:
67 - name: postgres:9.6
68 alias: postgres
69 command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
70 script:
71 - mix ecto.create
72 - mix ecto.migrate
73 - mix pleroma.load_testing
74
75 unit-testing:
76 stage: test
77 only:
78 changes:
79 - "**/*.ex"
80 - "**/*.exs"
81 - "mix.lock"
82 cache: &testing_cache_policy
83 <<: *global_cache_policy
84 policy: pull
85
86 services:
87 - name: postgres:13
88 alias: postgres
89 command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
90 script:
91 - apt-get update && apt-get install -y libimage-exiftool-perl ffmpeg
92 - mix ecto.create
93 - mix ecto.migrate
94 - mix coveralls --preload-modules
95
96 unit-testing-erratic:
97 stage: test
98 retry: 2
99 only:
100 changes:
101 - "**/*.ex"
102 - "**/*.exs"
103 - "mix.lock"
104 cache: &testing_cache_policy
105 <<: *global_cache_policy
106 policy: pull
107
108 services:
109 - name: postgres:13
110 alias: postgres
111 command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
112 script:
113 - mix ecto.create
114 - mix ecto.migrate
115 - mix test --only=erratic
116
117 # Removed to fix CI issue. In this early state it wasn't adding much value anyway.
118 # TODO Fix and reinstate federated testing
119 # federated-testing:
120 # stage: test
121 # cache: *testing_cache_policy
122 # services:
123 # - name: minibikini/postgres-with-rum:12
124 # alias: postgres
125 # command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
126 # script:
127 # - mix deps.get
128 # - mix ecto.create
129 # - mix ecto.migrate
130 # - epmd -daemon
131 # - mix test --trace --only federated
132
133 unit-testing-rum:
134 stage: test
135 only:
136 changes:
137 - "**/*.ex"
138 - "**/*.exs"
139 - "mix.lock"
140 cache: *testing_cache_policy
141 services:
142 - name: minibikini/postgres-with-rum:12
143 alias: postgres
144 command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
145 variables:
146 <<: *global_variables
147 RUM_ENABLED: "true"
148 script:
149 - apt-get update && apt-get install -y libimage-exiftool-perl ffmpeg
150 - mix ecto.create
151 - mix ecto.migrate
152 - "mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/"
153 - mix test --preload-modules
154
155 lint:
156 image: elixir:1.12
157 stage: test
158 only:
159 changes:
160 - "**/*.ex"
161 - "**/*.exs"
162 - "mix.lock"
163 cache: *testing_cache_policy
164 script:
165 - mix format --check-formatted
166
167 analysis:
168 stage: test
169 only:
170 changes:
171 - "**/*.ex"
172 - "**/*.exs"
173 - "mix.lock"
174 cache: *testing_cache_policy
175 script:
176 - mix credo --strict --only=warnings,todo,fixme,consistency,readability
177
178 cycles:
179 stage: test
180 image: elixir:1.11
181 only:
182 changes:
183 - "**/*.ex"
184 - "**/*.exs"
185 - "mix.lock"
186 cache: {}
187 script:
188 - mix deps.get
189 - mix compile
190 - mix xref graph --format cycles --label compile | awk '{print $0} END{exit ($0 != "No cycles found")}'
191
192 docs-deploy:
193 stage: deploy
194 cache: *testing_cache_policy
195 image: alpine:latest
196 only:
197 - stable@pleroma/pleroma
198 - develop@pleroma/pleroma
199 before_script:
200 - apk add curl
201 script:
202 - curl -X POST -F"token=$DOCS_PIPELINE_TRIGGER" -F'ref=master' -F"variables[BRANCH]=$CI_COMMIT_REF_NAME" https://git.pleroma.social/api/v4/projects/673/trigger/pipeline
203 review_app:
204 image: alpine:3.9
205 stage: deploy
206 before_script:
207 - apk update && apk add openssh-client git
208 when: manual
209 environment:
210 name: review/$CI_COMMIT_REF_NAME
211 url: https://$CI_ENVIRONMENT_SLUG.pleroma.online/
212 on_stop: stop_review_app
213 only:
214 - branches
215 except:
216 - master
217 - develop
218 script:
219 - echo "$CI_ENVIRONMENT_SLUG"
220 - mkdir -p ~/.ssh
221 - eval $(ssh-agent -s)
222 - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
223 - ssh-keyscan -H "pleroma.online" >> ~/.ssh/known_hosts
224 - (ssh -t dokku@pleroma.online -- apps:create "$CI_ENVIRONMENT_SLUG") || true
225 - (ssh -t dokku@pleroma.online -- git:set "$CI_ENVIRONMENT_SLUG" keep-git-dir true) || true
226 - ssh -t dokku@pleroma.online -- config:set "$CI_ENVIRONMENT_SLUG" APP_NAME="$CI_ENVIRONMENT_SLUG" APP_HOST="$CI_ENVIRONMENT_SLUG.pleroma.online" MIX_ENV=dokku
227 - (ssh -t dokku@pleroma.online -- postgres:create $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db) || true
228 - (ssh -t dokku@pleroma.online -- postgres:link $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db "$CI_ENVIRONMENT_SLUG") || true
229 - (ssh -t dokku@pleroma.online -- certs:add "$CI_ENVIRONMENT_SLUG" /home/dokku/server.crt /home/dokku/server.key) || true
230 - git push -f dokku@pleroma.online:$CI_ENVIRONMENT_SLUG $CI_COMMIT_SHA:refs/heads/master
231
232 spec-deploy:
233 stage: deploy
234 artifacts:
235 paths:
236 - spec.json
237 only:
238 - develop@pleroma/pleroma
239 image: alpine:latest
240 before_script:
241 - apk add curl
242 script:
243 - curl -X POST -F"token=$API_DOCS_PIPELINE_TRIGGER" -F'ref=master' -F"variables[BRANCH]=$CI_COMMIT_REF_NAME" -F"variables[JOB_REF]=$CI_JOB_ID" https://git.pleroma.social/api/v4/projects/1130/trigger/pipeline
244
245
246 stop_review_app:
247 image: alpine:3.9
248 stage: deploy
249 before_script:
250 - apk update && apk add openssh-client git
251 when: manual
252 environment:
253 name: review/$CI_COMMIT_REF_NAME
254 action: stop
255 script:
256 - echo "$CI_ENVIRONMENT_SLUG"
257 - mkdir -p ~/.ssh
258 - eval $(ssh-agent -s)
259 - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
260 - ssh-keyscan -H "pleroma.online" >> ~/.ssh/known_hosts
261 - ssh -t dokku@pleroma.online -- --force apps:destroy "$CI_ENVIRONMENT_SLUG"
262 - ssh -t dokku@pleroma.online -- --force postgres:destroy $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db
263
264 amd64:
265 stage: release
266 image: elixir:1.10.4
267 only: &release-only
268 - stable@pleroma/pleroma
269 - develop@pleroma/pleroma
270 - /^maint/.*$/@pleroma/pleroma
271 - /^release/.*$/@pleroma/pleroma
272 artifacts: &release-artifacts
273 name: "pleroma-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
274 paths:
275 - release/*
276 # Ideally it would be never for master branch and with the next commit for develop,
277 # but Gitlab does not support neither `only` for artifacts
278 # nor setting it to never from .gitlab-ci.yml
279 # nor expiring with the next commit
280 expire_in: 42 yrs
281
282 cache: &release-cache
283 key: $CI_COMMIT_REF_NAME-$CI_JOB_NAME
284 paths:
285 - deps
286 variables: &release-variables
287 MIX_ENV: prod
288 before_script: &before-release
289 - apt-get update && apt-get install -y cmake libmagic-dev
290 - echo "import Mix.Config" > config/prod.secret.exs
291 - mix local.hex --force
292 - mix local.rebar --force
293 script: &release
294 - mix deps.get --only prod
295 - mkdir release
296 - export PLEROMA_BUILD_BRANCH=$CI_COMMIT_REF_NAME
297 - mix release --path release
298
299
300 amd64-musl:
301 stage: release
302 artifacts: *release-artifacts
303 only: *release-only
304 image: elixir:1.10.4-alpine
305 cache: *release-cache
306 variables: *release-variables
307 before_script: &before-release-musl
308 - apk add git gcc g++ musl-dev make cmake file-dev
309 - echo "import Mix.Config" > config/prod.secret.exs
310 - mix local.hex --force
311 - mix local.rebar --force
312 script: *release
313
314 arm:
315 stage: release
316 artifacts: *release-artifacts
317 only: *release-only
318 tags:
319 - arm32-specified
320 image: arm32v7/elixir:1.10.4
321 cache: *release-cache
322 variables: *release-variables
323 before_script: *before-release
324 script: *release
325
326 arm-musl:
327 stage: release
328 artifacts: *release-artifacts
329 only: *release-only
330 tags:
331 - arm32-specified
332 image: arm32v7/elixir:1.10.4-alpine
333 cache: *release-cache
334 variables: *release-variables
335 before_script: *before-release-musl
336 script: *release
337
338 arm64:
339 stage: release
340 artifacts: *release-artifacts
341 only: *release-only
342 tags:
343 - arm
344 image: arm64v8/elixir:1.10.4
345 cache: *release-cache
346 variables: *release-variables
347 before_script: *before-release
348 script: *release
349
350 arm64-musl:
351 stage: release
352 artifacts: *release-artifacts
353 only: *release-only
354 tags:
355 - arm
356 image: arm64v8/elixir:1.10.4-alpine
357 cache: *release-cache
358 variables: *release-variables
359 before_script: *before-release-musl
360 script: *release
361
362 docker:
363 stage: docker
364 image: docker:latest
365 cache: {}
366 dependencies: []
367 variables: &docker-variables
368 DOCKER_DRIVER: overlay2
369 DOCKER_HOST: unix:///var/run/docker.sock
370 IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
371 IMAGE_TAG_SLUG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
372 IMAGE_TAG_LATEST: $CI_REGISTRY_IMAGE:latest
373 IMAGE_TAG_LATEST_STABLE: $CI_REGISTRY_IMAGE:latest-stable
374 DOCKER_BUILDX_URL: https://github.com/docker/buildx/releases/download/v0.6.3/buildx-v0.6.3.linux-amd64
375 DOCKER_BUILDX_HASH: 980e6b9655f971991fbbb5fd6cd19f1672386195
376 before_script: &before-docker
377 - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
378 - docker pull $IMAGE_TAG_SLUG || true
379 - export CI_JOB_TIMESTAMP=$(date --utc -Iseconds)
380 - export CI_VCS_REF=$CI_COMMIT_SHORT_SHA
381 allow_failure: true
382 script:
383 - mkdir -p /root/.docker/cli-plugins
384 - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
385 - echo "${DOCKER_BUILDX_HASH} /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
386 - chmod +x ~/.docker/cli-plugins/docker-buildx
387 - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
388 - docker buildx create --name mbuilder --driver docker-container --use
389 - docker buildx inspect --bootstrap
390 - docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm64/v8 --push --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG -t $IMAGE_TAG_LATEST .
391 tags:
392 - dind
393 only:
394 - develop@pleroma/pleroma
395
396 docker-stable:
397 stage: docker
398 image: docker:latest
399 cache: {}
400 dependencies: []
401 variables: *docker-variables
402 before_script: *before-docker
403 allow_failure: true
404 script:
405 - mkdir -p /root/.docker/cli-plugins
406 - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
407 - echo "${DOCKER_BUILDX_HASH} /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
408 - chmod +x ~/.docker/cli-plugins/docker-buildx
409 - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
410 - docker buildx create --name mbuilder --driver docker-container --use
411 - docker buildx inspect --bootstrap
412 - docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm64/v8 --push --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG -t $IMAGE_TAG_LATEST_STABLE .
413 tags:
414 - dind
415 only:
416 - stable@pleroma/pleroma
417
418 docker-release:
419 stage: docker
420 image: docker:latest
421 cache: {}
422 dependencies: []
423 variables: *docker-variables
424 before_script: *before-docker
425 allow_failure: true
426 script:
427 script:
428 - mkdir -p /root/.docker/cli-plugins
429 - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
430 - echo "${DOCKER_BUILDX_HASH} /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
431 - chmod +x ~/.docker/cli-plugins/docker-buildx
432 - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
433 - docker buildx create --name mbuilder --driver docker-container --use
434 - docker buildx inspect --bootstrap
435 - docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm64/v8 --push --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG .
436 tags:
437 - dind
438 only:
439 - /^release/.*$/@pleroma/pleroma
440
441 docker-adhoc:
442 stage: docker
443 image: docker:latest
444 cache: {}
445 dependencies: []
446 variables: *docker-variables
447 before_script: *before-docker
448 allow_failure: true
449 script:
450 script:
451 - mkdir -p /root/.docker/cli-plugins
452 - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
453 - echo "${DOCKER_BUILDX_HASH} /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
454 - chmod +x ~/.docker/cli-plugins/docker-buildx
455 - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
456 - docker buildx create --name mbuilder --driver docker-container --use
457 - docker buildx inspect --bootstrap
458 - docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm64/v8 --push --cache-from $IMAGE_TAG_SLUG --build-arg VCS_REF=$CI_VCS_REF --build-arg BUILD_DATE=$CI_JOB_TIMESTAMP -t $IMAGE_TAG -t $IMAGE_TAG_SLUG .
459 tags:
460 - dind
461 only:
462 - /^build-docker/.*$/@pleroma/pleroma