build_backend:
  stage: build
  image: maven:3.9.9-eclipse-temurin-21@sha256:2e3824afeb41f61761adee95318814e6669bd59aaf61255b2af47064b8755c02
  script:
    - cd backend
    - mvn package
  artifacts:
    paths:
      - backend/common/target/
      - backend/gateway/target/
      - backend/discovery/target/
      - backend/server/target
    expire_in: 1 hour

docker_common:
  extends: .docker-common-template
  variables:
    IMAGE_NAME: common
    WORKDIR_PATH: backend
    DOCKERFILE_PATH: Dockerfile.base
  needs:
    - build_backend

docker_gateway:
  extends: .docker-build-template
  variables:
    IMAGE_NAME: gateway
    COMMON_IMAGE: "$CI_REGISTRY/$CI_PROJECT_PATH/common"
    WORKDIR_PATH: backend
    DOCKERFILE_PATH: Dockerfile.app
    BUILD_FOLDER: "gateway/target"
    MAIN_CLASS: dev.rheinsw.gateway.GatewayApplication
  needs:
    - build_backend
    - docker_common

docker_server:
  extends: .docker-build-template
  variables:
    IMAGE_NAME: server
    COMMON_IMAGE: "$CI_REGISTRY/$CI_PROJECT_PATH/common"
    WORKDIR_PATH: backend
    DOCKERFILE_PATH: Dockerfile.app
    BUILD_FOLDER: "server/target"
    MAIN_CLASS: dev.rheinsw.server.ServerApplication
  needs:
    - build_backend
    - docker_common
