.gitlab-ci.yml 10.7 KB
Newer Older
Steven Fuchs's avatar
Steven Fuchs committed
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
  key: ${CI_COMMIT_REF_SLUG}
rinpatch's avatar
rinpatch committed
12
  paths:
13
14
15
    - deps
    - _build

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

before_script:
25
  - apt-get update && apt-get install -y cmake
lain's avatar
lain committed
26
27
  - mix local.hex --force
  - mix local.rebar --force
lain's avatar
lain committed
28

29
30
build:
  stage: build
lain's avatar
lain committed
31
  script:
rinpatch's avatar
huh    
rinpatch committed
32
  - mix deps.get
33
  - mix compile --force
rinpatch's avatar
rinpatch committed
34

lain's avatar
lain committed
35
36
benchmark:
  stage: benchmark
lain's avatar
lain committed
37
  when: manual
lain's avatar
lain committed
38
39
40
  variables:
    MIX_ENV: benchmark
  services:
41
  - name: postgres:9.6
lain's avatar
lain committed
42
43
44
45
46
47
    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
lain's avatar
lain committed
48
    - mix pleroma.load_testing
rinpatch's avatar
rinpatch committed
49

50
51
unit-testing:
  stage: test
52
  retry: 2
53
54
55
56
  cache: &testing_cache_policy
    <<: *global_cache_policy
    policy: pull

57
  services:
58
  - name: postgres:9.6
59
    alias: postgres
60
61
    command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
  script:
lain's avatar
lain committed
62
    - apt-get update && apt-get install -y libimage-exiftool-perl ffmpeg
63
    - mix deps.get
64
65
    - mix ecto.create
    - mix ecto.migrate
rinpatch's avatar
rinpatch committed
66
    - mix coveralls --preload-modules
67

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 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
83

lain's avatar
lain committed
84
unit-testing-rum:
85
  stage: test
86
  retry: 2
87
  cache: *testing_cache_policy
lain's avatar
lain committed
88
  services:
89
  - name: minibikini/postgres-with-rum:12
90
    alias: postgres
lain's avatar
lain committed
91
    command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
92
  variables:
93
    <<: *global_variables
94
    RUM_ENABLED: "true"
lain's avatar
lain committed
95
  script:
lain's avatar
lain committed
96
    - apt-get update && apt-get install -y libimage-exiftool-perl ffmpeg
lain's avatar
lain committed
97
98
99
100
    - mix deps.get
    - mix ecto.create
    - mix ecto.migrate
    - "mix ecto.migrate --migrations-path priv/repo/optional_migrations/rum_indexing/"
rinpatch's avatar
rinpatch committed
101
    - mix test --preload-modules
lain's avatar
lain committed
102

103
104
lint:
  stage: test
105
  cache: *testing_cache_policy
106
107
108
109
110
  script:
    - mix format --check-formatted

analysis:
  stage: test
111
  cache: *testing_cache_policy
112
  script:
rinpatch's avatar
rinpatch committed
113
    - mix deps.get
114
115
    - mix credo --strict --only=warnings,todo,fixme,consistency,readability

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

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
173
174

amd64:
175
  stage: release
176
  image: elixir:1.10.3
rinpatch's avatar
rinpatch committed
177
  only: &release-only
178
  - stable@pleroma/pleroma
rinpatch's avatar
rinpatch committed
179
  - develop@pleroma/pleroma
180
  - /^maint/.*$/@pleroma/pleroma
181
  - /^release/.*$/@pleroma/pleroma
