Skip to content
Snippets Groups Projects
.gitlab-ci.yml 5.06 KiB
Newer Older
stages:
  - test
Erwan Rouchet's avatar
Erwan Rouchet committed
  - build
Erwan Rouchet's avatar
Erwan Rouchet committed
  - deploy
# GitLab provides a template to ensure pipelines run only for branches and tags, not for merge requests
# This prevents duplicate pipelines in merge requests.
# See https://docs.gitlab.com/ee/ci/troubleshooting.html#job-may-allow-multiple-pipelines-to-run-for-a-single-action
include:
  - template: 'Workflows/Branch-Pipelines.gitlab-ci.yml'

Erwan Rouchet's avatar
Erwan Rouchet committed
# For jobs that run backend scripts directly
.backend-setup:
Erwan Rouchet's avatar
Erwan Rouchet committed
  image: registry.gitlab.teklia.com/arkindex/backend/base:gitlab-teklia
Erwan Rouchet's avatar
Erwan Rouchet committed
  cache:
    paths:
      - .cache/pip
Erwan Rouchet's avatar
Erwan Rouchet committed
  before_script:
    - "echo database: {host: postgres, port: 5432} > $CONFIG_PATH"
    - pip install -e .[test]
  # Those jobs require the base image; they might fail if the image is not up to date.
  # Allow them to fail when building a new base image, to prevent them from blocking a new base image build
  # Never run those jobs on scheduled pipelines
  rules:
    - if: '$CI_COMMIT_TAG && $CI_COMMIT_TAG =~ /^base-.*/'
      allow_failure: true
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
Erwan Rouchet's avatar
Erwan Rouchet committed
  variables:
    # For the postgres image
    POSTGRES_DB: arkindex_dev
    POSTGRES_USER: devuser
    POSTGRES_PASSWORD: devdata
Erwan Rouchet's avatar
Erwan Rouchet committed
    # For the backend
    CONFIG_PATH: "$CI_PROJECT_DIR/config.yml"
Erwan Rouchet's avatar
Erwan Rouchet committed
    # Pip cache
    PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
Erwan Rouchet's avatar
Erwan Rouchet committed

backend-tests:
Erwan Rouchet's avatar
Erwan Rouchet committed
  extends: .backend-setup
  stage: test
Erwan Rouchet's avatar
Erwan Rouchet committed

    - name: postgis/postgis:14-3.2
      alias: postgres
  artifacts:
    when: always
    reports:
      junit:
Erwan Rouchet's avatar
Erwan Rouchet committed
        - test-report.xml
  script:
    - arkindex test
Erwan Rouchet's avatar
Erwan Rouchet committed
  image: python:3.10
  except:
    - schedules

  cache:
    paths:
      - .cache/pip
      - .cache/pre-commit

  variables:
    PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
    PRE_COMMIT_HOME: "$CI_PROJECT_DIR/.cache/pre-commit"

  before_script:
    - pip install pre-commit

    - pre-commit run -a
Erwan Rouchet's avatar
Erwan Rouchet committed

backend-migrations:
Erwan Rouchet's avatar
Erwan Rouchet committed
  extends: .backend-setup
  stage: test

  services:
    - name: postgis/postgis:12-3.1
      alias: postgres
    - arkindex makemigrations --check --noinput --dry-run -v 3
backend-openapi:
  extends: .backend-setup
  stage: build

  script:
    - ci/openapi.sh

  artifacts:
    paths:
      - output/

backend-static:
Erwan Rouchet's avatar
Erwan Rouchet committed
  extends: .backend-setup
  stage: build

  script:
Erwan Rouchet's avatar
Erwan Rouchet committed
    - ci/static-collect.sh

  artifacts:
    paths:
      - static
Erwan Rouchet's avatar
Erwan Rouchet committed

backend-build-base:
  stage: build
  image: docker:19.03.1
  services:
    - docker:dind
  variables:
    DOCKER_DRIVER: overlay2
    DOCKER_HOST: tcp://docker:2375/

  # Run this only on base tags
  rules:
    - if: '$CI_COMMIT_TAG =~ /^base-.*/'
      when: on_success
    - when: never

  script:
    - ci/build-base.sh

backend-build:
  stage: build
  image: docker:19.03.1
  services:
    - docker:dind
  variables:
    DOCKER_DRIVER: overlay2
    DOCKER_HOST: tcp://docker:2375/

  # Run this on master and tags except base tags and schedules
Erwan Rouchet's avatar
Erwan Rouchet committed
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
Erwan Rouchet's avatar
Erwan Rouchet committed
    - if: '$CI_COMMIT_BRANCH == "master"'
      when: on_success
    - if: '$CI_COMMIT_TAG && $CI_COMMIT_TAG !~ /^base-.*/'
      when: on_success
    - when: never

  script:
    - ci/build.sh
Erwan Rouchet's avatar
Erwan Rouchet committed

# Make sure arkindex is always compatible with Nuitka
backend-build-binary:
  stage: build

  image: python:3.10

  before_script:
    - pip install nuitka

  script:
    - python -m nuitka --nofollow-imports --include-package=arkindex --nofollow-import-to=*.tests arkindex/manage.py

  except:
    - schedules

Erwan Rouchet's avatar
Erwan Rouchet committed
backend-static-deploy:
  stage: deploy
Erwan Rouchet's avatar
Erwan Rouchet committed

  # Run this on any version tag except base images
  rules:
    - if: '$CI_COMMIT_TAG && $CI_COMMIT_TAG !~ /^base-.*/'
      when: on_success
    - when: never

  # Run immediately once backend-static ends without waiting for others
  needs:
    - backend-static

  # Ensure artifacts are available
  dependencies:
    - backend-static

  script:
    - ci/static-deploy.sh
backend-openapi-deploy:
  stage: deploy

  # Run on master updates only
  only:

  # Ensure artifacts are available
  dependencies:
    - backend-openapi

  before_script:
    - pip install awscli

  script:
    - aws s3 cp output/schema.yml s3://teklia-assets-release/arkindex/openapi.yml

sentry-release:
  stage: deploy
  image: getsentry/sentry-cli
    - if: '$CI_COMMIT_TAG && $CI_COMMIT_TAG !~ /^base-.*/'
      when: on_success
    - when: never

  variables:
    RELEASE: "arkindex-backend@$CI_COMMIT_TAG"
    SENTRY_ORG: teklia
    SENTRY_PROJECT: arkindex-backend

  dependencies:
    - backend-build

  script:
    - sentry-cli releases new --finalize $RELEASE

release-notes:
  stage: deploy
Erwan Rouchet's avatar
Erwan Rouchet committed
  image: registry.gitlab.teklia.com/infra/devops:latest
  rules:
    - if: '$CI_COMMIT_TAG && $CI_COMMIT_TAG !~ /^base-.*/'
      when: on_success
    - when: never

  script:
    - devops release-notes

bump-python-deps:
  stage: deploy
Erwan Rouchet's avatar
Erwan Rouchet committed
  image: registry.gitlab.teklia.com/infra/devops:latest
    - devops python-deps requirements.txt base/requirements.txt tests-requirements.txt