#!/bin/bash  
  
# Exit immediately if a command exits with a non-zero status  
set -e  
  
# Optional: Configure Docker authentication with Google Cloud (uncomment if needed)  
# echo "Configuring Docker authentication..."  
# gcloud auth configure-docker asia-east2-docker.pkg.dev

# gcloud config set project gcp-digital-infra
  
# Build the Go application for Linux AMD64  
echo "Building Go application for linux_amd64 architecture..."  
make go.build.linux_amd64.data-platform
  
# Package the handle for Linux AMD64  
echo "Packing handle for linux_amd64 architecture..."  
make pack.handle.linux_amd64.data-platform  
  
# Deploy to Google Cloud Run  
echo "Deploying to Google Cloud Run..."  
gcloud run deploy data-platform \
  --platform=managed \
  --allow-unauthenticated \
  --image=asia-east2-docker.pkg.dev/gcp-digital-infra/internal-tools/data-platform-linux-amd64:latest \
  --update-secrets /app/config/config.yaml=data-platform:latest,NEXUSCRM_FINANCE_ORDER_BACKFILL_CLIENT_SECRET=nexuscrm-finance-order-backfill-client-secret:latest \
  --port=8868 \
  --service-account=data-platform@gcp-digital-infra.iam.gserviceaccount.com \
  --region=us-west2 \
  --ingress=internal-and-cloud-load-balancing  
  
echo "Deployment completed successfully!"
