forked from influxdata/cd-gitops-reference-architecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cd-base.bash
23 lines (17 loc) · 878 Bytes
/
cd-base.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
set -eu -o pipefail
# get current branch and commit sha, and force branch name to valid docker tag character set
# allow forcing branch name regardless of current banch using FORCE_CI_* variables
readonly branch_name="${FORCE_CI_BRANCH_NAME:-$(git rev-parse --abbrev-ref HEAD | tr -d '\n' | tr -c '[:alnum:].-' _)}"
readonly git_sha="${FORCE_CI_GIT_SHA:-$(git rev-parse HEAD)}"
# pull image if it exists, ignore if it does not
docker pull "docker.example.com/app-bins:${branch_name}" || true
docker build --pull \
--cache-from "docker.example.com/app-bins:${branch_name}" \
-t "docker.example.com/app-bins:${git_sha}" \
-f Dockerfile.cd .
docker tag \
"docker.example.com/app-bins:${git_sha}" \
"docker.example.com/app-bins:${branch_name}"
docker push "docker.example.com/app-bins:${git_sha}"
docker push "docker.example.com/app-bins:${branch_name}"