.gitlab-ci.yml 12.2 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
lain's avatar
lain committed
40
  script:
41
  - mix compile --force
rinpatch's avatar
rinpatch committed
42

43
44
45
46
47
48
49
50
spec-build:
  stage: test
  artifacts:
    paths:
    - spec.json
  script:
  - mix pleroma.openapi_spec spec.json

lain's avatar
lain committed
51
52
benchmark:
  stage: benchmark
lain's avatar
lain committed
53
  when: manual
lain's avatar
lain committed
54
55
56
  variables:
    MIX_ENV: benchmark
  services:
57
  - name: postgres:9.6
lain's avatar
lain committed
58
59
60
61
62
    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
63
    - mix pleroma.load_testing
rinpatch's avatar
rinpatch committed
64

65
66
unit-testing:
  stage: test
67
  retry: 2
68
69
70
71
  cache: &testing_cache_policy
    <<: *global_cache_policy
    policy: pull

72
  services:
lain's avatar
lain committed
73
  - name: postgres:13
74
    alias: postgres
75
76
    command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
  script:
lain's avatar
lain committed
77
    - apt-get update && apt-get install -y libimage-exiftool-perl ffmpeg
78
79
    - mix ecto.create
    - mix ecto.migrate
rinpatch's avatar
rinpatch committed
80
    - mix coveralls --preload-modules
81

Steven Fuchs's avatar
Steven Fuchs committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 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
97

lain's avatar
lain committed
98
unit-testing-rum:
99
  stage: test
100
  retry: 2
101
  cache: *testing_cache_policy
lain's avatar
lain committed
102
  services:
103
  - name: minibikini/postgres-with-rum:12
104
    alias: postgres
lain's avatar
lain committed
105
    command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
106
  variables:
107
    <<: *global_variables
108
    RUM_ENABLED: "true"
lain's avatar
lain committed
109
  script:
lain's avatar
lain committed
110
    - apt-get update && apt-get install -y libimage-exiftool-perl ffmpeg
lain's avatar
lain committed
111
112
113
    - mix ecto.create
    - mix ecto.migrate
    - "mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/"
rinpatch's avatar
rinpatch committed
114
    - mix test --preload-modules
lain's avatar
lain committed
115

116
117
lint:
  stage: test
118
  cache: *testing_cache_policy
119
120
121
122
123
  script:
    - mix format --check-formatted

analysis:
  stage: test
124
  cache: *testing_cache_policy
125
126
127
  script:
    - mix credo --strict --only=warnings,todo,fixme,consistency,readability

128
docs-deploy:
129
  stage: deploy
130
  cache: *testing_cache_policy
131
  image: alpine:latest
rinpatch's avatar
rinpatch committed
132
  only:
133
  - stable@pleroma/pleroma
rinpatch's avatar
rinpatch committed
134
135
  - develop@pleroma/pleroma
  before_script:
136
  - apk add curl
rinpatch's avatar
rinpatch committed
137
  script:
138
  - 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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
161
    - (ssh -t dokku@pleroma.online -- git:set "$CI_ENVIRONMENT_SLUG" keep-git-dir true) || true
lain's avatar
lain committed
162
163
164
165
    - 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
166
    - git push -f dokku@pleroma.online:$CI_ENVIRONMENT_SLUG $CI_COMMIT_SHA:refs/heads/master
lain's avatar
lain committed
167

168
169
spec-deploy:
  stage: deploy
170
171
172
  artifacts:
    paths:
    - spec.json
173
174
175
176
177
178
  only:
    - develop@pleroma/pleroma
  image: alpine:latest
  before_script:
    - apk add curl
  script:
rinpatch's avatar
rinpatch committed
179
    - 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
180
181


lain's avatar
lain committed
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
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
199
200

amd64:
201
  stage: release
202
  image: elixir:1.10.3
rinpatch's avatar
rinpatch committed
203
  only: &release-only
204
  - stable@pleroma/pleroma
rinpatch's avatar
rinpatch committed
205
  - develop@pleroma/pleroma
206
  - /^maint/.*$/@pleroma/pleroma
207
  - /^release/.*$/@pleroma/pleroma
