-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudbuild.yaml
More file actions
81 lines (73 loc) · 3.07 KB
/
cloudbuild.yaml
File metadata and controls
81 lines (73 loc) · 3.07 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
steps:
# 1. Build the API image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'us-central1-docker.pkg.dev/$PROJECT_ID/explainflow-repo/explainflow-api:latest', '-f', 'api/Dockerfile', '.']
# 2. Push the API image
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'us-central1-docker.pkg.dev/$PROJECT_ID/explainflow-repo/explainflow-api:latest']
# 3. Deploy API to Cloud Run (Serverless, Fully Managed)
# This uses the image we just built. It sets the timeout to 300s (critical for multimodal streaming).
# We fetch the API key from Secret Manager (which must be created via Terraform or manually first).
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
args:
- 'run'
- 'deploy'
- 'explainflow-api'
- '--image'
- 'us-central1-docker.pkg.dev/$PROJECT_ID/explainflow-repo/explainflow-api:latest'
- '--region'
- 'us-central1'
- '--allow-unauthenticated'
- '--timeout'
- '300'
- '--memory'
- '2Gi'
- '--cpu'
- '2'
- '--min-instances'
- '1'
- '--set-env-vars'
- 'EXPLAINFLOW_BUCKET=explainflow-assets-$PROJECT_ID'
- '--set-secrets'
- 'GEMINI_API_KEY=explainflow-gemini-api-key:latest,RATE_LIMIT_BYPASS_KEY=explainflow-rate-limit-bypass-key:latest'
# 4. Fetch the deployed API URL and bypass key for the Web build
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: 'bash'
args:
- '-c'
- |
API_URL=$(gcloud run services describe explainflow-api --region us-central1 --format 'value(status.url)')
echo "Found API_URL: $$API_URL"
echo "$$API_URL" > /workspace/api_url.txt
BYPASS_KEY=$(gcloud secrets versions access latest --secret=explainflow-rate-limit-bypass-key 2>/dev/null || echo "")
echo "$$BYPASS_KEY" > /workspace/bypass_key.txt
# 5. Build the Web image, dynamically injecting the API URL and bypass key
- name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
API_URL=$$(cat /workspace/api_url.txt)
BYPASS_KEY=$$(cat /workspace/bypass_key.txt)
docker build -t us-central1-docker.pkg.dev/$PROJECT_ID/explainflow-repo/explainflow-web:latest -f web/Dockerfile --build-arg NEXT_PUBLIC_API_URL="$$API_URL" --build-arg NEXT_PUBLIC_RATE_LIMIT_BYPASS_KEY="$$BYPASS_KEY" .
# 6. Push the Web image
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'us-central1-docker.pkg.dev/$PROJECT_ID/explainflow-repo/explainflow-web:latest']
# 7. Deploy Web to Cloud Run
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
args:
- 'run'
- 'deploy'
- 'explainflow-web'
- '--image'
- 'us-central1-docker.pkg.dev/$PROJECT_ID/explainflow-repo/explainflow-web:latest'
- '--region'
- 'us-central1'
- '--allow-unauthenticated'
options:
logging: CLOUD_LOGGING_ONLY
images:
- 'us-central1-docker.pkg.dev/$PROJECT_ID/explainflow-repo/explainflow-api:latest'
- 'us-central1-docker.pkg.dev/$PROJECT_ID/explainflow-repo/explainflow-web:latest'