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