-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudbuild.yaml
101 lines (88 loc) · 2.44 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
87
88
89
90
91
92
93
94
95
96
97
98
substitutions:
_TWO_PART_VERSION: "0.1"
_GITHUB_USERNAME: "chrisguest75"
_CONTAINER_SUBFOLDER: "simple_api_server"
steps:
# Show some debug info - current state of folder.
- name: 'gcr.io/cloud-builders/git'
entrypoint: '/bin/bash'
args:
- '-c'
- |
pwd
ls -la
echo ${_GITHUB_USERNAME}
echo ${_TWO_PART_VERSION}
# Decrypt the ssh key.
- name: 'gcr.io/cloud-builders/gcloud'
args:
- kms
- decrypt
- --ciphertext-file=cloudbuild_ssh.key.enc
- --plaintext-file=/root/.ssh/id_rsa
- --location=global
- --keyring=cloudbuild-keyring
- --key=github-key
volumes:
- name: 'ssh'
path: /root/.ssh
# Modify known hosts.
- name: 'gcr.io/cloud-builders/git'
entrypoint: '/bin/bash'
args:
- '-c'
- |
chmod 600 /root/.ssh/id_rsa
cat <<EOF >/root/.ssh/config
Hostname github.com
IdentityFile /root/.ssh/id_rsa
EOF
mv known_hosts /root/.ssh/known_hosts
volumes:
- name: 'ssh'
path: /root/.ssh
# Use git clone to get private repo.
- name: 'gcr.io/cloud-builders/git'
args:
- clone
- git@github.com:${_GITHUB_USERNAME}/$REPO_NAME
volumes:
- name: 'ssh'
path: /root/.ssh
# Build the dockerfile with the latest cloned code.
- name: 'gcr.io/cloud-builders/docker'
args:
- 'build'
- '--tag=gcr.io/$PROJECT_ID/$REPO_NAME:latest'
- '--file=./${_CONTAINER_SUBFOLDER}/Dockerfile'
- './${_CONTAINER_SUBFOLDER}'
# TODO: This has an issue that it might have had another commit since build trigger.
#- './$REPO_NAME/hellonode'
# Retag latest with git sha
- name: 'gcr.io/cloud-builders/docker'
args: ['tag',
'gcr.io/$PROJECT_ID/$REPO_NAME:latest',
'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA']
# Create semver tag
# TODO: Need to filter height from the commitid as another commit might have sneaked in after trigger fired.
- name: gcr.io/cloud-builders/git
entrypoint: /bin/bash
args:
- '-c'
- |
cd $REPO_NAME
pwd
ls -la
echo ${_TWO_PART_VERSION}.$(git rev-list --count ${BRANCH_NAME}) > IMAGE_TAG
# Push semver image - should all be cached
- name: gcr.io/cloud-builders/docker
entrypoint: /bin/bash
args:
- '-c'
- |
cd $REPO_NAME
docker tag gcr.io/$PROJECT_ID/$REPO_NAME:latest gcr.io/$PROJECT_ID/$REPO_NAME:$(cat IMAGE_TAG)
docker push gcr.io/$PROJECT_ID/$REPO_NAME:$(cat IMAGE_TAG)
# These are images that pushed as well
images: ['gcr.io/$PROJECT_ID/$REPO_NAME:latest',
'gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA']