Merge branch 'cluster-test-ci' 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: ${CI_COMMIT_REF_SLUG}
12 paths:
13 - deps
14 - _build
15
16 stages:
17 - build
18 - test
19 - benchmark
20 - deploy
21 - release
22 - docker
23
24 before_script:
25 - mix local.hex --force
26 - mix local.rebar --force
27
28 build:
29 stage: build
30 script:
31 - mix deps.get
32 - mix compile --force
33
34 benchmark:
35 stage: benchmark
36 when: manual
37 variables:
38 MIX_ENV: benchmark
39 services:
40 - name: postgres:9.6
41 alias: postgres
42 command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
43 script:
44 - mix deps.get
45 - mix ecto.create
46 - mix ecto.migrate
47 - mix pleroma.load_testing
48
49 unit-testing:
50 stage: test
51 retry: 2
52 cache: &testing_cache_policy
53 <<: *global_cache_policy
54 policy: pull
55
56 services:
57 - name: postgres:9.6
58 alias: postgres
59 command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
60 script:
61 - mix deps.get
62 - mix ecto.create
63 - mix ecto.migrate
64 - mix coveralls --preload-modules
65
66 federated-testing:
67 stage: test
68 cache: *testing_cache_policy
69 services:
70 - name: minibikini/postgres-with-rum:12
71 alias: postgres
72 command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
73 script:
74 - mix deps.get
75 - mix ecto.create
76 - mix ecto.migrate
77 - epmd -daemon
78 - mix test --trace --only federated
79
80 unit-testing-rum:
81 stage: test
82 retry: 2
83 cache: *testing_cache_policy
84 services:
85 - name: minibikini/postgres-with-rum:12
86 alias: postgres
87 command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
88 variables:
89 <<: *global_variables
90 RUM_ENABLED: "true"
91 script:
92 - mix deps.get
93 - mix ecto.create
94 - mix ecto.migrate
95 - "mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/"
96 - mix test --preload-modules
97
98 lint:
99 stage: test
100 cache: *testing_cache_policy
101 script:
102 - mix format --check-formatted
103
104 analysis:
105 stage: test
106 cache: *testing_cache_policy
107 script:
108 - mix deps.get
109 - mix credo --strict --only=warnings,todo,fixme,consistency,readability
110
111 docs-deploy:
112 stage: deploy
113 cache: *testing_cache_policy
114 image: alpine:latest
115 only:
116 - stable@pleroma/pleroma
117 - develop@pleroma/pleroma
118 before_script:
119 - apk add curl
120 script:
121 - 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
122 review_app:
123 image: alpine:3.9
124 stage: deploy
125 before_script:
126 - apk update && apk add openssh-client git
127 when: manual
128 environment:
129 name: review/$CI_COMMIT_REF_NAME
130 url: https://$CI_ENVIRONMENT_SLUG.pleroma.online/
131 on_stop: stop_review_app
132 only:
133 - branches
134 except:
135 - master
136 - develop
137 script:
138 - echo "$CI_ENVIRONMENT_SLUG"
139 - mkdir -p ~/.ssh
140 - eval $(ssh-agent -s)
141 - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
142 - ssh-keyscan -H "pleroma.online" >> ~/.ssh/known_hosts
143 - (ssh -t dokku@pleroma.online -- apps:create "$CI_ENVIRONMENT_SLUG") || true
144 - (ssh -t dokku@pleroma.online -- git:set "$CI_ENVIRONMENT_SLUG" keep-git-dir true) || true
145 - 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
146 - (ssh -t dokku@pleroma.online -- postgres:create $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db) || true
147 - (ssh -t dokku@pleroma.online -- postgres:link $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db "$CI_ENVIRONMENT_SLUG") || true
148 - (ssh -t dokku@pleroma.online -- certs:add "$CI_ENVIRONMENT_SLUG" /home/dokku/server.crt /home/dokku/server.key) || true
149 - git push -f dokku@pleroma.online:$CI_ENVIRONMENT_SLUG $CI_COMMIT_SHA:refs/heads/master
150
151 stop_review_app:
152 image: alpine:3.9
153 stage: deploy
154 before_script:
155 - apk update && apk add openssh-client git
156 when: manual
157 environment:
158 name: review/$CI_COMMIT_REF_NAME
159 action: stop
160 script:
161 - echo "$CI_ENVIRONMENT_SLUG"
162 - mkdir -p ~/.ssh
163 - eval $(ssh-agent -s)
164 - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
165 - ssh-keyscan -H "pleroma.online" >> ~/.ssh/known_hosts
166 - ssh -t dokku@pleroma.online -- --force apps:destroy "$CI_ENVIRONMENT_SLUG"
167 - ssh -t dokku@pleroma.online -- --force postgres:destroy $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db
168
169 amd64:
170 stage: release
171 image: elixir:1.10.3
172 only: &release-only
173 - stable@pleroma/pleroma
174 - develop@pleroma/pleroma
175 - /^maint/.*$/@pleroma/pleroma
176 - /^release/.*$/@pleroma/pleroma
177 artifacts: &release-artifacts
178 name: "pleroma-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
179 paths:
180 - release/*
181 # Ideally it would be never for master branch and with the next commit for develop,
182 # but Gitlab does not support neither `only` for artifacts
183 # nor setting it to never from .gitlab-ci.yml
184 # nor expiring with the next commit
185 expire_in: 42 yrs
186
187 cache: &release-cache
188 key: $CI_COMMIT_REF_NAME-$CI_JOB_NAME
189 paths:
190 - deps
191 variables: &release-variables
192 MIX_ENV: prod
193 before_script: &before-release
194 - echo "import Mix.Config" > config/prod.secret.exs
195 - mix local.hex --force
196 - mix local.rebar --force
197 script: &release
198 - mix deps.get --only prod
199 - mkdir release
200 - export PLEROMA_BUILD_BRANCH=$CI_COMMIT_REF_NAME
201 - mix release --path release
202
203
204 amd64-musl:
205 stage: release
206 artifacts: *release-artifacts
207 only: *release-only
208 image: elixir:1.10.3-alpine
209 cache: *release-cache
210 variables: *release-variables
211 before_script: &before-release-musl
212 - apk add git gcc g++ musl-dev make
213 - echo "import Mix.Config" > config/prod.secret.exs
214 - mix local.hex --force
215 - mix local.rebar --force
216 script: *release
217
218 arm:
219 stage: release
220 artifacts: *release-artifacts
221 only: *release-only
222 tags:
223 - arm32
224 image: elixir:1.10.3
225 cache: *release-cache
226 variables: *release-variables
227 before_script: *before-release
228 script: *release
229
230 arm-musl:
231 stage: release
232 artifacts: *release-artifacts
233 only: *release-only
234 tags:
235 - arm32
236 image: elixir:1.10.3-alpine
237 cache: *release-cache
238 variables: *release-variables
239 before_script: *before-release-musl
240 script: *release
241
242 arm64:
243 stage: release
244 artifacts: *release-artifacts
245 only: *release-only
246 tags:
247 - arm
248 image: elixir:1.10.3
249 cache: *release-cache
250 variables: *release-variables
251 before_script: *before-release
252 script: *release
253
254 arm64-musl:
255 stage: release
256 artifacts: *release-artifacts
257 only: *release-only
258 tags:
259 - arm
260 # TODO: Replace with upstream image when 1.9.0 comes out
261 image: elixir:1.10.3-alpine
262 cache: *release-cache
263 variables: *release-variables
264 before_script: *before-release-musl
265 script: *release
266
267 docker:
268 stage: docker
269 image: docker:latest
270 cache: {}
271 dependencies: []
272 variables: &docker-variables
273 DOCKER_DRIVER: overlay2
274 DOCKER_HOST: unix:///var/run/docker.sock
275 IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
276 IMAGE_TAG_SLUG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
277 IMAGE_TAG_LATEST: $CI_REGISTRY_IMAGE:latest
278 IMAGE_TAG_LATEST_STABLE: $CI_REGISTRY_IMAGE:latest-stable
279 before_script: &before-docker
280 - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
281 - docker pull $IMAGE_TAG_SLUG || true
282 - export CI_JOB_TIMESTAMP=$(date --utc -Iseconds)
283 - export CI_VCS_REF=$CI_COMMIT_SHORT_SHA
284 allow_failure: true
285 script:
286 - docker build --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 .
287 - docker push $IMAGE_TAG
288 - docker push $IMAGE_TAG_SLUG
289 - docker push $IMAGE_TAG_LATEST
290 tags:
291 - dind
292 only:
293 - develop@pleroma/pleroma
294
295 docker-stable:
296 stage: docker
297 image: docker:latest
298 cache: {}
299 dependencies: []
300 variables: *docker-variables
301 before_script: *before-docker
302 allow_failure: true
303 script:
304 - docker build --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 .
305 - docker push $IMAGE_TAG
306 - docker push $IMAGE_TAG_SLUG
307 - docker push $IMAGE_TAG_LATEST_STABLE
308 tags:
309 - dind
310 only:
311 - stable@pleroma/pleroma
312
313 docker-release:
314 stage: docker
315 image: docker:latest
316 cache: {}
317 dependencies: []
318 variables: *docker-variables
319 before_script: *before-docker
320 allow_failure: true
321 script:
322 - docker build --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 .
323 - docker push $IMAGE_TAG
324 - docker push $IMAGE_TAG_SLUG
325 tags:
326 - dind
327 only:
328 - /^release/.*$/@pleroma/pleroma