Skip to content

Commit feda878

Browse files
authored
Merge pull request #471 from justinsb/cd_on_push_to_branch
Create CD script to be run after every push to main branch
2 parents 8c357b6 + b621ffb commit feda878

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

dev/cd/after-push-to-branch

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
# cd to the repo root
8+
REPO_ROOT=$(git rev-parse --show-toplevel)
9+
cd "${REPO_ROOT}"
10+
11+
if [ -z "${GIT_REF:-}" ]; then
12+
echo "GIT_REF must be set"
13+
exit 1
14+
fi
15+
16+
if [[ -z "${REGISTRY_BASE:-}" ]]; then
17+
echo "REGISTRY_BASE must be set"
18+
exit 1
19+
fi
20+
21+
if [[ ! "${GIT_REF}" =~ ^refs/heads/.* ]]; then
22+
echo "GIT_REF=${GIT_REF} is not of the expected format refs/heads/*"
23+
exit 1
24+
fi
25+
26+
BRANCH=${GIT_REF/refs\/heads\//}
27+
echo "BRANCH is ${BRANCH}"
28+
29+
GIT_REVISION=$(git rev-parse --short HEAD)
30+
echo "GIT_REVISION is ${GIT_REVISION}"
31+
32+
export IMAGE_TAG="g${GIT_REVISION}"
33+
echo "IMAGE_TAG is ${IMAGE_TAG}"
34+
35+
pushd ${REPO_ROOT}/guestbook-go
36+
VERSION=${IMAGE_TAG} REGISTRY=${REGISTRY_BASE} make push
37+
popd

dev/cloudbuild/cloudbuild.yaml

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

0 commit comments

Comments
 (0)