-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudbuild.yaml
86 lines (80 loc) · 2.4 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
# [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]
# Access the id_github file from Secret Manager, and setup SSH
- name: 'gcr.io/cloud-builders/git'
secretEnv: ['SSH_KEY']
entrypoint: 'bash'
args:
- -c
- |
echo "$$SSH_KEY" >> /root/.ssh/id_rsa
chmod 400 /root/.ssh/id_rsa
cp known_hosts.github /root/.ssh/known_hosts
volumes:
- name: 'ssh'
path: /root/.ssh
# This step clones the myapp1-k8s-repo repository
- name: 'gcr.io/cloud-builders/git'
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)')
volumes:
- name: 'ssh'
path: /root/.ssh
# 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
volumes:
- name: 'ssh'
path: /root/.ssh
# [END cloudbuild-trigger-cd]
availableSecrets:
secretManager:
- versionName: projects/420039265868/secrets/keneobum881-github/versions/latest
env: 'SSH_KEY'
options:
logging: CLOUD_LOGGING_ONLY