.gitlab-ci.yml 9.43 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:
lain's avatar
lain committed
25 26
  - mix local.hex --force
  - mix local.rebar --force
lain's avatar
lain committed
27

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

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

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

56
  services:
57
  - name: postgres:9.6
58
    alias: postgres
59 60
    command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
  script:
61
    - mix deps.get
62 63
    - mix ecto.create
    - mix ecto.migrate
rinpatch's avatar
rinpatch committed
64
    - mix coveralls --preload-modules
65

Steven Fuchs's avatar
Steven Fuchs committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
# 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
81

lain's avatar
lain committed
82
unit-testing-rum:
83
  stage: test
84
  retry: 2
85
  cache: *testing_cache_policy
lain's avatar
lain committed
86
  services:
87
  - name: minibikini/postgres-with-rum:12
88
    alias: postgres
lain's avatar
lain committed
89
    command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
90
  variables:
91
    <<: *global_variables
92
    RUM_ENABLED: "true"
lain's avatar
lain committed
93 94 95 96 97
  script:
    - 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
98
    - mix test --preload-modules
lain's avatar
lain committed
99

100 101
lint:
  stage: test
102
  cache: *testing_cache_policy
103 104 105 106 107
  script:
    - mix format --check-formatted

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

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

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
170 171

amd64:
172
  stage: release
rinpatch's avatar
rinpatch committed
173 174 175
  # TODO: Replace with upstream image when 1.9.0 comes out
  image: rinpatch/elixir:1.9.0-rc.0
  only: &release-only
176
  - stable@pleroma/pleroma
rinpatch's avatar
rinpatch committed
177
  - develop@pleroma/pleroma
178
  - /^maint/.*$/@pleroma/pleroma
179
  - /^release/.*$/@pleroma/pleroma
rinpatch's avatar
rinpatch committed
180 181 182 183
  artifacts: &release-artifacts
    name: "pleroma-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME"
    paths:
      - release/*
rinpatch's avatar
rinpatch committed
184 185 186 187 188 189
    # 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
190 191 192 193 194 195 196 197 198 199 200 201 202
  cache: &release-cache
    key: $CI_COMMIT_REF_NAME-$CI_JOB_NAME
    paths:
          - deps
  variables: &release-variables
    MIX_ENV: prod
  before_script: &before-release
  - 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
203
    - export PLEROMA_BUILD_BRANCH=$CI_COMMIT_REF_NAME
rinpatch's avatar
rinpatch committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
    - mix release --path release


amd64-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  # TODO: Replace with upstream image when 1.9.0 comes out
  image: rinpatch/elixir:1.9.0-rc.0-alpine
  cache: *release-cache
  variables: *release-variables
  before_script: &before-release-musl
  - apk add git gcc g++ musl-dev make
  - 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
  # TODO: Replace with upstream image when 1.9.0 comes out
  image: rinpatch/elixir:1.9.0-rc.0-arm
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release
  script: *release

arm-musl:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm32
  # TODO: Replace with upstream image when 1.9.0 comes out
  image: rinpatch/elixir:1.9.0-rc.0-arm-alpine
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release-musl
  script: *release

arm64:
  stage: release
  artifacts: *release-artifacts
  only: *release-only
  tags:
    - arm
  # TODO: Replace with upstream image when 1.9.0 comes out
  image: rinpatch/elixir:1.9.0-rc.0-arm64
  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
  image: rinpatch/elixir:1.9.0-rc.0-arm64-alpine
  cache: *release-cache
  variables: *release-variables
  before_script: *before-release-musl
  script: *release
273 274 275 276

docker:
  stage: docker
  image: docker:latest
277
  cache: {}
278
  dependencies: []
279 280 281 282 283 284 285
  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
286 287
  before_script: &before-docker
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
288
    - docker pull $IMAGE_TAG_SLUG || true
289 290
    - export CI_JOB_TIMESTAMP=$(date --utc -Iseconds)
    - export CI_VCS_REF=$CI_COMMIT_SHORT_SHA
jp's avatar
jp committed
291
  allow_failure: true
292
  script:
293
    - docker build --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 .
294 295 296 297 298
    - docker push $IMAGE_TAG
    - docker push $IMAGE_TAG_SLUG
    - docker push $IMAGE_TAG_LATEST
  tags:
    - dind
299
  only:
300
    - develop@pleroma/pleroma
301 302 303 304 305

docker-stable:
  stage: docker
  image: docker:latest
  cache: {}
306
  dependencies: []
307 308
  variables: *docker-variables
  before_script: *before-docker
jp's avatar
jp committed
309
  allow_failure: true
310
  script:
311
    - docker build --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 .
312 313 314 315 316 317
    - docker push $IMAGE_TAG
    - docker push $IMAGE_TAG_SLUG
    - docker push $IMAGE_TAG_LATEST_STABLE
  tags:
    - dind
  only:
318
    - stable@pleroma/pleroma
319 320 321 322 323 324 325 326 327 328

docker-release:
  stage: docker
  image: docker:latest
  cache: {}
  dependencies: []
  variables: *docker-variables
  before_script: *before-docker
  allow_failure: true
  script:
329
    - docker build --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 .
330 331 332 333 334
    - docker push $IMAGE_TAG
    - docker push $IMAGE_TAG_SLUG
  tags:
    - dind
  only:
335
    - /^release/.*$/@pleroma/pleroma