forked from christophersanson/gcb-gke-codelab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudbuild.yaml
51 lines (44 loc) · 1.48 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
steps:
# Build the image
- id: 'Build docker image'
name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/$_APP_NAME:$SHORT_SHA', '.' ]
# Push updated image
- id: 'Push image to registry'
name: 'gcr.io/cloud-builders/docker'
args: [ 'push', 'gcr.io/$PROJECT_ID/$_APP_NAME:$SHORT_SHA' ]
# Patch the Deployment
- id: 'Patch manifest with new image'
name: 'gcr.io/cloud-builders/kubectl'
entrypoint: 'sh'
env:
- 'CLOUDSDK_COMPUTE_ZONE=${_CLOUDSDK_COMPUTE_ZONE}'
- 'CLOUDSDK_CONTAINER_CLUSTER=${_CLOUDSDK_CONTAINER_CLUSTER}'
args:
- '-c'
- |
gcloud container clusters get-credentials \
--project="${PROJECT_ID}" --zone="${_CLOUDSDK_COMPUTE_ZONE}" "${_CLOUDSDK_CONTAINER_CLUSTER}"
cat <<EOF > patch.yaml
spec:
template:
spec:
containers:
- name: ${_APP_NAME}
image: gcr.io/${PROJECT_ID}/${_APP_NAME}:${SHORT_SHA}
EOF
kubectl patch --local -o yaml \
-f k8s/deployment.yaml \
-p "$(cat patch.yaml)" \
> deployment.yaml
mv deployment.yaml k8s/deployment.yaml
# Apply change
- id: 'Apply update to cluster'
name: 'gcr.io/cloud-builders/kubectl'
args: [ 'apply', '-f', 'k8s/']
env:
- 'CLOUDSDK_COMPUTE_ZONE=${_CLOUDSDK_COMPUTE_ZONE}'
- 'CLOUDSDK_CONTAINER_CLUSTER=${_CLOUDSDK_CONTAINER_CLUSTER}'
# Associate image that was pushed to GCR with the build history UI
images:
- 'gcr.io/$PROJECT_ID/$_APP_NAME:$SHORT_SHA'