# Cloud Build configuration for Autodoc Cloud API
# Deploy to Cloud Run

steps:
  # Build the container image
  - name: 'gcr.io/cloud-builders/docker'
    args:
      - 'build'
      - '-t'
      - 'gcr.io/$PROJECT_ID/autodoc-api:${_TAG}'
      - '-t'
      - 'gcr.io/$PROJECT_ID/autodoc-api:latest'
      - '.'
    dir: 'infrastructure/api'

  # Push the container image to Container Registry
  - name: 'gcr.io/cloud-builders/docker'
    args:
      - 'push'
      - 'gcr.io/$PROJECT_ID/autodoc-api:${_TAG}'

  - name: 'gcr.io/cloud-builders/docker'
    args:
      - 'push'
      - 'gcr.io/$PROJECT_ID/autodoc-api:latest'

  # Deploy container image to Cloud Run
  - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
    entrypoint: gcloud
    args:
      - 'run'
      - 'deploy'
      - 'autodoc-api'
      - '--image'
      - 'gcr.io/$PROJECT_ID/autodoc-api:${_TAG}'
      - '--region'
      - '${_REGION}'
      - '--platform'
      - 'managed'
      - '--allow-unauthenticated'
      - '--set-env-vars'
      - 'SUPABASE_URL=${_SUPABASE_URL}'
      - '--memory'
      - '512Mi'
      - '--cpu'
      - '1'
      - '--min-instances'
      - '0'
      - '--max-instances'
      - '10'
      - '--concurrency'
      - '80'

substitutions:
  _REGION: us-central1
  _SUPABASE_URL: https://iowgufboylypltycvwcp.supabase.co
  _TAG: latest

images:
  - 'gcr.io/$PROJECT_ID/autodoc-api:${_TAG}'
  - 'gcr.io/$PROJECT_ID/autodoc-api:latest'

options:
  logging: CLOUD_LOGGING_ONLY
