Create CD script to be run after every push to main branch

Hook up guestbook-go (first) to push images to the staging project
with prow.
This commit is contained in:
Justin SB 2023-01-24 13:43:21 -05:00
parent 8c357b6f7d
commit b621ffb775
2 changed files with 50 additions and 0 deletions

37
dev/cd/after-push-to-branch Executable file
View File

@ -0,0 +1,37 @@
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
# cd to the repo root
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "${REPO_ROOT}"
if [ -z "${GIT_REF:-}" ]; then
echo "GIT_REF must be set"
exit 1
fi
if [[ -z "${REGISTRY_BASE:-}" ]]; then
echo "REGISTRY_BASE must be set"
exit 1
fi
if [[ ! "${GIT_REF}" =~ ^refs/heads/.* ]]; then
echo "GIT_REF=${GIT_REF} is not of the expected format refs/heads/*"
exit 1
fi
BRANCH=${GIT_REF/refs\/heads\//}
echo "BRANCH is ${BRANCH}"
GIT_REVISION=$(git rev-parse --short HEAD)
echo "GIT_REVISION is ${GIT_REVISION}"
export IMAGE_TAG="g${GIT_REVISION}"
echo "IMAGE_TAG is ${IMAGE_TAG}"
pushd ${REPO_ROOT}/guestbook-go
VERSION=${IMAGE_TAG} REGISTRY=${REGISTRY_BASE} make push
popd

View File

@ -0,0 +1,13 @@
timeout: 900s
steps:
- name: 'gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20230111-cd1b3caf9c'
entrypoint: dev/cd/after-push-to-branch
env:
- GIT_REF=$_GIT_TAG
- PULL_BASE_REF=$_PULL_BASE_REF
- REGISTRY_BASE=gcr.io/k8s-staging-examples
substitutions:
# _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and
# can be used as a substitution
_GIT_TAG: '12345'
_PULL_BASE_REF: 'master'