From 7869c71cd75c440ef3899bbbc3a680e088c76564 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Thu, 2 Jul 2026 17:03:17 +0200 Subject: [PATCH] Update deploy script --- backend/api/deploy-api.sh | 20 ++++++++++++++++++-- backend/api/main.tf | 11 +++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/backend/api/deploy-api.sh b/backend/api/deploy-api.sh index 3293b7eb..62cade60 100755 --- a/backend/api/deploy-api.sh +++ b/backend/api/deploy-api.sh @@ -7,13 +7,28 @@ source ../../.env ENV=${1:-prod} +if [ "$ENV" != "prod" ] && [ "$ENV" != "dev" ]; then + echo "Invalid environment '${ENV}'; must be 'dev' or 'prod'." + exit 1 +fi + # Config REGION="us-west1" ZONE="us-west1-b" -PROJECT="compass-130ba" +# Prod and dev live in separate GCP/Firebase projects (see main.tf). The image is +# built into, and Cloud Run deployed to, the project matching $ENV. +if [ "$ENV" = "prod" ]; then + PROJECT="compass-130ba" + DOMAIN="api.compassmeet.com" +else + PROJECT="compass-57c3c" + DOMAIN="api.dev.compassmeet.com" +fi SERVICE_NAME="api" +echo "Deploying '${SERVICE_NAME}' to ${ENV} (project ${PROJECT})" + GIT_REVISION=$(git rev-parse --short HEAD) GIT_COMMIT_DATE=$(git log -1 --format=%ci) GIT_COMMIT_AUTHOR=$(git log -1 --format='%an') @@ -47,9 +62,10 @@ docker push ${IMAGE_URL} # but simply swaps the container image. gcloud run deploy ${SERVICE_NAME} \ --image ${IMAGE_URL} \ + --project ${PROJECT} \ --region ${REGION} \ --platform managed \ --quiet -echo "Custom Domain: https://api.compassmeet.com" +echo "Custom Domain: https://${DOMAIN}" echo "✅ Code updated on Cloud Run!" diff --git a/backend/api/main.tf b/backend/api/main.tf index 195c11d4..25d54602 100644 --- a/backend/api/main.tf +++ b/backend/api/main.tf @@ -12,12 +12,19 @@ variable "env" { # 2. Local Constants locals { - project = "compass-130ba" + is_prod = var.env == "prod" + # Prod and dev live in separate GCP/Firebase projects. env=dev targets the dev + # Firebase project so the API talks to the dev Auth/Firestore/Storage backends. + project = local.is_prod ? "compass-130ba" : "compass-57c3c" region = "us-west1" service_name = "api" + api_domain = local.is_prod ? "api.compassmeet.com" : "api.dev.compassmeet.com" } # 3. Provider & Backend +# State stays in the prod bucket but is isolated per environment via Terraform +# workspaces (default = prod, `terraform workspace new dev` for dev). The gcs +# backend automatically namespaces named workspaces, so dev/prod never collide. terraform { backend "gcs" { bucket = "compass-130ba-terraform-state" @@ -142,7 +149,7 @@ resource "google_cloud_run_v2_service_iam_member" "public_access" { # Otherwise, use 'google_cloud_run_v2_domain_mapping' resource "google_cloud_run_domain_mapping" "api_domain" { location = local.region - name = "api.compassmeet.com" + name = local.api_domain metadata { namespace = local.project