rinpatch's avatar
rinpatch committed
182
183
184
185
  artifacts: &release-artifacts
    name: "pleroma-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
    paths:
      - release/*
rinpatch's avatar
rinpatch committed
186
187
188
189
190
191
    # 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
192
193
194
195
196
197
198
  cache: &release-cache
    key: $CI_COMMIT_REF_NAME-$CI_JOB_NAME
    paths:
          - deps
  variables: &release-variables
    MIX_ENV: prod
  before_script: &before-release
lain's avatar
lain committed
199
  - apt-get update && apt-get install -y cmake
rinpatch's avatar
rinpatch committed
200
201
202
203
204
205
  - 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
206
    - export PLEROMA_BUILD_BRANCH=$CI_COMMIT_REF_NAME
rinpatch's avatar
rinpatch committed
207
208
209
210
211
212
213
    - mix release --path release


amd64-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
214
  image: elixir:1.10.3-alpine 
rinpatch's avatar
rinpatch committed
215
216
217
  cache: *release-cache
  variables: *release-variables
  before_script: &before-release-musl
lain's avatar
lain committed
218
  - apk add git gcc g++ musl-dev make cmake
rinpatch's avatar
rinpatch committed
219
220
221
222
223
224
225
226
227
228
229
  - 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:
    - arm32
230
  image: elixir:1.10.3
rinpatch's avatar
rinpatch committed
231
232
233
234
235
236
237
238
239
240
241
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release
  script: *release

arm-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm32
242
  image: elixir:1.10.3-alpine
rinpatch's avatar
rinpatch committed
243
244
245
246
247
248
249
250
251
252
253
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release-musl
  script: *release

arm64:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm
254
  image: elixir:1.10.3
rinpatch's avatar
rinpatch committed
255
256
257
258
259
260
261
262
263
264
265
266
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release
  script: *release

arm64-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm
  # TODO: Replace with upstream image when 1.9.0 comes out
267
  image: elixir:1.10.3-alpine
rinpatch's avatar
rinpatch committed
268
269
270
271
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release-musl
  script: *release
272
273
274
275

docker:
  stage: docker
  image: docker:latest
276
  cache: {}
277
  dependencies: []
278
279
280
281
282
283
284
  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
285
286
    DOCKER_BUILDX_URL: https://github.com/docker/buildx/releases/download/v0.4.1/buildx-v0.4.1.linux-amd64
    DOCKER_BUILDX_HASH: 71a7d01439aa8c165a25b59c44d3f016fddbd98b
287
288
  before_script: &before-docker
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
289
    - docker pull $IMAGE_TAG_SLUG || true
290
291
    - export CI_JOB_TIMESTAMP=$(date --utc -Iseconds)
    - export CI_VCS_REF=$CI_COMMIT_SHORT_SHA
jp's avatar
jp committed
292
  allow_failure: true
293
  script:
294
    - mkdir -p /root/.docker/cli-plugins
295
296
    - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
    - echo "${DOCKER_BUILDX_HASH}  /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
297
298
299
300
    - 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
301
    - 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 .
302
303
  tags:
    - dind
304
  only:
305
    - develop@pleroma/pleroma
306
307
308
309
310

docker-stable:
  stage: docker
  image: docker:latest
  cache: {}
311
  dependencies: []
312
313
  variables: *docker-variables
  before_script: *before-docker
jp's avatar
jp committed
314
  allow_failure: true
315
  script:
316
    - mkdir -p /root/.docker/cli-plugins
317
318
    - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
    - echo "${DOCKER_BUILDX_HASH}  /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
319
320
321
322
    - 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
323
    - 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 .
324
325
326
  tags:
    - dind
  only:
327
    - stable@pleroma/pleroma
328
329
330
331
332
333
334
335
336
337

docker-release:
  stage: docker
  image: docker:latest
  cache: {}
  dependencies: []
  variables: *docker-variables
  before_script: *before-docker
  allow_failure: true
  script:
338
339
  script:
    - mkdir -p /root/.docker/cli-plugins
340
341
    - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
    - echo "${DOCKER_BUILDX_HASH}  /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
342
343
344
345
    - 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
346
    - 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 .
347
348
349
  tags:
    - dind
  only:
350
    - /^release/.*$/@pleroma/pleroma