-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcloudbuild.yaml
137 lines (127 loc) · 3.22 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
steps:
# pull image from container registry to build from cache, bypasses error if first time building image
- id: "pull docker image"
name: "gcr.io/cloud-builders/docker"
entrypoint: "sh"
args:
- "-c"
- |
docker pull gcr.io/$PROJECT_ID/dash-cloudrun-demo:latest || true
# build docker image in target project with git commit tag and latest
# cache the previous build as a starting point for subsequent builds
- id: "build docker image from cache"
name: "gcr.io/cloud-builders/docker"
args:
[
"build",
"-t",
"gcr.io/$PROJECT_ID/dash-cloudrun-demo:${SHORT_SHA}",
"-t",
"gcr.io/$PROJECT_ID/dash-cloudrun-demo:latest",
"--cache-from",
"gcr.io/$PROJECT_ID/dash-cloudrun-demo:latest",
".",
]
# push docker image with git commit to container registry
- id: "push docker image"
name: "gcr.io/cloud-builders/docker"
args: ["push", "gcr.io/$PROJECT_ID/dash-cloudrun-demo"]
- id: "download encrypted secrets only during build"
name: "gcr.io/cloud-builders/gsutil"
args:
[
"cp",
"gs://$PROJECT_ID-secure-bucket-secrets/ciphertext_file.enc",
"ciphertext_file.enc",
]
- id: "decrypt secrets only during build"
name: "gcr.io/cloud-builders/gcloud"
args:
[
"kms",
"decrypt",
"--ciphertext-file",
"ciphertext_file.enc",
"--plaintext-file",
"service_account.json",
"--location",
"global",
"--keyring",
"$PROJECT_ID-keyring",
"--key",
"$PROJECT_ID-key",
]
###############################################
# deploy terraform infrastructure
- id: "branch name"
name: "alpine"
entrypoint: "sh"
args:
- "-c"
- |
echo "***********************"
echo "$BRANCH_NAME"
echo "***********************"
- id: "tf init"
name: "hashicorp/terraform:0.12.9"
entrypoint: "sh"
args:
- "-c"
- |
cd tf_modules/
terraform init
# [START tf-plan]
- id: "tf plan"
name: "hashicorp/terraform:0.12.9"
entrypoint: "sh"
args:
- "-c"
- |
cd tf_modules/
terraform plan
# [END tf-plan]
# [START tf-apply]
- id: "tf apply"
name: "hashicorp/terraform:0.12.9"
entrypoint: "sh"
args:
- "-c"
- |
cd tf_modules/
terraform apply -auto-approve
# [END tf-apply]
# must set cloudbuild service account with Cloud Run Admin role
- id: "allow cloud run unauthenticated"
name: "gcr.io/cloud-builders/gcloud"
args:
[
"beta",
"run",
"services",
"add-iam-policy-binding",
"tf-dash-cloud-run-demo",
"--member",
"allUsers",
"--region",
"us-central1",
"--role",
"roles/run.invoker",
"--platform",
"managed",
]
- id: "upgrade container memory limit"
name: "gcr.io/cloud-builders/gcloud"
args:
[
"beta",
"run",
"services",
"update",
"tf-dash-cloud-run-demo",
"--memory",
"1Gi",
"--region",
"us-central1",
"--platform",
"managed",
]