stages:
  - build
  - test

backend-image:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context ${CI_PROJECT_DIR}/backend/ --dockerfile ${CI_PROJECT_DIR}/backend/Dockerfile --destination $CI_REGISTRY_IMAGE/backend:${CI_COMMIT_REF_NAME}
  only:
    changes:
      - ./**/*
      - .gitlab-ci.yml

backend-unittests:
  stage: test
  variables:
    DATABASE_USER: postgres
    DATABASE_PASSWORD: secret
    DATABASE_NAME: postgres
    DATABASE_HOST: postgres
    POSTGRES_PASSWORD: secret
  services:
    - name: postgres:11
      alias: postgres
  image: ${CI_REGISTRY_IMAGE}/backend:${CI_COMMIT_REF_NAME}
  script:
    - cd backend
    - python3 -m unittest discover
  only:
    changes:
      - login_provider/**/*
      - .gitlab-ci.yml
