-
Notifications
You must be signed in to change notification settings - Fork 1
/
cloudbuild.yaml
141 lines (120 loc) · 3.94 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
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
timeout: 3000s
# If you want to grant outsiders access to your build logs, you may save
# the logs to a separate bucket determined by the logsBucket setting and
# grant the outsiders access to the bucket
# logsBucket: 'gs://my-builds' # TODO _TEMPLATE_DEFAULT for this also
options:
# You can give CI/CD more cpu/mem with machineType
# machineType: N1_HIGHCPU_8
substitutions:
_REPO_NAME: website-template
_IMAGE_REGISTRY: eu.gcr.io/$PROJECT_ID
_TAITO_CI_PHASES:
_VC_TOKEN:
steps:
# NOTE: This first step is an optimization. We execute CI/CD build cancel with
# the google provided gcloud container instead of Taito CLI, because it
# doesn't need to be pulled before execution -> cancel executes immediately.
- id: manual-cancel
name: "gcr.io/cloud-builders/gcloud"
entrypoint: "bash"
env:
- build_id=$BUILD_ID
- repo_name=$_REPO_NAME
- branch_name=$BRANCH_NAME
args:
- "-c"
- |
export taito_target_env="$${branch_name//master/prod}"
source ./taito-config.sh
echo "- Cancel all previous ongoing builds targetting the same branch"
gcloud builds list \
--format="table[no-heading](id)" \
--ongoing \
--filter=" \
substitutions._REPO_NAME='$${repo_name}' AND \
substitutions.BRANCH_NAME='$${branch_name}'" | \
grep -v "$${build_id}" | \
xargs gcloud builds cancel 2> /dev/null || :
# ----------------------- Taito CLI ----------------------------------
# Prepare build
- id: build-prepare
waitFor: ["-"]
name: "${_TEMPLATE_DEFAULT_TAITO_IMAGE}"
args: ["build-prepare:$BRANCH_NAME", "$COMMIT_SHA"]
env:
- taito_mode=ci
- taito_ci_phases=${_TAITO_CI_PHASES}
- VC_TOKEN=${_VC_TOKEN}
# Build artifacts in parallel
- id: artifact-prepare-www
name: "${_TEMPLATE_DEFAULT_TAITO_IMAGE}"
args: ["artifact-prepare:www:$BRANCH_NAME", "$COMMIT_SHA"]
env:
- taito_mode=ci
- taito_ci_phases=${_TAITO_CI_PHASES}
- id: artifact-prepare-webhook
name: "${_TEMPLATE_DEFAULT_TAITO_IMAGE}"
args:
[
"artifact-prepare:webhook:$BRANCH_NAME",
"$COMMIT_SHA",
"",
"false",
"./www",
"./www",
"Dockerfile.webhook",
]
env:
- taito_mode=ci
- taito_ci_phases=${_TAITO_CI_PHASES}
# Deploy to target environment
- id: deployment-deploy
name: "${_TEMPLATE_DEFAULT_TAITO_IMAGE}"
args: ["deployment-deploy:$BRANCH_NAME", "$COMMIT_SHA"]
env:
- taito_mode=ci
- taito_ci_phases=${_TAITO_CI_PHASES}
# Test and verify deployment
- id: deployment-wait
name: "${_TEMPLATE_DEFAULT_TAITO_IMAGE}"
args: ["deployment-wait:$BRANCH_NAME"]
env:
- taito_mode=ci
- taito_ci_phases=${_TAITO_CI_PHASES}
- id: test
name: "${_TEMPLATE_DEFAULT_TAITO_IMAGE}"
args: ["test:$BRANCH_NAME"]
env:
- taito_mode=ci
- taito_ci_phases=${_TAITO_CI_PHASES}
- taito_image=${_TEMPLATE_DEFAULT_TAITO_IMAGE}
- id: deployment-verify
name: "${_TEMPLATE_DEFAULT_TAITO_IMAGE}"
args: ["deployment-verify:$BRANCH_NAME"]
env:
- taito_mode=ci
- taito_ci_phases=${_TAITO_CI_PHASES}
# Release artifacts in parallel
- id: artifact-release-www
waitFor: ["deployment-verify"]
name: "${_TEMPLATE_DEFAULT_TAITO_IMAGE}"
args: ["artifact-release:www:$BRANCH_NAME", "$COMMIT_SHA"]
env:
- taito_mode=ci
- taito_ci_phases=${_TAITO_CI_PHASES}
- id: artifact-release-webhook
waitFor: ["deployment-verify"]
name: "${_TEMPLATE_DEFAULT_TAITO_IMAGE}"
args: ["artifact-release:webhook:$BRANCH_NAME", "$COMMIT_SHA"]
env:
- taito_mode=ci
- taito_ci_phases=${_TAITO_CI_PHASES}
# Release build
- id: build-release
name: "${_TEMPLATE_DEFAULT_TAITO_IMAGE}"
args: ["build-release:$BRANCH_NAME"]
env:
- taito_mode=ci
- taito_ci_phases=${_TAITO_CI_PHASES}
- VC_TOKEN=${_VC_TOKEN}