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