Skip to content

Commit a163fc7

Browse files
committed
add deployment script
1 parent 1df6664 commit a163fc7

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

backend/deploy.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
# Deploy script for Photo Frame Generator Cloud Function
4+
# Make sure you have gcloud CLI installed and configured
5+
6+
set -e
7+
8+
# Configuration
9+
FUNCTION_NAME="can-sentry-fix-this"
10+
REGION="us-central1"
11+
PROJECT_ID=$(gcloud config get-value project)
12+
GCS_BUCKET_NAME="sentry-fix-this-bucket"
13+
14+
echo "🚀 Deploying Photo Frame Generator Cloud Function..."
15+
echo "Project: $PROJECT_ID"
16+
echo "Region: $REGION"
17+
echo "Function: $FUNCTION_NAME"
18+
19+
# Check if gcloud is configured
20+
if [ -z "$PROJECT_ID" ]; then
21+
echo "❌ Error: gcloud is not configured. Please run 'gcloud auth login' and 'gcloud config set project YOUR_PROJECT_ID'"
22+
exit 1
23+
fi
24+
25+
# Check if GCS_BUCKET_NAME is set (we'll use Secret Manager for GEMINI_API_KEY)
26+
if [ -z "$GCS_BUCKET_NAME" ]; then
27+
echo "Using default GCS bucket name: $GCS_BUCKET_NAME"
28+
fi
29+
30+
# Verify that the GEMINI_API_KEY secret exists in Secret Manager
31+
echo "🔐 Checking GEMINI_API_KEY secret in Secret Manager..."
32+
if ! gcloud secrets describe GEMINI_API_KEY --project=$PROJECT_ID >/dev/null 2>&1; then
33+
echo "❌ Error: GEMINI_API_KEY secret not found in Secret Manager"
34+
echo "Please create the secret with: gcloud secrets create GEMINI_API_KEY --data-file=- <<< 'your_api_key_here'"
35+
exit 1
36+
fi
37+
echo "✅ GEMINI_API_KEY secret found in Secret Manager"
38+
39+
# Create GCS bucket if it doesn't exist
40+
echo "📦 Checking/creating GCS bucket..."
41+
gsutil ls -b gs://$GCS_BUCKET_NAME > /dev/null 2>&1 || gsutil mb -l $REGION gs://$GCS_BUCKET_NAME
42+
43+
# Make bucket publicly readable (for serving images)
44+
gsutil iam ch allUsers:objectViewer gs://$GCS_BUCKET_NAME
45+
46+
echo "✅ GCS bucket ready: gs://$GCS_BUCKET_NAME"
47+
48+
# Deploy the cloud function
49+
echo "🚀 Deploying cloud function..."
50+
gcloud functions deploy $FUNCTION_NAME \
51+
--gen2 \
52+
--runtime=python313 \
53+
--region=$REGION \
54+
--source=. \
55+
--entry-point=process_photo \
56+
--trigger-http \
57+
--allow-unauthenticated \
58+
--memory=2GB \
59+
--timeout=540s \
60+
--service-account="gha-cloud-functions-deployment@jeffreyhung-test.iam.gserviceaccount.com" \
61+
--set-env-vars="GCS_BUCKET_NAME=$GCS_BUCKET_NAME" \
62+
--set-secrets="GEMINI_API_KEY=GEMINI_API_KEY:latest"
63+
64+
# Get the function URL
65+
FUNCTION_URL=$(gcloud functions describe $FUNCTION_NAME --region=$REGION --gen2 --format="value(serviceConfig.uri)")
66+
67+
echo "✅ Deployment successful!"
68+
echo "🌐 Function URL: $FUNCTION_URL"
69+
echo ""
70+
echo "📝 Next steps:"
71+
echo "1. Update the frontend to use this URL: $FUNCTION_URL"
72+
echo "2. Test the function by taking a photo on your mobile device"
73+
echo "3. Check the GCS bucket for processed images"
74+
echo ""
75+
echo "🔧 To update the function, run this script again"

backend/deploy.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
runtime: python311
2+
entry_point: process_photo
3+
memory: 2GB
4+
timeout: 540s
5+
available_memory_mb: 2048
6+
source: .
7+
environment_variables:
8+
GEMINI_API_KEY: "YOUR_GEMINI_API_KEY_HERE"
9+
GCS_BUCKET_NAME: "YOUR_GCS_BUCKET_NAME_HERE"

0 commit comments

Comments
 (0)