-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudbuild.yaml
More file actions
92 lines (85 loc) · 2.54 KB
/
cloudbuild.yaml
File metadata and controls
92 lines (85 loc) · 2.54 KB
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
steps:
# Build the container image:
- name: 'gcr.io/cloud-builders/docker'
id: Build Image
args:
- 'build'
- '-t'
- 'gcr.io/$PROJECT_ID/pumba-validator:$SHORT_SHA'
- '.'
# Push the image to Container Registry (Currently Google)
# The PROJECT_ID and SHORT_SHA variables are automatically
# replaced by Cloud Build.
- name: 'gcr.io/cloud-builders/docker'
id: Push Image
args:
- 'push'
- 'gcr.io/$PROJECT_ID/pumba-validator:$SHORT_SHA'
# Access the id_github file from Secret Manager
# TODO: Create a key to github for this project
- name: gcr.io/cloud-builders/gcloud
id: Get ssh key
entrypoint: 'bash'
args: [ '-c', 'gcloud secrets versions access latest --secret=pumba-github > /root/.ssh/id_github' ]
volumes:
- name: 'ssh'
path: /root/.ssh
# Set up git with key and domain
- name: 'gcr.io/cloud-builders/gcloud'
id: Store ssh key
entrypoint: /bin/sh
args:
- '-c'
- |
chmod 600 /root/.ssh/id_github
cat <<EOF >/root/.ssh/config
Hostname github.com
IdentityFile /root/.ssh/id_github
EOF
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts
volumes:
- name: 'ssh'
path: /root/.ssh
# Connect to the repository
- name: 'gcr.io/cloud-builders/gcloud'
id: Clone main repository
entrypoint: /bin/sh
args:
- '-c'
- |
set -x && \
# Configure Git to create commits with Cloud Build's service account
git config user.email $(gcloud auth list --filter=status:ACTIVE --format='value(account)') && \
git clone git@github.com:linux-devops-opensource/pumba.git && \
cd pumba && \
git checkout main && \
git config user.email $(gcloud auth list --filter=status:ACTIVE --format='value(account)')
volumes:
- name: 'ssh'
path: /root/.ssh
# Generate the new manifest
- name: 'gcr.io/cloud-builders/gcloud'
id: Generate manifest
entrypoint: /bin/sh
args:
- '-c'
- |
sed "s/GOOGLE_CLOUD_PROJECT/${PROJECT_ID}/g" kubernetes.yaml.tpl | \
sed "s/COMMIT_SHA/${SHORT_SHA}/g" > pumba/manifests/pumba-validator/deployment.yaml
# This step pushes the manifest back to hello-cloudbuild-env
- name: 'gcr.io/cloud-builders/gcloud'
id: Add the new manifest
entrypoint: /bin/sh
args:
- '-c'
- |
set -x && \
cd pumba && \
git add manifests/pumba-validator/deployment.yaml && \
git commit -m "Deploying image gcr.io/${PROJECT_ID}/pumba-validator:${SHORT_SHA}
Built from commit ${COMMIT_SHA} of repository pumba-validator
Author: $(git log --format='%an <%ae>' -n 1 HEAD)" && \
git push origin main
volumes:
- name: 'ssh'
path: /root/.ssh