variables:
  DOCKER_IMAGE: registry.forge.hefr.ch/team-raclette/project-softweng/gateway:latest

default:
  image: $DOCKER_IMAGE

stages:
  - gateway-build

# This job runs only when Dockerfile changes
gateway-docker-build:
  image: docker:latest
  stage: gateway-build
  services:
    - docker:dind
  script:
    - docker build -t $DOCKER_IMAGE -f gateway/Dockerfile .
    - echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
    - docker push $DOCKER_IMAGE
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_COMMIT_BRANCH == 'main'
    - changes:
        - gateway/Dockerfile
        - gateway/src/*
