-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudbuild.yaml
109 lines (98 loc) · 3.28 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
99
100
101
102
103
104
105
106
107
108
substitutions:
_TWO_PART_VERSION: "0.1"
_GITHUB_USERNAME: "chrisguest75"
#_CONTAINER_SUBFOLDER: "codelabs"
timeout: "1200.0s"
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/open-source-01/custom_cloudbuild_sshkeys:0.0.5'
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
- --branch
- $BRANCH_NAME
- [email protected]:${_GITHUB_USERNAME}/$REPO_NAME
volumes:
- name: 'ssh'
path: /root/.ssh
# Build the base image
# push the base image?
- name: 'gcr.io/cloud-builders/git'
entrypoint: /bin/bash
args:
- '-c'
- |
pwd
ls -la
cd $REPO_NAME
git clone https://github.com/chrisguest75/codelab-tools-fork
cp Dockerfile ./codelab-tools-fork/Dockerfile
cd ./codelab-tools-fork
# Build the dockerfile with the latest cloned code.
- name: 'gcr.io/cloud-builders/docker'
entrypoint: /bin/bash
args:
- '-c'
- |
cd $REPO_NAME/codelab-tools-fork
pwd
ls -la
docker build --cache-from=gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_base:latest -t codelabs_base:latest .
docker tag codelabs_base:latest gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_base:latest
docker tag codelabs_base:latest gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_base:$COMMIT_SHA
docker push gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_base:latest
# TODO: This has an issue that it might have had another commit since build trigger.
# 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
# This uses the base image
- name: 'gcr.io/cloud-builders/docker'
entrypoint: /bin/bash
args:
- '-c'
- |
cd $REPO_NAME
pwd
ls -la
docker build -t codelabs:latest -f Dockerfile.codelabs .
docker tag codelabs:latest gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_$BRANCH_NAME:latest
docker tag codelabs:latest gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_$BRANCH_NAME:$COMMIT_SHA
docker tag gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_$BRANCH_NAME:latest gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_$BRANCH_NAME:$(cat IMAGE_TAG)
docker push gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_$BRANCH_NAME:latest
docker push gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_$BRANCH_NAME:$COMMIT_SHA
docker push gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_$BRANCH_NAME:$(cat IMAGE_TAG)
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: /bin/bash
args:
- '-c'
- |
gcloud beta run deploy codelabs --image gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_$BRANCH_NAME:$COMMIT_SHA --region europe-west1 --platform managed --quiet
# These are images that pushed as well
images: ['gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_base:latest',
'gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_$BRANCH_NAME:latest',
'gcr.io/$PROJECT_ID/$REPO_NAME/codelabs_$BRANCH_NAME:$COMMIT_SHA']