From b621ffb775f0e7c6794548667dc7b156b21e4fa4 Mon Sep 17 00:00:00 2001 From: Justin SB Date: Tue, 24 Jan 2023 13:43:21 -0500 Subject: [PATCH] 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. --- dev/cd/after-push-to-branch | 37 ++++++++++++++++++++++++++++++++++ dev/cloudbuild/cloudbuild.yaml | 13 ++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 dev/cd/after-push-to-branch create mode 100644 dev/cloudbuild/cloudbuild.yaml diff --git a/dev/cd/after-push-to-branch b/dev/cd/after-push-to-branch new file mode 100755 index 00000000..9f63c476 --- /dev/null +++ b/dev/cd/after-push-to-branch @@ -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 \ No newline at end of file diff --git a/dev/cloudbuild/cloudbuild.yaml b/dev/cloudbuild/cloudbuild.yaml new file mode 100644 index 00000000..aaf48fa3 --- /dev/null +++ b/dev/cloudbuild/cloudbuild.yaml @@ -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'