stages:
  - build

variables:
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: ""

  POSTGRESQL_IMAGE_NAME: "postgres"
  POSTGRESQL_IMAGE: $CI_REGISTRY_IMAGE/$POSTGRESQL_IMAGE_NAME

  ECLIPSE_TEMURIN_IMAGE_NAME: "eclipse-temurin"
  ECLIPSE_TEMURIN_IMAGE: $CI_REGISTRY_IMAGE/$ECLIPSE_TEMURIN_IMAGE_NAME

  KANIKO_IMAGE_NAME: "custom-kaniko"
  KANIKO_IMAGE: $CI_REGISTRY_IMAGE/$KANIKO_IMAGE_NAME

build_eclipse_temurin:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  tags:
    - docker
  script:
    - export
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$(echo -n ${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD} | base64)\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR/eclipse-temurin/17 --dockerfile $CI_PROJECT_DIR/eclipse-temurin/17/Dockerfile --destination ${ECLIPSE_TEMURIN_IMAGE}:17-jre-alpine
    - /kaniko/executor --context $CI_PROJECT_DIR/eclipse-temurin/21 --dockerfile $CI_PROJECT_DIR/eclipse-temurin/21/Dockerfile --destination ${ECLIPSE_TEMURIN_IMAGE}:21-jre-alpine
  only:
    - main

build_postgresql:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  tags:
    - docker
  script:
    - export
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$(echo -n ${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD} | base64)\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR/postgresql/14 --dockerfile $CI_PROJECT_DIR/postgresql/14/Dockerfile --destination ${POSTGRESQL_IMAGE}:14
    - /kaniko/executor --context $CI_PROJECT_DIR/postgresql/15 --dockerfile $CI_PROJECT_DIR/postgresql/15/Dockerfile --destination ${POSTGRESQL_IMAGE}:15
    - /kaniko/executor --context $CI_PROJECT_DIR/postgresql/16 --dockerfile $CI_PROJECT_DIR/postgresql/16/Dockerfile --destination ${POSTGRESQL_IMAGE}:16
  only:
    - main

build_kaniko:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  tags:
    - docker
  script:
    - export
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$(echo -n ${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD} | base64)\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --context $CI_PROJECT_DIR/kaniko/1_23 --dockerfile $CI_PROJECT_DIR/kaniko/1_23/Dockerfile --destination ${KANIKO_IMAGE}:1.23.2
  only:
    - main