Cycles CI: disable cache
[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 retry: 2
83 cache: &testing_cache_policy
84 <<: *global_cache_policy
85 policy: pull
86
87 services:
88 - name: postgres:13
89 alias: postgres
90 command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
91 script:
92 - apt-get update && apt-get install -y libimage-exiftool-perl ffmpeg
93 - mix ecto.create
94 - mix ecto.migrate
95 - mix coveralls --preload-modules
96
97 # Removed to fix CI issue. In this early state it wasn't adding much value anyway.
98 # TODO Fix and reinstate federated testing
99 # federated-testing:
100 # stage: test
101 # cache: *testing_cache_policy
102 # services:
103 # - name: minibikini/postgres-with-rum:12
104 # alias: postgres
105 # command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
106 # script:
107 # - mix deps.get
108 # - mix ecto.create
109 # - mix ecto.migrate
110 # - epmd -daemon
111 # - mix test --trace --only federated
112
113 unit-testing-rum:
114 stage: test
115 only:
116 changes:
117 - "**/*.ex"
118 - "**/*.exs"
119 - "mix.lock"
120 retry: 2
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 variables:
127 <<: *global_variables
128 RUM_ENABLED: "true"
129 script:
130 - apt-get update && apt-get install -y libimage-exiftool-perl ffmpeg
131 - mix ecto.create
132 - mix ecto.migrate
133 - "mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/"
134 - mix test --preload-modules
135
136 lint:
137 stage: test
138 only:
139 changes:
140 - "**/*.ex"
141 - "**/*.exs"
142 - "mix.lock"
143 cache: *testing_cache_policy
144 script:
145 - mix format --check-formatted
146
147 analysis:
148 stage: test
149 only:
150 changes:
151 - "**/*.ex"
152 - "**/*.exs"
153 - "mix.lock"
154 cache: *testing_cache_policy
155 script:
156 - mix credo --strict --only=warnings,todo,fixme,consistency,readability
157
158 cycles:
159 stage: test
160 image: elixir:1.11
161 cache: {}
162 script:
163 - mix deps.get
164 - mix compile
165 - mix xref graph --format cycles --label compile | awk '{print $0} END{exit ($0 != "No cycles found")}'
166
167 docs-deploy:
168 stage: deploy
169 cache: *testing_cache_policy
170 image: alpine:latest
171 only:
172 - stable@pleroma/pleroma
173 - develop@pleroma/pleroma
174 before_script:
175 - apk add curl
176 script:
177 - 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
178 review_app:
179 image: alpine:3.9
180 stage: deploy
181 before_script:
182 - apk update && apk add openssh-client git
183 when: manual
184 environment:
185 name: review/$CI_COMMIT_REF_NAME
186 url: https://$CI_ENVIRONMENT_SLUG.pleroma.online/
187 on_stop: stop_review_app
188 only:
189 - branches
190 except:
191 - master
192 - develop
193 script:
194 - echo "$CI_ENVIRONMENT_SLUG"
195 - mkdir -p ~/.ssh
196 - eval $(ssh-agent -s)
197 - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
198 - ssh-keyscan -H "pleroma.online" >> ~/.ssh/known_hosts
199 - (ssh -t dokku@pleroma.online -- apps:create "$CI_ENVIRONMENT_SLUG") || true
200 - (ssh -t dokku@pleroma.online -- git:set "$CI_ENVIRONMENT_SLUG" keep-git-dir true) || true
201 - 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
202 - (ssh -t dokku@pleroma.online -- postgres:create $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db) || true
203 - (ssh -t dokku@pleroma.online -- postgres:link $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db "$CI_ENVIRONMENT_SLUG") || true
204 - (ssh -t dokku@pleroma.online -- certs:add "$CI_ENVIRONMENT_SLUG" /home/dokku/server.crt /home/dokku/server.key) || true
205 - git push -f dokku@pleroma.online:$CI_ENVIRONMENT_SLUG $CI_COMMIT_SHA:refs/heads/master
206
207 spec-deploy:
208 stage: deploy
209 artifacts:
210 paths:
211 - spec.json
212 only:
213 - develop@pleroma/pleroma
214 image: alpine:latest
215 before_script:
216 - apk add curl
217 script:
218 - 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
219
220
221 stop_review_app:
222 image: alpine:3.9
223 stage: deploy
224 before_script:
225 - apk update && apk add openssh-client git
226 when: manual
227 environment:
228 name: review/$CI_COMMIT_REF_NAME
229 action: stop
230 script:
231 - echo "$CI_ENVIRONMENT_SLUG"
232 - mkdir -p ~/.ssh
233 - eval $(ssh-agent -s)
234 - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
235 - ssh-keyscan -H "pleroma.online" >> ~/.ssh/known_hosts
236 - ssh -t dokku@pleroma.online -- --force apps:destroy "$CI_ENVIRONMENT_SLUG"
237 - ssh -t dokku@pleroma.online -- --force postgres:destroy $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db
238
239 amd64:
240 stage: release
241 image: elixir:1.10.3
242 only: &release-only
243 - stable@pleroma/pleroma
244 - develop@pleroma/pleroma
245 - /^maint/.*$/@pleroma/pleroma
246 - /^release/.*$/@pleroma/pleroma
247 artifacts: &release-artifacts
248 name: "pleroma-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
249 paths:
250 - release/*
251 # Ideally it would be never for master branch and with the next commit for develop,
252 # but Gitlab does not support neither `only` for artifacts
253 # nor setting it to never from .gitlab-ci.yml
254 # nor expiring with the next commit
255 expire_in: 42 yrs
256
257 cache: &release-cache
258 key: $CI_COMMIT_REF_NAME-$CI_JOB_NAME
259 paths:
260 - deps
261 variables: &release-variables
262 MIX_ENV: prod
263 before_script: &before-release
264 - apt-get update && apt-get install -y cmake libmagic-dev
265 - echo "import Mix.Config" > config/prod.secret.exs
266 - mix local.hex --force
267 - mix local.rebar --force
268 script: &release
269 - mix deps.get --only prod
270 - mkdir release
271 - export PLEROMA_BUILD_BRANCH=$CI_COMMIT_REF_NAME
272 - mix release --path release
273
274
275 amd64-musl:
276 stage: release
277 artifacts: *release-artifacts
278 only: *release-only
279 image: elixir:1.10.3-alpine
280 cache: *release-cache
281 variables: *release-variables
282 before_script: &before-release-musl
283 - apk add git gcc g++ musl-dev make cmake file-dev
284 - echo "import Mix.Config" > config/prod.secret.exs
285 - mix local.hex --force
286 - mix local.rebar --force
287 script: *release
288
289 arm:
290 stage: release
291 artifacts: *release-artifacts
292 only: *release-only
293 tags:
294 - arm32-specified
295 image: arm32v7/elixir:1.10.3
296 cache: *release-cache
297 variables: *release-variables
298 before_script: *before-release
299 script: *release
300
301 arm-musl:
302 stage: release
303 artifacts: *release-artifacts
304 only: *release-only
305 tags:
306 - arm32-specified
307 image: arm32v7/elixir:1.10.3-alpine
308 cache: *release-cache
309 variables: *release-variables
310 before_script: *before-release-musl
311 script: *release
312
313 arm64:
314 stage: release
315 artifacts: *release-artifacts
316 only: *release-only
317 tags:
318 - arm
319 image: arm64v8/elixir:1.10.3
320 cache: *release-cache
321 variables: *release-variables
322 before_script: *before-release
323 script: *release
324
325 arm64-musl:
326 stage: release
327 artifacts: *release-artifacts
328 only: *release-only
329 tags:
330 - arm
331 image: arm64v8/elixir:1.10.3-alpine
332 cache: *release-cache
333 variables: *release-variables
334 before_script: *before-release-musl
335 script: *release
336
337 docker:
338 stage: docker
339 image: docker:latest
340 cache: {}
341 dependencies: []
342 variables: &docker-variables
343 DOCKER_DRIVER: overlay2
344 DOCKER_HOST: unix:///var/run/docker.sock
345 IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
346 IMAGE_TAG_SLUG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
347 IMAGE_TAG_LATEST: $CI_REGISTRY_IMAGE:latest
348 IMAGE_TAG_LATEST_STABLE: $CI_REGISTRY_IMAGE:latest-stable
349 DOCKER_BUILDX_URL: https://github.com/docker/buildx/releases/download/v0.4.1/buildx-v0.4.1.linux-amd64
350 DOCKER_BUILDX_HASH: 71a7d01439aa8c165a25b59c44d3f016fddbd98b
351 before_script: &before-docker
352 - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
353 - docker pull $IMAGE_TAG_SLUG || true
354 - export CI_JOB_TIMESTAMP=$(date --utc -Iseconds)
355 - export CI_VCS_REF=$CI_COMMIT_SHORT_SHA
356 allow_failure: true
357 script:
358 - mkdir -p /root/.docker/cli-plugins
359 - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
360 - echo "${DOCKER_BUILDX_HASH} /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
361 - chmod +x ~/.docker/cli-plugins/docker-buildx
362 - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
363 - docker buildx create --name mbuilder --driver docker-container --use
364 - docker buildx inspect --bootstrap
365 - 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 .
366 tags:
367 - dind
368 only:
369 - develop@pleroma/pleroma
370
371 docker-stable:
372 stage: docker
373 image: docker:latest
374 cache: {}
375 dependencies: []
376 variables: *docker-variables
377 before_script: *before-docker
378 allow_failure: true
379 script:
380 - mkdir -p /root/.docker/cli-plugins
381 - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
382 - echo "${DOCKER_BUILDX_HASH} /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
383 - chmod +x ~/.docker/cli-plugins/docker-buildx
384 - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
385 - docker buildx create --name mbuilder --driver docker-container --use
386 - docker buildx inspect --bootstrap
387 - 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 .
388 tags:
389 - dind
390 only:
391 - stable@pleroma/pleroma
392
393 docker-release:
394 stage: docker
395 image: docker:latest
396 cache: {}
397 dependencies: []
398 variables: *docker-variables
399 before_script: *before-docker
400 allow_failure: true
401 script:
402 script:
403 - mkdir -p /root/.docker/cli-plugins
404 - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
405 - echo "${DOCKER_BUILDX_HASH} /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
406 - chmod +x ~/.docker/cli-plugins/docker-buildx
407 - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
408 - docker buildx create --name mbuilder --driver docker-container --use
409 - docker buildx inspect --bootstrap
410 - 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 .
411 tags:
412 - dind
413 only:
414 - /^release/.*$/@pleroma/pleroma
415
416 docker-adhoc:
417 stage: docker
418 image: docker:latest
419 cache: {}
420 dependencies: []
421 variables: *docker-variables
422 before_script: *before-docker
423 allow_failure: true
424 script:
425 script:
426 - mkdir -p /root/.docker/cli-plugins
427 - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
428 - echo "${DOCKER_BUILDX_HASH} /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
429 - chmod +x ~/.docker/cli-plugins/docker-buildx
430 - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
431 - docker buildx create --name mbuilder --driver docker-container --use
432 - docker buildx inspect --bootstrap
433 - 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 .
434 tags:
435 - dind
436 only:
437 - /^build-docker/.*$/@pleroma/pleroma