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