rinpatch's avatar
rinpatch committed
208
209
210
211
  artifacts: &release-artifacts
    name: "pleroma-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
    paths:
      - release/*
rinpatch's avatar
rinpatch committed
212
213
214
215
216
217
    # 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
218
219
220
221
222
223
224
  cache: &release-cache
    key: $CI_COMMIT_REF_NAME-$CI_JOB_NAME
    paths:
          - deps
  variables: &release-variables
    MIX_ENV: prod
  before_script: &before-release
225
  - apt-get update && apt-get install -y cmake libmagic-dev
rinpatch's avatar
rinpatch committed
226
227
228
229
230
231
  - 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
232
    - export PLEROMA_BUILD_BRANCH=$CI_COMMIT_REF_NAME
rinpatch's avatar
rinpatch committed
233
234
235
236
237
238
239
    - mix release --path release


amd64-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
240
  image: elixir:1.10.3-alpine
rinpatch's avatar
rinpatch committed
241
242
243
  cache: *release-cache
  variables: *release-variables
  before_script: &before-release-musl
244
  - apk add git gcc g++ musl-dev make cmake file-dev
rinpatch's avatar
rinpatch committed
245
246
247
248
249
250
251
252
253
254
  - 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:
255
    - arm32-specified
256
  image: arm32v7/elixir:1.10.3
rinpatch's avatar
rinpatch committed
257
258
259
260
261
262
263
264
265
266
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release
  script: *release

arm-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
267
    - arm32-specified
lain's avatar
lain committed
268
  image: arm32v7/elixir:1.10.3-alpine
rinpatch's avatar
rinpatch committed
269
270
271
272
273
274
275
276
277
278
279
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release-musl
  script: *release

arm64:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm
280
  image: arm64v8/elixir:1.10.3
rinpatch's avatar
rinpatch committed
281
282
283
284
285
286
287
288
289
290
291
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release
  script: *release

arm64-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm
292
  image: arm64v8/elixir:1.10.3-alpine
rinpatch's avatar
rinpatch committed
293
294
295
296
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release-musl
  script: *release
297
298
299
300

docker:
  stage: docker
  image: docker:latest
301
  cache: {}
302
  dependencies: []
303
304
305
306
307
308
309
  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
310
311
    DOCKER_BUILDX_URL: https://github.com/docker/buildx/releases/download/v0.4.1/buildx-v0.4.1.linux-amd64
    DOCKER_BUILDX_HASH: 71a7d01439aa8c165a25b59c44d3f016fddbd98b
312
313
  before_script: &before-docker
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
314
    - docker pull $IMAGE_TAG_SLUG || true
315
316
    - export CI_JOB_TIMESTAMP=$(date --utc -Iseconds)
    - export CI_VCS_REF=$CI_COMMIT_SHORT_SHA
jp's avatar
jp committed
317
  allow_failure: true
318
  script:
319
    - mkdir -p /root/.docker/cli-plugins
320
321
    - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
    - echo "${DOCKER_BUILDX_HASH}  /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
322
323
324
325
    - 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
326
    - 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 .
327
328
  tags:
    - dind
329
  only:
330
    - develop@pleroma/pleroma
331
332
333
334
335

docker-stable:
  stage: docker
  image: docker:latest
  cache: {}
336
  dependencies: []
337
338
  variables: *docker-variables
  before_script: *before-docker
jp's avatar
jp committed
339
  allow_failure: true
340
  script:
341
    - mkdir -p /root/.docker/cli-plugins
342
343
    - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
    - echo "${DOCKER_BUILDX_HASH}  /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
344
345
346
347
    - 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
348
    - 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 .
349
350
351
  tags:
    - dind
  only:
352
    - stable@pleroma/pleroma
353
354
355
356
357
358
359
360
361
362

docker-release:
  stage: docker
  image: docker:latest
  cache: {}
  dependencies: []
  variables: *docker-variables
  before_script: *before-docker
  allow_failure: true
  script:
363
364
  script:
    - mkdir -p /root/.docker/cli-plugins
365
366
    - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
    - echo "${DOCKER_BUILDX_HASH}  /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
367
368
369
370
    - 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
371
    - 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 .
372
373
374
  tags:
    - dind
  only:
375
    - /^release/.*$/@pleroma/pleroma
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397

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:
398
    - /^build-docker/.*$/@pleroma/pleroma