-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·91 lines (81 loc) · 2.77 KB
/
deploy.sh
File metadata and controls
executable file
·91 lines (81 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
#
# Echo Storyteller Deployment Script
#
# This script deploys the "Echo Storyteller" application to Google Cloud Run.
# It handles loading configuration from a local .env file, building the Flutter web app,
# and executing the gcloud deploy command.
#
# Usage:
# ./deploy.sh
#
# Configuration (.env):
# Required:
# GOOGLE_CLOUD_PROJECT - GCP Project ID
# GOOGLE_CLOUD_LOCATION - Vertex AI Region (e.g., us-central1)
#
# Optional:
# REGION - Cloud Run Region (Defaults to 'us-central1')
# SERVICE_NAME - Cloud Run Service Name (Defaults to 'echo-storyteller')
#
# Load environment variables from .env
if [ -f .env ]; then
echo "Loading configuration from .env..."
set -o allexport
source .env
set +o allexport
else
echo "Error: .env file not found. Please create one with the required variables."
exit 1
fi
# 1. Resolve Project ID
if [ -n "$GOOGLE_CLOUD_PROJECT" ]; then
PROJECT_ID="$GOOGLE_CLOUD_PROJECT"
elif [ -z "$PROJECT_ID" ]; then
PROJECT_ID=$(gcloud config get-value project 2>/dev/null)
if [ -z "$PROJECT_ID" ]; then
echo "Error: GOOGLE_CLOUD_PROJECT or PROJECT_ID not found in .env and no default project set in gcloud."
exit 1
fi
fi
echo "Using Google Cloud Project: $PROJECT_ID"
# 2. Resolve Location (Required for Vertex AI)
if [ -z "$GOOGLE_CLOUD_LOCATION" ]; then
GOOGLE_CLOUD_LOCATION="us-central1"
echo "Using default Vertex AI location: $GOOGLE_CLOUD_LOCATION"
fi
# 3. Set Defaults for Region and Service Name
REGION="${REGION:-us-central1}"
SERVICE_NAME="${SERVICE_NAME:-echo-storyteller}"
# 4. Build Frontend
echo "🎨 Building Frontend (Flutter Web) for deployment..."
(cd frontend && flutter clean && flutter pub get && flutter build web)
if [ $? -ne 0 ]; then
echo "Error: Flutter build failed."
exit 1
fi
# 5. Deploy
# Resolve Service Account
# We highly recommend using the dedicated SA created by setup_sa.sh
SA_NAME="${SERVICE_NAME}-sa"
SA_EMAIL="${SA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com"
echo "Deploying $SERVICE_NAME to $REGION in project $PROJECT_ID..."
echo "Vertex AI Location: $GOOGLE_CLOUD_LOCATION"
echo "Service Account: $SA_EMAIL"
ARGS=(
"$SERVICE_NAME"
"--source" "."
"--project" "$PROJECT_ID"
"--region" "$REGION"
"--allow-unauthenticated"
"--set-env-vars" "GOOGLE_CLOUD_PROJECT=$PROJECT_ID,GOOGLE_CLOUD_LOCATION=$GOOGLE_CLOUD_LOCATION"
)
# Check if SA exists, if so, use it
if gcloud iam service-accounts describe "$SA_EMAIL" --project "$PROJECT_ID" >/dev/null 2>&1; then
ARGS+=( "--service-account" "$SA_EMAIL" )
echo "✅ Using Service Account: $SA_EMAIL"
else
echo "⚠️ Service Account $SA_EMAIL not found. Using default Compute Engine SA."
echo " Run ./setup_sa.sh to create the dedicated SA with correct permissions."
fi
gcloud run deploy "${ARGS[@]}"