---

steps:
  - id: build-base
    name: us-east1-docker.pkg.dev/overleaf-ops/ol-docker/cloud-builder
    dir: server-ce
    args:
      - 'build-base'
      - 'OVERLEAF_BASE_CACHE=${_IMAGE_BASE_CACHE}'
      - 'OVERLEAF_BASE_TAG=${_IMAGE_BASE}'
  - id: build-community
    name: us-east1-docker.pkg.dev/overleaf-ops/ol-docker/cloud-builder
    dir: server-ce
    args:
      - build-community
      - 'OVERLEAF_BASE_CACHE=${_IMAGE_BASE_CACHE}'
      - 'OVERLEAF_BASE_TAG=${_IMAGE_BASE}'
      - 'OVERLEAF_TAG=${_IMAGE_TAG}'
  - id: tag_main_latest_base
    name: gcr.io/cloud-builders/docker
    script: |
      #!/usr/bin/env bash
      set -e
      if [ ${BRANCH_NAME} == main ]; then
        docker tag ${_IMAGE_BASE} ${_IMAGE_BASE_CACHE};
        docker push ${_IMAGE_BASE_CACHE};
      fi
    automapSubstitutions: true
  - id: tag_main_latest
    name: gcr.io/cloud-builders/docker
    script: |
      #!/usr/bin/env bash
      set -e
      if [ $BRANCH_NAME == main ]; then
        docker tag ${_IMAGE_TAG} ${_IMAGE_CE};
        docker push ${_IMAGE_CE};
      fi
    automapSubstitutions: true
timeout: 3600s
options:
  machineType: E2_HIGHCPU_32
  env:
    - 'BRANCH_NAME=${BRANCH_NAME}'
images:
  - '${_IMAGE_BASE}'
  - '${_IMAGE_TAG}'
substitutions:
  _IMAGE_BASE: 'us-east1-docker.pkg.dev/overleaf-ops/ol-docker/overleaf-base:${BRANCH_NAME}-${SHORT_SHA}_${BUILD_ID}'
  _IMAGE_BASE_CACHE: 'us-east1-docker.pkg.dev/overleaf-ops/ol-docker/overleaf-base:latest'
  _IMAGE_CE: 'us-east1-docker.pkg.dev/overleaf-ops/ol-docker/overleaf:latest'
  _IMAGE_TAG: 'us-east1-docker.pkg.dev/overleaf-ops/ol-docker/overleaf:${BRANCH_NAME}-${SHORT_SHA}_${BUILD_ID}'
tags:
  - 'overleaf-public'
  - '${BRANCH_NAME}'
  - '${SHORT_SHA}'