forked from kids-reporter/kids-reporter-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudbuild.yaml
98 lines (79 loc) · 2.87 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
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
steps:
# Temporarily disable kaniko cache approach due to unexpected build errors.
#
# build docker image for target sub-pacakge
# use debug tag so that we can use `sh` entrypoint
#- name: 'gcr.io/kaniko-project/executor:debug'
# id: Build Image
# entrypoint: 'sh'
# args:
# - '-c'
# - |
# cp yarn.lock packages/$_TARGET_PACKAGE
# cd packages/$_TARGET_PACKAGE
# /kaniko/executor --context="$(pwd)" --cache=true --cache-ttl=48h --destination=gcr.io/$PROJECT_ID/$_IMAGE_NAME:${BRANCH_NAME}_${SHORT_SHA}
# Pull previous image
- name: gcr.io/cloud-builders/docker
args:
- '-c'
- 'docker pull gcr.io/$PROJECT_ID/$_IMAGE_NAME:latest || exit 0'
entrypoint: bash
# Build image
- name: gcr.io/cloud-builders/docker
args:
- '-c'
- >
cp yarn.lock packages/$_TARGET_PACKAGE
cd packages/$_TARGET_PACKAGE
echo "copy $_ENV_FILE to .env.local"
cp $_ENV_FILE .env.local
docker build -t \
gcr.io/$PROJECT_ID/$_IMAGE_NAME:${BRANCH_NAME}_${SHORT_SHA} \
-t gcr.io/$PROJECT_ID/$_IMAGE_NAME:latest \
--cache-from gcr.io/$PROJECT_ID/$_IMAGE_NAME:latest .
entrypoint: bash
# Push container image to registry
- name: gcr.io/cloud-builders/docker
args:
- push
- 'gcr.io/$PROJECT_ID/$_IMAGE_NAME:${BRANCH_NAME}_${SHORT_SHA}'
# Deploy container image to Cloud Runs
- name: gcr.io/cloud-builders/gcloud
id: Deploy Image
entrypoint: 'bash'
args:
- '-c'
- |
# read cloud run service names from substitution variable
IFS=',' read -r -a cloud_runs <<< "$_CLOUD_RUN_SERVICE_NAMES"
for cr in "${cloud_runs[@]}"
do
# check if _DEPLOYMENT_TYPE is 'job'
if [[ "$_DEPLOYMENT_TYPE" == "job" ]]; then
# check if job exists
if gcloud run jobs describe "$cr" --region asia-east1 &> /dev/null; then
# update cloud run job
gcloud run jobs update "$cr" --image gcr.io/$PROJECT_ID/$_IMAGE_NAME:${BRANCH_NAME}_${SHORT_SHA} --region asia-east1
else
# create cloud run job
gcloud run jobs create "$cr" --image gcr.io/$PROJECT_ID/$_IMAGE_NAME:${BRANCH_NAME}_${SHORT_SHA} --region asia-east1
fi
else
# deploy cloud run service
gcloud run deploy "$cr" --image gcr.io/$PROJECT_ID/$_IMAGE_NAME:${BRANCH_NAME}_${SHORT_SHA} --region asia-east1
fi
done
# Push container image to registry to update the latest one
- name: gcr.io/cloud-builders/docker
args:
- push
- 'gcr.io/$PROJECT_ID/$_IMAGE_NAME:latest'
timeout: 2400s
options:
logging: CLOUD_LOGGING_ONLY
substitutions:
_TARGET_PACKAGE: '' # default value
_IMAGE_NAME: '' # default value
_CLOUD_RUN_SERVICE_NAMES: '' # default value
_ENV_FILE: '' # default value
_DEPLOYMENT_TYPE: 'service' # default value