generated from RedPillAnalytics/docker-cloudbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudbuild.yaml
87 lines (87 loc) · 2.2 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
substitutions:
# See if this is either a tag or a PR
# Replace "/" in branch names with "-"
_TAG_NAME: ${TAG_NAME:-${_HEAD_BRANCH//\//-}}
# Capture long and short versions of the repository name
_REPO_LONG: ${REPO_NAME#*/}
_REPO_SHORT: ${REPO_NAME#*-}
# If it's a PR, image tag will be the Head Branch
# If it's a tag, image tag will be the tag
# If it's not a tag or a PR, then it should be latest
_IMAGE_NAME: ${_REPO_LONG}:${_TAG_NAME:-latest}
# Get repository URL
_REPO_URL: $(body.repository.html_url)
steps:
- name: gcr.io/$PROJECT_ID/project-version
id: version
args:
- $_REPO_URL
- $BRANCH_NAME
waitFor: ['-']
# use Kaniko and --single-snapshot to reduce image size
# No need to combine multiple statements in a Dockerfile to reduce image size
- name: 'gcr.io/kaniko-project/executor:latest'
id: build
args:
- --destination=gcr.io/$PROJECT_ID/$_IMAGE_NAME
- --cache=true
- --cache-ttl=48h
- --single-snapshot
- --context=./
waitFor:
- version
- name: 'gcr.io/$PROJECT_ID/${_IMAGE_NAME}'
id: test
entrypoint: bash
args:
- '-cx'
- |
echo "The test is successful or else..." \
|| exit 1
waitFor:
- build
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
id: tag-image
entrypoint: bash
args:
- '-cx'
- |
if [[ $BRANCH_NAME =~ master|main ]]
then
gcloud container images add-tag gcr.io/$PROJECT_ID/${_IMAGE_NAME} gcr.io/$PROJECT_ID/$_REPO_LONG:`<stepvars/version`
fi
waitFor:
- test
- name: gcr.io/$PROJECT_ID/gh
id: delete-release
entrypoint: bash
args:
- '-cx'
- |
if [[ $BRANCH_NAME =~ master|main ]]
then
gh release delete `<stepvars/tag` || exit 0
fi
waitFor:
- test
- name: gcr.io/$PROJECT_ID/gh
id: create-release
entrypoint: bash
args:
- '-cx'
- |
if [[ $BRANCH_NAME =~ master|main ]]
then
gh release create `<stepvars/tag` --target $BRANCH_NAME
fi
waitFor:
- delete-release
timeout: 3600s
options:
dynamic_substitutions: true
secretEnv:
- GITHUB_TOKEN
availableSecrets:
secretManager:
- versionName: projects/737919165778/secrets/GITHUB_TOKEN/versions/latest
env: GITHUB_TOKEN