forked from mirror-media/Adam
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudbuild.yaml
More file actions
86 lines (67 loc) · 2.35 KB
/
cloudbuild.yaml
File metadata and controls
86 lines (67 loc) · 2.35 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
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
env:
- 'NEXT_PUBLIC_ENV=${BRANCH_NAME}'
- 'NEXT_PUBLIC_IS_PREVIEW_MODE=$_IS_PREVIEW_MODE'
args:
- '-c'
- >
cp yarn.lock packages/$_TARGET_PACKAGE
cd packages/$_TARGET_PACKAGE
echo "print environment variables and output to file"
printenv | tee .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
# deploy cloud run service iteratively
gcloud run deploy "$cr" --image gcr.io/$PROJECT_ID/$_IMAGE_NAME:${BRANCH_NAME}_${SHORT_SHA} --region asia-east1
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: 1800s
substitutions:
_TARGET_PACKAGE: '' # default value
_IMAGE_NAME: '' # default value
_CLOUD_RUN_SERVICE_NAMES: '' # default value
_IS_PREVIEW_MODE: 'false' # default value