Skip to content

Commit 7869c71

Browse files
committed
Update deploy script
1 parent ec13ea5 commit 7869c71

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

backend/api/deploy-api.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,28 @@ source ../../.env
77

88
ENV=${1:-prod}
99

10+
if [ "$ENV" != "prod" ] && [ "$ENV" != "dev" ]; then
11+
echo "Invalid environment '${ENV}'; must be 'dev' or 'prod'."
12+
exit 1
13+
fi
14+
1015
# Config
1116
REGION="us-west1"
1217
ZONE="us-west1-b"
1318

14-
PROJECT="compass-130ba"
19+
# Prod and dev live in separate GCP/Firebase projects (see main.tf). The image is
20+
# built into, and Cloud Run deployed to, the project matching $ENV.
21+
if [ "$ENV" = "prod" ]; then
22+
PROJECT="compass-130ba"
23+
DOMAIN="api.compassmeet.com"
24+
else
25+
PROJECT="compass-57c3c"
26+
DOMAIN="api.dev.compassmeet.com"
27+
fi
1528
SERVICE_NAME="api"
1629

30+
echo "Deploying '${SERVICE_NAME}' to ${ENV} (project ${PROJECT})"
31+
1732
GIT_REVISION=$(git rev-parse --short HEAD)
1833
GIT_COMMIT_DATE=$(git log -1 --format=%ci)
1934
GIT_COMMIT_AUTHOR=$(git log -1 --format='%an')
@@ -47,9 +62,10 @@ docker push ${IMAGE_URL}
4762
# but simply swaps the container image.
4863
gcloud run deploy ${SERVICE_NAME} \
4964
--image ${IMAGE_URL} \
65+
--project ${PROJECT} \
5066
--region ${REGION} \
5167
--platform managed \
5268
--quiet
5369

54-
echo "Custom Domain: https://api.compassmeet.com"
70+
echo "Custom Domain: https://${DOMAIN}"
5571
echo "✅ Code updated on Cloud Run!"

backend/api/main.tf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ variable "env" {
1212

1313
# 2. Local Constants
1414
locals {
15-
project = "compass-130ba"
15+
is_prod = var.env == "prod"
16+
# Prod and dev live in separate GCP/Firebase projects. env=dev targets the dev
17+
# Firebase project so the API talks to the dev Auth/Firestore/Storage backends.
18+
project = local.is_prod ? "compass-130ba" : "compass-57c3c"
1619
region = "us-west1"
1720
service_name = "api"
21+
api_domain = local.is_prod ? "api.compassmeet.com" : "api.dev.compassmeet.com"
1822
}
1923

2024
# 3. Provider & Backend
25+
# State stays in the prod bucket but is isolated per environment via Terraform
26+
# workspaces (default = prod, `terraform workspace new dev` for dev). The gcs
27+
# backend automatically namespaces named workspaces, so dev/prod never collide.
2128
terraform {
2229
backend "gcs" {
2330
bucket = "compass-130ba-terraform-state"
@@ -142,7 +149,7 @@ resource "google_cloud_run_v2_service_iam_member" "public_access" {
142149
# Otherwise, use 'google_cloud_run_v2_domain_mapping'
143150
resource "google_cloud_run_domain_mapping" "api_domain" {
144151
location = local.region
145-
name = "api.compassmeet.com"
152+
name = local.api_domain
146153

147154
metadata {
148155
namespace = local.project

0 commit comments

Comments
 (0)