Personal time tracking app built in python fastAPI
steps:
  # Build the Docker image with SHA tag and latest tag
  - name: 'gcr.io/cloud-builders/docker'
    args:
      - 'build'
      - '-t'
      - '${_REGISTRY_LOCATION}-docker.pkg.dev/${_PROJECT_ID}/${_REPO_NAME}/${_IMAGE_NAME}:$COMMIT_SHA'
      - '-t'
      - '${_REGISTRY_LOCATION}-docker.pkg.dev/${_PROJECT_ID}/${_REPO_NAME}/${_IMAGE_NAME}:latest'
      - '.'
    id: 'build-image'

  # Push image with SHA tag
  - name: 'gcr.io/cloud-builders/docker'
    args:
      - 'push'
      - '${_REGISTRY_LOCATION}-docker.pkg.dev/${_PROJECT_ID}/${_REPO_NAME}/${_IMAGE_NAME}:$COMMIT_SHA'
    id: 'push-image-sha'

  # Push latest tag
  - name: 'gcr.io/cloud-builders/docker'
    args:
      - 'push'
      - '${_REGISTRY_LOCATION}-docker.pkg.dev/${_PROJECT_ID}/${_REPO_NAME}/${_IMAGE_NAME}:latest'
    id: 'push-image-latest'

  # Deploy to Cloud Run using the commit SHA tag to ensure we deploy the exact image just built
  - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
    entrypoint: gcloud
    args:
      - 'run'
      - 'deploy'
      - '${_IMAGE_NAME}'
      - '--image'
      - '${_REGISTRY_LOCATION}-docker.pkg.dev/${_PROJECT_ID}/${_REPO_NAME}/${_IMAGE_NAME}:$COMMIT_SHA'
      - '--region'
      - '${_REGION}'
      - '--platform'
      - 'managed'
      - '--allow-unauthenticated'
    id: 'deploy-cloud-run'

# Images to store in Artifact Registry
images:
  - '${_REGISTRY_LOCATION}-docker.pkg.dev/${_PROJECT_ID}/${_REPO_NAME}/${_IMAGE_NAME}:$COMMIT_SHA'
  - '${_REGISTRY_LOCATION}-docker.pkg.dev/${_PROJECT_ID}/${_REPO_NAME}/${_IMAGE_NAME}:latest'

# Build options
options:
  machineType: 'E2_HIGHCPU_8'
  logging: CLOUD_LOGGING_ONLY

# Timeout for the build
timeout: '1200s'

# Tags for the build
tags:
  - 'docker'
  - '${_IMAGE_NAME}'