.gitlab-ci.yml 10.8 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
href's avatar
href committed
28 29
  - apt-get -qq update
  - apt-get install -y libmagic-dev
lain's avatar
lain committed
30

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

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

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

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

Steven Fuchs's avatar
Steven Fuchs committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
# 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
85

lain's avatar
lain committed
86
unit-testing-rum:
87
  stage: test
88
  retry: 2
89
  cache: *testing_cache_policy
lain's avatar
lain committed
90
  services:
91
  - name: minibikini/postgres-with-rum:12
92
    alias: postgres
lain's avatar
lain committed
93
    command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
94
  variables:
95
    <<: *global_variables
96
    RUM_ENABLED: "true"
lain's avatar
lain committed
97
  script:
lain's avatar
lain committed
98
    - apt-get update && apt-get install -y libimage-exiftool-perl ffmpeg
lain's avatar
lain committed
99 100 101 102
    - 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
103
    - mix test --preload-modules
lain's avatar
lain committed
104

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

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

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

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
175 176

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


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

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

arm64:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm
256
  image: elixir:1.10.3
rinpatch's avatar
rinpatch committed
257 258 259 260 261 262 263 264 265 266 267 268
  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
269
  image: elixir:1.10.3-alpine
rinpatch's avatar
rinpatch committed
270 271 272 273
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release-musl
  script: *release
274 275 276 277

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

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

docker-release:
  stage: docker
  image: docker:latest
  cache: {}
  dependencies: []
  variables: *docker-variables
  before_script: *before-docker
  allow_failure: true
  script:
340 341
  script:
    - 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 .
349 350 351
  tags:
    - dind
  only:
352
    - /^release/.*$/@pleroma/pleroma