stages:
  - backend_build
  - dockerize

variables:
  REGISTRY: registry.gitlab.com/rheinsw/$CI_PROJECT_PATH
  TAG: $CI_COMMIT_REF_SLUG

default:
  before_script:
    - cd backend

backend_build_job:
  stage: backend_build
  image: maven:3.9.9-eclipse-temurin-21@sha256:2e3824afeb41f61761adee95318814e6669bd59aaf61255b2af47064b8755c02
  script:
    - mvn package
  artifacts:
    paths:
      - backend/shared/target/
      - backend/gateway/target/
      - backend/discoveryServer/target/
      - backend/services/**/target
    expire_in: 1 hour

build_shared_base_image:
  stage: dockerize
  script:
    - docker build -f Dockerfile.base -t $REGISTRY/shared-base:$TAG .
    - docker push $REGISTRY/shared-base:$TAG
  needs:
    - backend_build_job

build_gateway_image:
  stage: dockerize
  script:
    - docker build --build-arg JAR_FILE=backend/gateway/target/gateway-*.jar -f Dockerfile.service -t $REGISTRY/gateway:$TAG .
    - docker push $REGISTRY/gateway:$TAG
  needs:
    - backend_build_job
    - build_shared_base_image

build_discovery_image:
  stage: dockerize
  script:
    - docker build --build-arg JAR_FILE=backend/discoveryServer/target/discoveryServer-*.jar -f Dockerfile.service -t $REGISTRY/discovery-server:$TAG .
    - docker push $REGISTRY/discovery-server:$TAG
  needs:
    - backend_build_job
    - build_shared_base_image
