-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudbuild.yaml
More file actions
152 lines (141 loc) · 4.52 KB
/
Copy pathcloudbuild.yaml
File metadata and controls
152 lines (141 loc) · 4.52 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Cloud Build deploys the production Go API and Python ML service to Cloud Run.
#
# Expected Cloud Build trigger substitutions:
# _CORS_ORIGINS Required for browser callers. Defaults to the current Vercel URL.
#
# Expected Secret Manager secrets:
# database-url Supabase/Postgres connection string used by the API
#
# Expected Artifact Registry repo:
# ${_REGION}-docker.pkg.dev/$PROJECT_ID/${_AR_REPO}
substitutions:
_REGION: asia-northeast1
_AR_REPO: daimon
_API_SERVICE: daimon-api
_ML_SERVICE: daimon-ml
_CORS_ORIGINS: https://daimon-sandy.vercel.app
_API_CPU: "1"
_API_MEMORY: 512Mi
_API_MIN_INSTANCES: "0"
_API_MAX_INSTANCES: "1"
_ML_CPU: "2"
_ML_MEMORY: 2Gi
_ML_MIN_INSTANCES: "0"
_ML_MAX_INSTANCES: "1"
_ML_INGRESS: all
options:
logging: CLOUD_LOGGING_ONLY
machineType: E2_MEDIUM
steps:
- id: validate-config
name: gcr.io/google.com/cloudsdktool/cloud-sdk:slim
entrypoint: bash
args:
- -ceu
- |
test -n "${_CORS_ORIGINS}" || {
echo "Missing required Cloud Build substitution: _CORS_ORIGINS" >&2
exit 1
}
- id: build-ml
name: gcr.io/cloud-builders/docker
entrypoint: bash
args:
- -ceu
- |
IMAGE="${_REGION}-docker.pkg.dev/$PROJECT_ID/${_AR_REPO}/daimon-ml"
docker pull "$${IMAGE}:latest" || true
docker build \
--cache-from "$${IMAGE}:latest" \
-t "$${IMAGE}:$SHORT_SHA" \
-t "$${IMAGE}:latest" \
ml-service
- id: push-ml
name: gcr.io/cloud-builders/docker
entrypoint: bash
args:
- -ceu
- |
IMAGE="${_REGION}-docker.pkg.dev/$PROJECT_ID/${_AR_REPO}/daimon-ml"
docker push "$${IMAGE}:$SHORT_SHA"
docker push "$${IMAGE}:latest"
- id: deploy-ml
name: gcr.io/google.com/cloudsdktool/cloud-sdk:slim
entrypoint: gcloud
args:
- run
- deploy
- ${_ML_SERVICE}
- --image=${_REGION}-docker.pkg.dev/$PROJECT_ID/${_AR_REPO}/daimon-ml:$SHORT_SHA
- --region=${_REGION}
- --platform=managed
- --port=8001
- --cpu=${_ML_CPU}
- --memory=${_ML_MEMORY}
- --min=${_ML_MIN_INSTANCES}
- --max=${_ML_MAX_INSTANCES}
- --ingress=${_ML_INGRESS}
- --startup-probe=tcpSocket.port=8001,periodSeconds=10,timeoutSeconds=10,failureThreshold=60
- --no-allow-unauthenticated
- --cpu-throttling
- --no-cpu-boost
- id: capture-ml-url
name: gcr.io/google.com/cloudsdktool/cloud-sdk:slim
entrypoint: bash
args:
- -ceu
- |
gcloud run services describe "${_ML_SERVICE}" \
--region="${_REGION}" \
--format='value(status.url)' > /workspace/ml-url.txt
test -s /workspace/ml-url.txt
echo "ML service URL: $(cat /workspace/ml-url.txt)"
- id: build-api
name: gcr.io/cloud-builders/docker
entrypoint: bash
args:
- -ceu
- |
IMAGE="${_REGION}-docker.pkg.dev/$PROJECT_ID/${_AR_REPO}/daimon-api"
docker pull "$${IMAGE}:latest" || true
docker build \
--cache-from "$${IMAGE}:latest" \
-t "$${IMAGE}:$SHORT_SHA" \
-t "$${IMAGE}:latest" \
api
- id: push-api
name: gcr.io/cloud-builders/docker
entrypoint: bash
args:
- -ceu
- |
IMAGE="${_REGION}-docker.pkg.dev/$PROJECT_ID/${_AR_REPO}/daimon-api"
docker push "$${IMAGE}:$SHORT_SHA"
docker push "$${IMAGE}:latest"
- id: deploy-api
name: gcr.io/google.com/cloudsdktool/cloud-sdk:slim
entrypoint: bash
args:
- -ceu
- |
ML_URL="$(cat /workspace/ml-url.txt)"
gcloud run deploy "${_API_SERVICE}" \
--image="${_REGION}-docker.pkg.dev/$PROJECT_ID/${_AR_REPO}/daimon-api:$SHORT_SHA" \
--region="${_REGION}" \
--platform=managed \
--port=8000 \
--cpu="${_API_CPU}" \
--memory="${_API_MEMORY}" \
--min="${_API_MIN_INSTANCES}" \
--max="${_API_MAX_INSTANCES}" \
--ingress=all \
--allow-unauthenticated \
--cpu-throttling \
--no-cpu-boost \
--set-env-vars="^|^EMBED_URL=$${ML_URL}|EMBED_AUTH=true|CORS_ORIGINS=${_CORS_ORIGINS}" \
--set-secrets="DATABASE_URL=database-url:latest"
images:
- ${_REGION}-docker.pkg.dev/$PROJECT_ID/${_AR_REPO}/daimon-api:$SHORT_SHA
- ${_REGION}-docker.pkg.dev/$PROJECT_ID/${_AR_REPO}/daimon-api:latest
- ${_REGION}-docker.pkg.dev/$PROJECT_ID/${_AR_REPO}/daimon-ml:$SHORT_SHA
- ${_REGION}-docker.pkg.dev/$PROJECT_ID/${_AR_REPO}/daimon-ml:latest