.gitlab-ci.yml 13 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:
Alex Gleason's avatar
Alex Gleason committed
27
  - echo $MIX_ENV
28
  - rm -rf _build/*/lib/pleroma
29
  - apt-get update && apt-get install -y cmake
lain's avatar
lain committed
30 31
  - mix local.hex --force
  - mix local.rebar --force
32
  - mix deps.get
href's avatar
href committed
33 34
  - apt-get -qq update
  - apt-get install -y libmagic-dev
lain's avatar
lain committed
35

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

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

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

lain's avatar
lain committed
61 62
benchmark:
  stage: benchmark
lain's avatar
lain committed
63
  when: manual
lain's avatar
lain committed
64 65 66
  variables:
    MIX_ENV: benchmark
  services:
67
  - name: postgres:9.6
lain's avatar
lain committed
68 69 70 71 72
    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
73
    - mix pleroma.load_testing
rinpatch's avatar
rinpatch committed
74

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

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

Steven Fuchs's avatar
Steven Fuchs committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
# 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
112

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

136
lint:
Haelwenn's avatar
Haelwenn committed
137
  image: elixir:1.12
138
  stage: test
139 140 141 142 143
  only:
    changes:
      - "**/*.ex"
      - "**/*.exs"
      - "mix.lock"
144
  cache: *testing_cache_policy
145 146 147 148 149
  script:
    - mix format --check-formatted

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

159 160 161
cycles:
  stage: test
  image: elixir:1.11
162 163 164 165 166
  only:
    changes:
      - "**/*.ex"
      - "**/*.exs"
      - "mix.lock"
Alex Gleason's avatar
Alex Gleason committed
167
  cache: {}
168 169 170 171 172
  script:
    - mix deps.get
    - mix compile
    - mix xref graph --format cycles --label compile | awk '{print $0} END{exit ($0 != "No cycles found")}'

173
docs-deploy:
174
  stage: deploy
175
  cache: *testing_cache_policy
176
  image: alpine:latest
rinpatch's avatar
rinpatch committed
177
  only:
178
  - stable@pleroma/pleroma
rinpatch's avatar
rinpatch committed
179 180
  - develop@pleroma/pleroma
  before_script:
181
  - apk add curl
rinpatch's avatar
rinpatch committed
182
  script:
183
  - 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
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
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
206
    - (ssh -t dokku@pleroma.online -- git:set "$CI_ENVIRONMENT_SLUG" keep-git-dir true) || true
lain's avatar
lain committed
207 208 209 210
    - 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
211
    - git push -f dokku@pleroma.online:$CI_ENVIRONMENT_SLUG $CI_COMMIT_SHA:refs/heads/master
lain's avatar
lain committed
212

213 214
spec-deploy:
  stage: deploy
215 216 217
  artifacts:
    paths:
    - spec.json
218 219 220 221 222 223
  only:
    - develop@pleroma/pleroma
  image: alpine:latest
  before_script:
    - apk add curl
  script:
rinpatch's avatar
rinpatch committed
224
    - 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
225 226


lain's avatar
lain committed
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
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
244 245

amd64:
246
  stage: release
247
  image: elixir:1.10.3
rinpatch's avatar
rinpatch committed
248
  only: &release-only
249
  - stable@pleroma/pleroma
rinpatch's avatar
rinpatch committed
250
  - develop@pleroma/pleroma
251
  - /^maint/.*$/@pleroma/pleroma
252
  - /^release/.*$/@pleroma/pleroma
