steps:
  # Loading hml image
  - name: "gcr.io/cloud-builders/docker"
    args: [
            "pull",
            "${_REPOSITORY}/$_IMAGE_NAME:$_HLG_BRANCH"
          ]
    id: Loading HML Image

  # Tagging image
  - name: "gcr.io/cloud-builders/docker"
    args: [
            "tag",
            "${_REPOSITORY}/$_IMAGE_NAME:$_HLG_BRANCH",
            "${_REPOSITORY}/$_IMAGE_NAME:$TAG_NAME"
          ]
    id: Tagging PRD image

  # Tagging LATEST image
  - name: "gcr.io/cloud-builders/docker"
    args: [
            "tag",
            "${_REPOSITORY}/$_IMAGE_NAME:$_HLG_BRANCH",
            "${_REPOSITORY}/$_IMAGE_NAME:latest"
          ]
    id: Tagging LATEST image

  # Push the PRD image to Artifact Registry
  - name: "gcr.io/cloud-builders/docker"
    args: [
            "push",
            "${_REPOSITORY}/$_IMAGE_NAME:$TAG_NAME"
          ]
    id: Push the PRD image to Artifact Registry

  # Deploy PRD image to Cloud Run
  - name: "gcr.io/google.com/cloudsdktool/cloud-sdk:slim"
    entrypoint: gcloud
    args: [
            run, jobs, update, $_SERVICE_NAME,
            --image, $_REPOSITORY/$_IMAGE_NAME:$TAG_NAME,
            --region, $_RUN_LOCATION
          ]
    id: Deploy container image to Cloud Run

images:
  - "${_REPOSITORY}/$_IMAGE_NAME:latest"
  - "${_REPOSITORY}/$_IMAGE_NAME:$TAG_NAME"

tags:
  - gcp-cloud-build-deploy-cloud-run
  - gcp-cloud-build-deploy-cloud-run-managed
  - $_SERVICE_NAME

timeout: 3600s
