-
Notifications
You must be signed in to change notification settings - Fork 2
/
cloudbuild-frontend-staging.yaml
71 lines (66 loc) · 2.15 KB
/
cloudbuild-frontend-staging.yaml
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
steps:
# Set the PR_BUILD flag
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
if [ "$_PR_BUILD" == "true" ]; then
echo "true" > /workspace/PR_BUILD.txt
else
echo "false" > /workspace/PR_BUILD.txt
fi
id: 'set-pr-build-flag-staging'
# Build the frontend Docker image
- name: 'gcr.io/cloud-builders/docker'
args: [
'build',
'--build-arg',
'ENVIRONMENT=staging',
'--build-arg',
'GOOGLE_ANALYTICS_ID=$_GOOGLE_ANALYTICS_ID',
'-t',
'gcr.io/$PROJECT_ID/frontend:$SHORT_SHA',
'./frontend/'
]
id: 'build-frontend-image-staging'
# Push the frontend Docker image to Google Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/frontend:$SHORT_SHA']
id: 'push-frontend-image-staging'
# Deploy the frontend to Google Cloud Run
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
if [ "$(cat /workspace/PR_BUILD.txt)" == "false" ]; then
gcloud run deploy instruct-multilingual-frontend-staging \
--image gcr.io/$PROJECT_ID/frontend:$SHORT_SHA \
--project $PROJECT_ID \
--region ${_REGION} \
--platform managed \
--allow-unauthenticated \
--concurrency 5 \
--cpu 1 \
--memory 2Gi \
--min-instances 2 \
--max-instances 3 \
--set-env-vars ENVIRONMENT=staging,BACKEND_URL=https://instruct-multilingual-backend-staging-dtjnk4f6ra-ue.a.run.app
echo $(gcloud run services describe instruct-multilingual-frontend-staging --platform managed --region ${_REGION} --format 'value(status.url)') > /workspace/FRONTEND_URL.txt
fi
id: 'deploy-frontend-staging'
timeout: '600s'
# Update the backend with the correct FRONTEND_URL
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
if [ "$(cat /workspace/PR_BUILD.txt)" == "false" ]; then
gcloud run services update instruct-multilingual-backend-staging \
--region ${_REGION} \
--platform managed \
--update-env-vars FRONTEND_URL="$(cat /workspace/FRONTEND_URL.txt)"
fi
id: 'update-backend-frontend-url-staging'