rinpatch's avatar
rinpatch committed
253 254 255 256
  artifacts: &release-artifacts
    name: "pleroma-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
    paths:
      - release/*
rinpatch's avatar
rinpatch committed
257 258 259 260 261 262
    # 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
263 264 265 266 267 268 269
  cache: &release-cache
    key: $CI_COMMIT_REF_NAME-$CI_JOB_NAME
    paths:
          - deps
  variables: &release-variables
    MIX_ENV: prod
  before_script: &before-release
270
  - apt-get update && apt-get install -y cmake libmagic-dev
rinpatch's avatar
rinpatch committed
271 272 273 274 275 276
  - 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
277
    - export PLEROMA_BUILD_BRANCH=$CI_COMMIT_REF_NAME
rinpatch's avatar
rinpatch committed
278 279 280 281 282 283 284
    - mix release --path release


amd64-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
285
  image: elixir:1.10.3-alpine
rinpatch's avatar
rinpatch committed
286 287 288
  cache: *release-cache
  variables: *release-variables
  before_script: &before-release-musl
289
  - apk add git gcc g++ musl-dev make cmake file-dev
rinpatch's avatar
rinpatch committed
290 291 292 293 294 295 296 297 298 299
  - 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:
300
    - arm32-specified
301
  image: arm32v7/elixir:1.10.3
rinpatch's avatar
rinpatch committed
302 303 304 305 306 307 308 309 310 311
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release
  script: *release

arm-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
312
    - arm32-specified
lain's avatar
lain committed
313
  image: arm32v7/elixir:1.10.3-alpine
rinpatch's avatar
rinpatch committed
314 315 316 317 318 319 320 321 322 323 324
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release-musl
  script: *release

arm64:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm
325
  image: arm64v8/elixir:1.10.3
rinpatch's avatar
rinpatch committed
326 327 328 329 330 331 332 333 334 335 336
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release
  script: *release

arm64-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm
337
  image: arm64v8/elixir:1.10.3-alpine
rinpatch's avatar
rinpatch committed
338 339 340 341
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release-musl
  script: *release
342 343 344 345

docker:
  stage: docker
  image: docker:latest
346
  cache: {}
347
  dependencies: []
348 349 350 351 352 353 354
  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
355 356
    DOCKER_BUILDX_URL: https://github.com/docker/buildx/releases/download/v0.6.3/buildx-v0.6.3.linux-amd64
    DOCKER_BUILDX_HASH: 980e6b9655f971991fbbb5fd6cd19f1672386195
357 358
  before_script: &before-docker
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
359
    - docker pull $IMAGE_TAG_SLUG || true
360 361
    - export CI_JOB_TIMESTAMP=$(date --utc -Iseconds)
    - export CI_VCS_REF=$CI_COMMIT_SHORT_SHA
jp's avatar
jp committed
362
  allow_failure: true
363
  script:
364
    - 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 -t $IMAGE_TAG_LATEST .
372 373
  tags:
    - dind
374
  only:
375
    - develop@pleroma/pleroma
376 377 378 379 380

docker-stable:
  stage: docker
  image: docker:latest
  cache: {}
381
  dependencies: []
382 383
  variables: *docker-variables
  before_script: *before-docker
jp's avatar
jp committed
384
  allow_failure: true
385
  script:
386
    - mkdir -p /root/.docker/cli-plugins
387 388
    - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
    - echo "${DOCKER_BUILDX_HASH}  /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
389 390 391 392
    - 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
393
    - 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 .
394 395 396
  tags:
    - dind
  only:
397
    - stable@pleroma/pleroma
398 399 400 401 402 403 404 405 406 407

docker-release:
  stage: docker
  image: docker:latest
  cache: {}
  dependencies: []
  variables: *docker-variables
  before_script: *before-docker
  allow_failure: true
  script:
408 409
  script:
    - mkdir -p /root/.docker/cli-plugins
410 411
    - wget "${DOCKER_BUILDX_URL}" -O ~/.docker/cli-plugins/docker-buildx
    - echo "${DOCKER_BUILDX_HASH}  /root/.docker/cli-plugins/docker-buildx" | sha1sum -c
412 413 414 415
    - 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
416
    - 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 .
417 418 419
  tags:
    - dind
  only:
420
    - /^release/.*$/@pleroma/pleroma
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442

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