steps:
  # Build Docker image
  - name: 'gcr.io/cloud-builders/docker'
    args:
      - 'build'
      - '-t'
      - 'gcr.io/$PROJECT_ID/myroadtrip-api:$SHORT_SHA'
      - '-t'
      - 'gcr.io/$PROJECT_ID/myroadtrip-api:latest'
      - '-f'
      - 'apps/api/Dockerfile'
      - '.'

  # Push image to Container Registry
  - name: 'gcr.io/cloud-builders/docker'
    args:
      - 'push'
      - 'gcr.io/$PROJECT_ID/myroadtrip-api:$SHORT_SHA'

  # Deploy to Cloud Run (staging)
  - name: 'gcr.io/cloud-builders/gcloud'
    args:
      - 'run'
      - 'deploy'
      - 'myroadtrip-api-staging'
      - '--image=gcr.io/$PROJECT_ID/myroadtrip-api:$SHORT_SHA'
      - '--region=europe-west1'
      - '--platform=managed'
      - '--allow-unauthenticated'
      - '--set-env-vars=NODE_ENV=staging'
      - '--set-secrets=FIREBASE_PRIVATE_KEY=firebase-private-key:latest'
      - '--set-secrets=OPENAI_API_KEY=openai-api-key:latest'
      - '--min-instances=0'
      - '--max-instances=10'
      - '--memory=512Mi'
      - '--cpu=1'
      - '--timeout=60s'

images:
  - 'gcr.io/$PROJECT_ID/myroadtrip-api:$SHORT_SHA'
  - 'gcr.io/$PROJECT_ID/myroadtrip-api:latest'

options:
  machineType: 'N1_HIGHCPU_8'
  logging: CLOUD_LOGGING_ONLY
