stages:
  - build

docker-build-rolling:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  variables:
    TAG: $CI_COMMIT_BRANCH
  script:
    - cp ${DOCKER_HUB_CONFIG} /kaniko/.docker/config.json
    - /kaniko/executor --cleanup --context . --dockerfile docker/production/web-server/Dockerfile --destination ${DOCKER_IMAGE_WEB_SERVER}:${TAG}
    - /kaniko/executor --cleanup --context . --dockerfile docker/production/app/Dockerfile --destination ${DOCKER_IMAGE_APP}:${TAG}
    - /kaniko/executor --cleanup --context . --dockerfile docker/production/video-clipper/Dockerfile --destination ${DOCKER_IMAGE_VIDEO_CLIPPER}:${TAG}
    - /kaniko/executor --cleanup --context . --dockerfile docker/production/unit/Dockerfile --destination ${DOCKER_IMAGE_UNIT}:${TAG}
  needs:
    - pipeline: $PARENT_PIPELINE_ID
      job: bundle
  only:
    refs:
      - develop

docker-build-main-release:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
    - cp ${DOCKER_HUB_CONFIG} /kaniko/.docker/config.json
    - export CP_VERSION=$(cat CP_VERSION.env)
    - /kaniko/executor --cleanup --context . --dockerfile docker/production/web-server/Dockerfile --destination ${DOCKER_IMAGE_WEB_SERVER}:${CP_VERSION} --destination ${DOCKER_IMAGE_WEB_SERVER}:latest
    - /kaniko/executor --cleanup --context . --dockerfile docker/production/app/Dockerfile --destination ${DOCKER_IMAGE_APP}:${CP_VERSION} --destination ${DOCKER_IMAGE_APP}:latest
    - /kaniko/executor --cleanup --context . --dockerfile docker/production/video-clipper/Dockerfile --destination ${DOCKER_IMAGE_VIDEO_CLIPPER}:${CP_VERSION} --destination ${DOCKER_IMAGE_VIDEO_CLIPPER}:latest
    - /kaniko/executor --cleanup --context . --dockerfile docker/production/unit/Dockerfile --destination ${DOCKER_IMAGE_UNIT}:${CP_VERSION} --destination ${DOCKER_IMAGE_UNIT}:latest
  needs:
    - pipeline: $PARENT_PIPELINE_ID
      job: release
  only:
    refs:
      - main

docker-build-alpha-beta-release:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  variables:
    TAG: $CI_COMMIT_BRANCH
  script:
    - cp ${DOCKER_HUB_CONFIG} /kaniko/.docker/config.json
    - export CP_VERSION=$(cat CP_VERSION.env)
    - /kaniko/executor --cleanup --context . --dockerfile docker/production/web-server/Dockerfile --destination ${DOCKER_IMAGE_WEB_SERVER}:${CP_VERSION} --destination ${DOCKER_IMAGE_WEB_SERVER}:${TAG}
    - /kaniko/executor --cleanup --context . --dockerfile docker/production/app/Dockerfile --destination ${DOCKER_IMAGE_APP}:${CP_VERSION} --destination ${DOCKER_IMAGE_APP}:${TAG}
    - /kaniko/executor --cleanup --context . --dockerfile docker/production/video-clipper/Dockerfile --destination ${DOCKER_IMAGE_VIDEO_CLIPPER}:${CP_VERSION} --destination ${DOCKER_IMAGE_VIDEO_CLIPPER}:${TAG}
    - /kaniko/executor --cleanup --context . --dockerfile docker/production/unit/Dockerfile --destination ${DOCKER_IMAGE_UNIT}:${CP_VERSION} --destination ${DOCKER_IMAGE_UNIT}:${TAG}
  needs:
    - pipeline: $PARENT_PIPELINE_ID
      job: release
  only:
    refs:
      - alpha
      - beta
