Last active
March 17, 2023 13:02
-
-
Save flurdy/11595f8519beff50ea96bc64a1f41702 to your computer and use it in GitHub Desktop.
Google Cloud Build with pseudo semver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
steps: | |
- name: gcr.io/cloud-builders/git | |
args: ["fetch", "--unshallow"] | |
- name: gcr.io/cloud-builders/git | |
entrypoint: /bin/bash | |
args: | |
[ | |
"-c", | |
"echo ${_MAJOR}.${_MINOR}.$(git rev-list --count ${BRANCH_NAME}) > ${_VERSION_FILE}", | |
] | |
- name: "gcr.io/cloud-builders/docker" | |
entrypoint: /bin/bash | |
args: | |
[ | |
"-c", | |
"docker build --cache-from ${_IMAGE}:latest -t ${_IMAGE}:latest -t ${_IMAGE}:${SHORT_SHA} -t ${_IMAGE}:$(cat ${_VERSION_FILE}) .", | |
] | |
- name: gcr.io/cloud-builders/docker | |
entrypoint: /bin/bash | |
args: ["-c", "docker push ${_IMAGE}:$(cat ${_VERSION_FILE})"] | |
images: ["${_IMAGE}:latest", "${_IMAGE}:${SHORT_SHA}"] | |
substitutions: | |
_IMAGE: "gcr.io/${PROJECT_ID}/${_REPO_PREFIX}/${_REPO_PROJECT}" | |
_VERSION_FILE: "./commits-version.txt" | |
# _MAJOR - set in Trigger | |
# _MINOR - set in Trigger | |
# _REPO_PREFIX - set in Trigger | |
# _REPO_PROJECT - set in Trigger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by https://nieldw.medium.com/get-a-pseudo-sequential-build-number-in-google-cloud-build-85ae591cf86