-
Notifications
You must be signed in to change notification settings - Fork 364
/
cloudbuild.yaml
56 lines (54 loc) · 2.21 KB
/
cloudbuild.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
substitutions:
_GCP_PROJECT_ID: <GCP_PROJECT_ID>
_GCP_REGION: <GCP_REGION>
_DATABASE_URL: <DB_CONNECTION_STRING>
_COHERE_API_KEY: <COHERE_API_KEY>
steps:
# 1. BACKEND STEPS
# a) Build backend container image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$_GCP_PROJECT_ID/toolkit-backend', '-f', 'gcp.backend.Dockerfile', '.', '--build-arg', 'DATABASE_URL=$_DATABASE_URL']
# b) Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$_GCP_PROJECT_ID/toolkit-backend']
# c) Deploy container image to Cloud Run
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
args: ['run', 'deploy', 'toolkit-backend',
'--image', 'gcr.io/$_GCP_PROJECT_ID/toolkit-backend',
'--region', '$_GCP_REGION',
'--port', '8000',
'--set-env-vars', 'DATABASE_URL=$_DATABASE_URL',
'--set-env-vars', 'COHERE_API_KEY=$_COHERE_API_KEY',
'--allow-unauthenticated'
]
# d) Get the URL of the deployed backend service
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
gcloud run services describe toolkit-backend --platform managed --region $_GCP_REGION --format 'value(status.url)' > /workspace/backend_url.txt
# e) Apply backend Alembic migrations
- name: gcr.io/cloud-builders/curl
entrypoint: bash
args:
- '-c'
- 'curl -X POST "$(cat /workspace/backend_url.txt)/migrate"'
# 2. FRONTEND STEPS
# a) Build frontend container image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$_GCP_PROJECT_ID/toolkit-frontend', '-f', 'gcp.frontend.Dockerfile', 'src/interfaces/coral_web']
# b) Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$_GCP_PROJECT_ID/toolkit-frontend']
# c) Deploy container image to Cloud Run
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
gcloud run deploy toolkit-frontend --port 4000 --memory 2Gi --image gcr.io/$_GCP_PROJECT_ID/toolkit-frontend --region $_GCP_REGION --allow-unauthenticated --set-env-vars NEXT_PUBLIC_API_HOSTNAME=$(cat /workspace/backend_url.txt)
images:
- gcr.io/$_GCP_PROJECT_ID/toolkit-backend
- gcr.io/$_GCP_PROJECT_ID/toolkit-frontend