variables:
  HEROKU_APP_NAME: tdt4242-base
  HEROKU_REGISTRY_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/web
stages:
  - test
  - build_and_deploy

test:
  image: python:3
  stage: test
  script:
  # this configures Django application to use attached postgres database that is run on `postgres` host
    - cd backend/secfit
    - apt-get update -qy
    - pip install -r requirements.txt
    - python manage.py test

build_and_deploy:
  image: docker:stable
  services:
    - docker:dind
  stage: build_and_deploy
  script:
    - apk add --no-cache curl
    - docker login -u _ -p $HEROKU_AUTH_TOKEN registry.heroku.com
    - docker pull $HEROKU_REGISTRY_IMAGE || true
    - docker build
      --cache-from $HEROKU_REGISTRY_IMAGE
      --tag $HEROKU_REGISTRY_IMAGE
      --file ./Dockerfile
      "."
    - docker push $HEROKU_REGISTRY_IMAGE
    - chmod +x ./release.sh
    - ./release.sh