image: python:3.9-alpine


variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache"

cache:
  paths:
    - .cache/pip


stages:
  - test
  - style
  - build
  - deploy

django_test:
  stage: test
  before_script:
    - pip install -r requirements/dev.txt
  script:
    - python manage.py test

coverage:
  stage: test
  before_script:
    - pip install -r requirements/dev.txt
  script:
    - coverage run
    - coverage report -m
    - coverage html -d public/coverage
  artifacts:
    paths:
      - public/coverage

pylint:
  stage: style
  allow_failure: true
  before_script:
    - pip install -r requirements/dev.txt
  script:
    - pylint --reports=yes main

docker:
  stage: build
  only:
    - master
  tags:
    - docker
  before_script:
    - docker info
    - docker login -u $REGISTRY_USERNAME -p $REGISTRY_PASSWORD gitlab.cazzzer.com:5050
  script:
    - docker build . -t gitlab.cazzzer.com:5050/cazzzer/zendesk-access-controller:alpine
    - docker push gitlab.cazzzer.com:5050/cazzzer/zendesk-access-controller:alpine
  after_script:
    - docker logout

deploy:
  stage: deploy
  only:
    - master
  tags:
    - cazzzer-internal
  script:
    - sudo -u cazzzer /home/cazzzer/deploy_access_controller.sh
