.gitlab-ci.yml 12.6 KB
Newer Older
1
image: elixir:1.9.4
lain's avatar
lain committed
2

3
variables: &global_variables
lain's avatar
lain committed
4
  POSTGRES_DB: pleroma_test
Roger Braun's avatar
Roger Braun committed
5
6
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: postgres
lain's avatar
lain committed
7
  DB_HOST: postgres
8
  MIX_ENV: test
9

10
cache: &global_cache_policy
11
12
13
  key:
    files:
      - mix.lock
rinpatch's avatar
rinpatch committed
14
  paths:
15
16
17
    - deps
    - _build

lain's avatar
lain committed
18
stages:
19
  - build
lain's avatar
lain committed
20
  - test
lain's avatar
lain committed
21
  - benchmark
22
  - deploy
rinpatch's avatar
rinpatch committed
23
  - release
24
  - docker
lain's avatar
lain committed
25
26

before_script:
27
  - rm -rf _build/*/lib/pleroma
28
  - apt-get update && apt-get install -y cmake
lain's avatar
lain committed
29
30
  - mix local.hex --force
  - mix local.rebar --force
31
  - mix deps.get
href's avatar
href committed
32
33
  - apt-get -qq update
  - apt-get install -y libmagic-dev
lain's avatar
lain committed
34

35
36
37
after_script:
  - rm -rf _build/*/lib/pleroma

38
39
build:
  stage: build
40
41
42
43
44
  only:
    changes:
      - "**/*.ex"
      - "**/*.exs"
      - "mix.lock"
lain's avatar
lain committed
45
  script:
46
  - mix compile --force
rinpatch's avatar
rinpatch committed
47

48
49
spec-build:
  stage: test
50
51
52
53
  only:
    changes:
      - "lib/pleroma/web/api_spec/**/*.ex"
      - "lib/pleroma/web/api_spec.ex"
54
55
56
57
58
59
  artifacts:
    paths:
    - spec.json
  script:
  - mix pleroma.openapi_spec spec.json

lain's avatar
lain committed
60
61
benchmark:
  stage: benchmark
lain's avatar
lain committed
62
  when: manual
lain's avatar
lain committed
63
64
65
  variables:
    MIX_ENV: benchmark
  services:
66
  - name: postgres:9.6
lain's avatar
lain committed
67
68
69
70
71
    alias: postgres
    command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
  script:
    - mix ecto.create
    - mix ecto.migrate
lain's avatar
lain committed
72
    - mix pleroma.load_testing
rinpatch's avatar
rinpatch committed
73

74
75
unit-testing:
  stage: test
76
77
78
79
80
  only:
    changes:
      - "**/*.ex"
      - "**/*.exs"
      - "mix.lock"
81
  retry: 2
82
83
84
85
  cache: &testing_cache_policy
    <<: *global_cache_policy
    policy: pull

86
  services:
lain's avatar
lain committed
87
  - name: postgres:13
88
    alias: postgres
89
90
    command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
  script:
lain's avatar
lain committed
91
    - apt-get update && apt-get install -y libimage-exiftool-perl ffmpeg
92
93
    - mix ecto.create
    - mix ecto.migrate
rinpatch's avatar
rinpatch committed
94
    - mix coveralls --preload-modules
95

Steven Fuchs's avatar
Steven Fuchs committed
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Removed to fix CI issue. In this early state it wasn't adding much value anyway.
# TODO Fix and reinstate federated testing
# federated-testing:
#   stage: test
#   cache: *testing_cache_policy
#   services:
#   - name: minibikini/postgres-with-rum:12
#     alias: postgres
#     command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
#   script:
#     - mix deps.get
#     - mix ecto.create
#     - mix ecto.migrate
#     - epmd -daemon
#     - mix test --trace --only federated
111

lain's avatar
lain committed
112
unit-testing-rum:
113
  stage: test
114
115
116
117
118
  only:
    changes:
      - "**/*.ex"
      - "**/*.exs"
      - "mix.lock"
119
  retry: 2
120
  cache: *testing_cache_policy
lain's avatar
lain committed
121
  services:
122
  - name: minibikini/postgres-with-rum:12
123
    alias: postgres
lain's avatar
lain committed
124
    command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
125
  variables:
126
    <<: *global_variables
127
    RUM_ENABLED: "true"
lain's avatar
lain committed
128
  script:
lain's avatar
lain committed
129
    - apt-get update && apt-get install -y libimage-exiftool-perl ffmpeg
lain's avatar
lain committed
130
131
132
    - mix ecto.create
    - mix ecto.migrate
    - "mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/"
rinpatch's avatar
rinpatch committed
133
    - mix test --preload-modules
lain's avatar
lain committed
134

135
136
lint:
  stage: test
137
138
139
140
141
  only:
    changes:
      - "**/*.ex"
      - "**/*.exs"
      - "mix.lock"
142
  cache: *testing_cache_policy
143
144
145
146
147
  script:
    - mix format --check-formatted

analysis:
  stage: test
148
149
150
151
152
  only:
    changes:
      - "**/*.ex"
      - "**/*.exs"
      - "mix.lock"
