Skip to content

Instantly share code, notes, and snippets.

@flurdy
Last active March 17, 2023 13:02
Show Gist options
  • Save flurdy/11595f8519beff50ea96bc64a1f41702 to your computer and use it in GitHub Desktop.
Save flurdy/11595f8519beff50ea96bc64a1f41702 to your computer and use it in GitHub Desktop.
Google Cloud Build with pseudo semver
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