-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudbuild-trigger-cd.yaml
61 lines (57 loc) · 1.85 KB
/
cloudbuild-trigger-cd.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
# [START cloudbuild - Docker Image Build]
steps:
# This step builds the container image.
- name: 'gcr.io/cloud-builders/docker'
id: Build
args:
- 'build'
- '-t'
- 'us-central1-docker.pkg.dev/$PROJECT_ID/myapps-repository/myapp1:$SHORT_SHA'
- '.'
# This step pushes the image to Artifact Registry
# The PROJECT_ID and SHORT_SHA variables are automatically
# replaced by Cloud Build.
- name: 'gcr.io/cloud-builders/docker'
id: Push
args:
- 'push'
- 'us-central1-docker.pkg.dev/$PROJECT_ID/myapps-repository/myapp1:$SHORT_SHA'
# [END cloudbuild - Docker Image Build]
# [START cloudbuild-trigger-cd]
# This step clones the myapp1-k8s-repo repository
- name: 'gcr.io/cloud-builders/gcloud'
id: Clone myapp1-k8s-repo repository
entrypoint: /bin/sh
args:
- '-c'
- |
git clone git@github.com:keneobum881/myapp1-k8s-repo.git && \
cd myapp1-k8s-repo && \
git checkout candidate && \
git config user.email $(gcloud auth list --filter=status:ACTIVE --format='value(account)')
# This step generates the new manifest
- name: 'gcr.io/cloud-builders/gcloud'
id: Generate Kubernetes manifest
entrypoint: /bin/sh
args:
- '-c'
- |
sed "s/GOOGLE_CLOUD_PROJECT/${PROJECT_ID}/g" kubernetes.yaml.tpl | \
sed "s/COMMIT_SHA/${SHORT_SHA}/g" > myapp1-k8s-repo/kubernetes.yaml
# This step pushes the manifest back to myapp1-k8s-repo
- name: 'gcr.io/cloud-builders/gcloud'
id: Push manifest
entrypoint: /bin/sh
args:
- '-c'
- |
set -x && \
cd myapp1-k8s-repo && \
git add kubernetes.yaml && \
git commit -m "Deploying image us-central1-docker.pkg.dev/$PROJECT_ID/myapps-repository/myapp1:${SHORT_SHA}
Built from commit ${COMMIT_SHA} of repository myapp1-app-repo
Author: $(git log --format='%an <%ae>' -n 1 HEAD)" && \
git push origin candidate
# [END cloudbuild-trigger-cd]
options:
logging: CLOUD_LOGGING_ONLY