using another fn for file deletion
[akkoma] / .gitlab-ci.yml
1 image: elixir:1.8.1
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 cache: &testing_cache_policy
52 <<: *global_cache_policy
53 policy: pull
54
55 services:
56 - name: postgres:9.6
57 alias: postgres
58 command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
59 script:
60 - mix deps.get
61 - mix ecto.create
62 - mix ecto.migrate
63 - mix coveralls --preload-modules
64
65 # Removed to fix CI issue. In this early state it wasn't adding much value anyway.
66 # TODO Fix and reinstate federated testing
67 # federated-testing:
68 # stage: test
69 # cache: *testing_cache_policy
70 # services:
71 # - name: minibikini/postgres-with-rum:12
72 # alias: postgres
73 # command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
74 # script:
75 # - mix deps.get
76 # - mix ecto.create
77 # - mix ecto.migrate
78 # - epmd -daemon
79 # - mix test --trace --only federated
80
81 unit-testing-rum:
82 stage: test
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 # TODO: Replace with upstream image when 1.9.0 comes out
172 image: rinpatch/elixir:1.9.0-rc.0
173 only: &release-only
174 - stable@pleroma/pleroma
175 - develop@pleroma/pleroma
176 - /^maint/.*$/@pleroma/pleroma
177 - /^release/.*$/@pleroma/pleroma
178 artifacts: &release-artifacts
179 name: "pleroma-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
180 paths:
181 - release/*
182 # Ideally it would be never for master branch and with the next commit for develop,
183 # but Gitlab does not support neither `only` for artifacts
184 # nor setting it to never from .gitlab-ci.yml
185 # nor expiring with the next commit
186 expire_in: 42 yrs
187
188 cache: &release-cache
189 key: $CI_COMMIT_REF_NAME-$CI_JOB_NAME
190 paths:
191 - deps
192 variables: &release-variables
193 MIX_ENV: prod
194 before_script: &before-release
195 - echo "import Mix.Config" > config/prod.secret.exs
196 - mix local.hex --force
197 - mix local.rebar --force
198 script: &release
199 - mix deps.get --only prod
200 - mkdir release
201 - export PLEROMA_BUILD_BRANCH=$CI_COMMIT_REF_NAME
202 - mix release --path release
203
204
205 amd64-musl:
206 stage: release
207 artifacts: *release-artifacts
208 only: *release-only
209 # TODO: Replace with upstream image when 1.9.0 comes out
210 image: rinpatch/elixir:1.9.0-rc.0-alpine
211 cache: *release-cache
212 variables: *release-variables
213 before_script: &before-release-musl
214 - apk add git gcc g++ musl-dev make
215 - echo "import Mix.Config" > config/prod.secret.exs
216 - mix local.hex --force
217 - mix local.rebar --force
218 script: *release
219
220 arm:
221 stage: release
222 artifacts: *release-artifacts
223 only: *release-only
224 tags:
225 - arm32
226 # TODO: Replace with upstream image when 1.9.0 comes out
227 image: rinpatch/elixir:1.9.0-rc.0-arm
228 cache: *release-cache
229 variables: *release-variables
230 before_script: *before-release
231 script: *release
232
233 arm-musl:
234 stage: release
235 artifacts: *release-artifacts
236 only: *release-only
237 tags:
238 - arm32
239 # TODO: Replace with upstream image when 1.9.0 comes out
240 image: rinpatch/elixir:1.9.0-rc.0-arm-alpine
241 cache: *release-cache
242 variables: *release-variables
243 before_script: *before-release-musl
244 script: *release
245
246 arm64:
247 stage: release
248 artifacts: *release-artifacts
249 only: *release-only
250 tags:
251 - arm
252 # TODO: Replace with upstream image when 1.9.0 comes out
253 image: rinpatch/elixir:1.9.0-rc.0-arm64
254 cache: *release-cache
255 variables: *release-variables
256 before_script: *before-release
257 script: *release
258
259 arm64-musl:
260 stage: release
261 artifacts: *release-artifacts
262 only: *release-only
263 tags:
264 - arm
265 # TODO: Replace with upstream image when 1.9.0 comes out
266 image: rinpatch/elixir:1.9.0-rc.0-arm64-alpine
267 cache: *release-cache
268 variables: *release-variables
269 before_script: *before-release-musl
270 script: *release
271
272 docker:
273 stage: docker
274 image: docker:latest
275 cache: {}
276 dependencies: []
277 variables: &docker-variables
278 DOCKER_DRIVER: overlay2
279 DOCKER_HOST: unix:///var/run/docker.sock
280 IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
281 IMAGE_TAG_SLUG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
282 IMAGE_TAG_LATEST: $CI_REGISTRY_IMAGE:latest
283 IMAGE_TAG_LATEST_STABLE: $CI_REGISTRY_IMAGE:latest-stable
284 before_script: &before-docker
285 - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
286 - docker pull $IMAGE_TAG_SLUG || true
287 - export CI_JOB_TIMESTAMP=$(date --utc -Iseconds)
288 - export CI_VCS_REF=$CI_COMMIT_SHORT_SHA
289 allow_failure: true
290 script:
291 - 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 .
292 - docker push $IMAGE_TAG
293 - docker push $IMAGE_TAG_SLUG
294 - docker push $IMAGE_TAG_LATEST
295 tags:
296 - dind
297 only:
298 - develop@pleroma/pleroma
299
300 docker-stable:
301 stage: docker
302 image: docker:latest
303 cache: {}
304 dependencies: []
305 variables: *docker-variables
306 before_script: *before-docker
307 allow_failure: true
308 script:
309 - 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 .
310 - docker push $IMAGE_TAG
311 - docker push $IMAGE_TAG_SLUG
312 - docker push $IMAGE_TAG_LATEST_STABLE
313 tags:
314 - dind
315 only:
316 - stable@pleroma/pleroma
317
318 docker-release:
319 stage: docker
320 image: docker:latest
321 cache: {}
322 dependencies: []
323 variables: *docker-variables
324 before_script: *before-docker
325 allow_failure: true
326 script:
327 - 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 .
328 - docker push $IMAGE_TAG
329 - docker push $IMAGE_TAG_SLUG
330 tags:
331 - dind
332 only:
333 - /^release/.*$/@pleroma/pleroma