153
  cache: *testing_cache_policy
154
155
156
  script:
    - mix credo --strict --only=warnings,todo,fixme,consistency,readability

157
docs-deploy:
158
  stage: deploy
159
  cache: *testing_cache_policy
160
  image: alpine:latest
rinpatch's avatar
rinpatch committed
161
  only:
162
  - stable@pleroma/pleroma
rinpatch's avatar
rinpatch committed
163
164
  - develop@pleroma/pleroma
  before_script:
165
  - apk add curl
rinpatch's avatar
rinpatch committed
166
  script:
167
  - 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
lain's avatar
lain committed
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
review_app:
  image: alpine:3.9
  stage: deploy
  before_script:
    - apk update && apk add openssh-client git
  when: manual
  environment:
    name: review/$CI_COMMIT_REF_NAME
    url: https://$CI_ENVIRONMENT_SLUG.pleroma.online/
    on_stop: stop_review_app
  only:
    - branches
  except:
    - master
    - develop
  script:
    - echo "$CI_ENVIRONMENT_SLUG"
    - mkdir -p ~/.ssh
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - ssh-keyscan -H "pleroma.online" >> ~/.ssh/known_hosts
    - (ssh -t dokku@pleroma.online -- apps:create "$CI_ENVIRONMENT_SLUG") || true
190
    - (ssh -t dokku@pleroma.online -- git:set "$CI_ENVIRONMENT_SLUG" keep-git-dir true) || true
lain's avatar
lain committed
191
192
193
194
    - 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
    - (ssh -t dokku@pleroma.online -- postgres:create $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db) || true
    - (ssh -t dokku@pleroma.online -- postgres:link $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db "$CI_ENVIRONMENT_SLUG") || true
    - (ssh -t dokku@pleroma.online -- certs:add "$CI_ENVIRONMENT_SLUG" /home/dokku/server.crt /home/dokku/server.key) || true
lain's avatar
lain committed
195
    - git push -f dokku@pleroma.online:$CI_ENVIRONMENT_SLUG $CI_COMMIT_SHA:refs/heads/master
lain's avatar
lain committed
196

197
198
spec-deploy:
  stage: deploy
199
200
201
  artifacts:
    paths:
    - spec.json
202
203
204
205
206
207
  only:
    - develop@pleroma/pleroma
  image: alpine:latest
  before_script:
    - apk add curl
  script:
rinpatch's avatar
rinpatch committed
208
    - 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
209
210


lain's avatar
lain committed
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
stop_review_app:
  image: alpine:3.9
  stage: deploy
  before_script:
    - apk update && apk add openssh-client git
  when: manual
  environment:
    name: review/$CI_COMMIT_REF_NAME
    action: stop
  script:
    - echo "$CI_ENVIRONMENT_SLUG"
    - mkdir -p ~/.ssh
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
    - ssh-keyscan -H "pleroma.online" >> ~/.ssh/known_hosts
    - ssh -t dokku@pleroma.online -- --force apps:destroy "$CI_ENVIRONMENT_SLUG"
    - ssh -t dokku@pleroma.online -- --force postgres:destroy $(echo $CI_ENVIRONMENT_SLUG | sed -e 's/-/_/g')_db
rinpatch's avatar
rinpatch committed
228
229

amd64:
230
  stage: release
231
  image: elixir:1.10.3
rinpatch's avatar
rinpatch committed
232
  only: &release-only
233
  - stable@pleroma/pleroma
rinpatch's avatar
rinpatch committed
234
  - develop@pleroma/pleroma
235
  - /^maint/.*$/@pleroma/pleroma
236
  - /^release/.*$/@pleroma/pleroma
