-
Notifications
You must be signed in to change notification settings - Fork 2
/
cloudbuild.yaml
80 lines (68 loc) · 2.02 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
substitutions:
_TWO_PART_VERSION: "0.1"
_GITHUB_USERNAME: "hutomadotAI"
_CONTAINER_SUBFOLDER: "src"
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/opensource-239410/cloudbuild_sshkeys_image:latest'
entrypoint: '/workbench/decrypt.sh'
args: ['/workbench']
dir: '/workbench'
volumes:
- name: 'ssh'
path: /root/.ssh
# Use git clone to get private repo.
- name: 'gcr.io/cloud-builders/git'
args:
- clone
- [email protected]:${_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']