-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudbuild-trigger-cd.yaml
86 lines (77 loc) · 2.33 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
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
steps:
# Install dependenies and run tests
- name: "python:3.7-slim"
id: Test
entrypoint: 'bash'
args: ['./scripts/install-app-dependencies.sh', '&&', './scripts/test-app.sh']
# Docker build
- name: "gcr.io/cloud-builders/docker"
id: Build
entrypoint: 'bash'
args: ['./scripts/build-docker-image.sh']
env:
- 'PROJECT_ID=${PROJECT_ID}'
- 'LOCATION=${LOCATION}'
- 'SHORT_SHA=${SHORT_SHA}'
# Docker push to Artifact Registry
- name: "gcr.io/cloud-builders/gcloud"
id: Push
entrypoint: 'bash'
args: ['./scripts/check-artifact-registry-repo-or-create-one.sh', '&&', '.scripts/push-image.sh']
env:
- 'PROJECT_ID=${PROJECT_ID}'
- 'LOCATION=${LOCATION}'
- 'SHORT_SHA=${SHORT_SHA}'
# Access the id_github file from Secret Manager, and setup SSH
- name: 'gcr.io/cloud-builders/git'
id: Read Secret Manager
secretEnv: ['SSH_KEY']
entrypoint: 'bash'
args:
- -c
- |
echo "$$SSH_KEY" >> /root/.ssh/id_rsa
chmod 400 /root/.ssh/id_rsa
ssh-keyscan -t rsa github.com > known_hosts.github
mv known_hosts.github /root/.ssh/known_hosts
volumes:
- name: 'ssh'
path: /root/.ssh
# Clones the env repo
- name: "gcr.io/cloud-builders/git"
id: Clone env repo
entrypoint: 'bash'
args: ['./scripts/clone-env-repo.sh']
volumes:
- name: 'ssh'
path: /root/.ssh
# This step generates the new manifest
- name: 'gcr.io/cloud-builders/gcloud'
id: Generate manifest
entrypoint: 'bash'
args: ['./scripts/generate-new-manifest.sh']
env:
- 'PROJECT_ID=${PROJECT_ID}'
- 'LOCATION=${LOCATION}'
- 'SHORT_SHA=${SHORT_SHA}'
volumes:
- name: 'ssh'
path: /root/.ssh
# This step pushes the manifest back to hello-cloudbuild-env
- name: 'gcr.io/cloud-builders/gcloud'
id: Push manifest
entrypoint: 'bash'
args: ['./scripts/pushes-manifest-back-to-env-repo.sh']
env:
- 'PROJECT_ID=${PROJECT_ID}'
- 'LOCATION=${LOCATION}'
- 'SHORT_SHA=${SHORT_SHA}'
volumes:
- name: 'ssh'
path: /root/.ssh
images:
- '${LOCATION}-docker.pkg.dev/${PROJECT_ID}/my-repository/hello-cloudbuild:${SHORT_SHA}'
availableSecrets:
secretManager:
- versionName: projects/${PROJECT_ID}/secrets/cloudbuild-github-secret-key/versions/latest
env: 'SSH_KEY'