rinpatch's avatar
rinpatch committed
237
238
239
240
  artifacts: &release-artifacts
    name: "pleroma-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
    paths:
      - release/*
rinpatch's avatar
rinpatch committed
241
242
243
244
245
246
    # Ideally it would be never for master branch and with the next commit for develop,
    # but Gitlab does not support neither `only` for artifacts
    # nor setting it to never from .gitlab-ci.yml
    # nor expiring with the next commit
    expire_in: 42 yrs

rinpatch's avatar
rinpatch committed
247
248
249
250
251
252
253
  cache: &release-cache
    key: $CI_COMMIT_REF_NAME-$CI_JOB_NAME
    paths:
          - deps
  variables: &release-variables
    MIX_ENV: prod
  before_script: &before-release
254
  - apt-get update && apt-get install -y cmake libmagic-dev
rinpatch's avatar
rinpatch committed
255
256
257
258
259
260
  - echo "import Mix.Config" > config/prod.secret.exs
  - mix local.hex --force
  - mix local.rebar --force
  script: &release
    - mix deps.get --only prod
    - mkdir release
rinpatch's avatar
rinpatch committed
261
    - export PLEROMA_BUILD_BRANCH=$CI_COMMIT_REF_NAME
rinpatch's avatar
rinpatch committed
262
263
264
265
266
267
268
    - mix release --path release


amd64-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
269
  image: elixir:1.10.3-alpine
rinpatch's avatar
rinpatch committed
270
271
272
  cache: *release-cache
  variables: *release-variables
  before_script: &before-release-musl
273
  - apk add git gcc g++ musl-dev make cmake file-dev
rinpatch's avatar
rinpatch committed
274
275
276
277
278
279
280
281
282
283
  - echo "import Mix.Config" > config/prod.secret.exs
  - mix local.hex --force
  - mix local.rebar --force
  script: *release

arm:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
284
    - arm32-specified
285
  image: arm32v7/elixir:1.10.3
rinpatch's avatar
rinpatch committed
286
287
288
289
290
291
292
293
294
295
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release
  script: *release

arm-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
296
    - arm32-specified
lain's avatar
lain committed
297
  image: arm32v7/elixir:1.10.3-alpine
rinpatch's avatar
rinpatch committed
298
299
300
301
302
303
304
305
306
307
308
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release-musl
  script: *release

arm64:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm
309
  image: arm64v8/elixir:1.10.3
rinpatch's avatar
rinpatch committed
310
311
312
313
314
315
316
317
318
319
320
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release
  script: *release

arm64-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm
321
  image: arm64v8/elixir:1.10.3-alpine
rinpatch's avatar
rinpatch committed
322
323
324
325
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release-musl
  script: *release
326
327
328
329

docker:
  stage: docker
  image: docker:latest
330
  cache: {}
331
  dependencies: []
332
333
334
335
336
337
338
  variables: &docker-variables
    DOCKER_DRIVER: overlay2
    DOCKER_HOST: unix:///var/run/docker.sock
    IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
    IMAGE_TAG_SLUG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
    IMAGE_TAG_LATEST: $CI_REGISTRY_IMAGE:latest
    IMAGE_TAG_LATEST_STABLE: $CI_REGISTRY_IMAGE:latest-stable
339
340
    DOCKER_BUILDX_URL: https://github.com/docker/buildx/releases/download/v0.4.1/buildx-v0.4.1.linux-amd64
    DOCKER_BUILDX_HASH: 71a7d01439aa8c165a25b59c44d3f016fddbd98b
341
342
  before_script: &before-docker
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
343
    - docker pull $IMAGE_TAG_SLUG || true
344
345
    - export CI_JOB_TIMESTAMP=$(date --utc -Iseconds)
    - export CI_VCS_REF=$CI_COMMIT_SHORT_SHA
jp's avatar
jp committed
346
  allow_failure: true
347
  script:
348
    - mkdir -p /root/.docker/cli-plugins
349
350
    - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
    - echo "${DOCKER_BUILDX_HASH}  /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
351
352
353
354
    - chmod +x ~/.docker/cli-plugins/docker-buildx
    - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
    - docker buildx create --name mbuilder --driver docker-container --use
    - docker buildx inspect --bootstrap
355
    - 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 .
356
357
  tags:
    - dind
358
  only:
359
    - develop@pleroma/pleroma
360
361
362
363
364

docker-stable:
  stage: docker
  image: docker:latest
  cache: {}
365
  dependencies: []
366
367
  variables: *docker-variables
  before_script: *before-docker
jp's avatar
jp committed
368
  allow_failure: true
369
  script:
370
    - mkdir -p /root/.docker/cli-plugins
371
372
    - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
    - echo "${DOCKER_BUILDX_HASH}  /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
373
374
375
376
    - chmod +x ~/.docker/cli-plugins/docker-buildx
    - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
    - docker buildx create --name mbuilder --driver docker-container --use
    - docker buildx inspect --bootstrap
377
    - 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 .
378
379
380
  tags:
    - dind
  only:
381
    - stable@pleroma/pleroma
382
383
384
385
386
387
388
389
390
391

docker-release:
  stage: docker
  image: docker:latest
  cache: {}
  dependencies: []
  variables: *docker-variables
  before_script: *before-docker
  allow_failure: true
  script:
392
393
  script:
    - mkdir -p /root/.docker/cli-plugins
394
395
    - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
    - echo "${DOCKER_BUILDX_HASH}  /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
396
397
398
399
    - chmod +x ~/.docker/cli-plugins/docker-buildx
    - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
    - docker buildx create --name mbuilder --driver docker-container --use
    - docker buildx inspect --bootstrap
400
    - 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 .
401
402
403
  tags:
    - dind
  only:
404
    - /^release/.*$/@pleroma/pleroma
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426

docker-adhoc:
  stage: docker
  image: docker:latest
  cache: {}
  dependencies: []
  variables: *docker-variables
  before_script: *before-docker
  allow_failure: true
  script:
  script:
    - mkdir -p /root/.docker/cli-plugins
    - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
    - echo "${DOCKER_BUILDX_HASH}  /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
    - chmod +x ~/.docker/cli-plugins/docker-buildx
    - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
    - docker buildx create --name mbuilder --driver docker-container --use
    - docker buildx inspect --bootstrap
    - 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 .
  tags:
    - dind
  only:
427
    - /^build-docker/.*$/@pleroma/pleroma