Spaces:
Sleeping
Sleeping
| set -euo pipefail | |
| PROJECT_ID="${PROJECT_ID:-}" | |
| REGION="${REGION:-asia-south1}" | |
| SERVICE_NAME="${SERVICE_NAME:-mail-triage-api}" | |
| IMAGE="gcr.io/${PROJECT_ID}/${SERVICE_NAME}:latest" | |
| ALLOW_UNAUTH="${ALLOW_UNAUTH:-true}" | |
| if [[ -z "${PROJECT_ID}" ]]; then | |
| echo "Error: set PROJECT_ID before running this script." | |
| echo "Example: PROJECT_ID=my-gcp-project ./deploy/google_cloud_run/deploy.sh" | |
| exit 1 | |
| fi | |
| if [[ -z "${TRIAGE_API_KEY:-}" ]]; then | |
| echo "Error: set TRIAGE_API_KEY before running this script." | |
| echo "Example: TRIAGE_API_KEY='replace-me' PROJECT_ID=my-gcp-project ./deploy/google_cloud_run/deploy.sh" | |
| exit 1 | |
| fi | |
| echo "Using project: ${PROJECT_ID}" | |
| echo "Using region: ${REGION}" | |
| echo "Service name: ${SERVICE_NAME}" | |
| gcloud config set project "${PROJECT_ID}" | |
| gcloud services enable run.googleapis.com cloudbuild.googleapis.com artifactregistry.googleapis.com | |
| gcloud builds submit \ | |
| --config deploy/google_cloud_run/cloudbuild.yaml \ | |
| --substitutions "_IMAGE=${IMAGE}" \ | |
| . | |
| AUTH_FLAG="--allow-unauthenticated" | |
| if [[ "${ALLOW_UNAUTH}" != "true" ]]; then | |
| AUTH_FLAG="--no-allow-unauthenticated" | |
| fi | |
| gcloud run deploy "${SERVICE_NAME}" \ | |
| --image "${IMAGE}" \ | |
| --platform managed \ | |
| --region "${REGION}" \ | |
| --port 8080 \ | |
| --memory 1Gi \ | |
| --cpu 1 \ | |
| --max-instances 3 \ | |
| --set-env-vars "TRIAGE_API_KEY=${TRIAGE_API_KEY}" \ | |
| ${AUTH_FLAG} | |
| echo "Deployment complete." | |
| echo "Run to fetch URL: gcloud run services describe ${SERVICE_NAME} --region ${REGION} --format='value(status.url)'" | |