Skip to content

Commit

Permalink
Create CD script to be run after every push to main branch
Browse files Browse the repository at this point in the history
Hook up guestbook-go (first) to push images to the staging project
with prow.
  • Loading branch information
justinsb committed Jan 24, 2023
1 parent 8c357b6 commit b621ffb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
37 changes: 37 additions & 0 deletions dev/cd/after-push-to-branch
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions dev/cloudbuild/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit b621ffb

Please sign in to comment.