.gitlab-ci.yml 12.2 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

37 38 39 40 41 42 43 44
spec-build:
  stage: test
  artifacts:
    paths:
    - spec.json
  script:
  - mix pleroma.openapi_spec spec.json

lain's avatar
lain committed
45 46
benchmark:
  stage: benchmark
lain's avatar
lain committed
47
  when: manual
lain's avatar
lain committed
48 49 50
  variables:
    MIX_ENV: benchmark
  services:
51
  - name: postgres:9.6
lain's avatar
lain committed
52 53 54 55 56 57
    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
58
    - mix pleroma.load_testing
rinpatch's avatar
rinpatch committed
59

60 61
unit-testing:
  stage: test
62
  retry: 2
63 64 65 66
  cache: &testing_cache_policy
    <<: *global_cache_policy
    policy: pull

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

Steven Fuchs's avatar
Steven Fuchs committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
# 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
93

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

113 114
lint:
  stage: test
115
  cache: *testing_cache_policy
116 117 118 119 120
  script:
    - mix format --check-formatted

analysis:
  stage: test
121
  cache: *testing_cache_policy
122
  script:
rinpatch's avatar
rinpatch committed
123
    - mix deps.get
124 125
    - mix credo --strict --only=warnings,todo,fixme,consistency,readability

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

166 167
spec-deploy:
  stage: deploy
168 169 170
  artifacts:
    paths:
    - spec.json
171 172 173 174 175 176
  only:
    - develop@pleroma/pleroma
  image: alpine:latest
  before_script:
    - apk add curl
  script:
rinpatch's avatar
rinpatch committed
177
    - 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
178 179
  
 
lain's avatar
lain committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
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
197 198

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


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

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

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

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

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

docker-stable:
  stage: docker
  image: docker:latest
  cache: {}
334
  dependencies: []
335 336
  variables: *docker-variables
  before_script: *before-docker
jp's avatar
jp committed
337
  allow_failure: true
338
  script:
339
    - 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 -t $IMAGE_TAG_LATEST_STABLE .
347 348 349
  tags:
    - dind
  only:
350
    - stable@pleroma/pleroma
351 352 353 354 355 356 357 358 359 360

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

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