forked from gomods/athens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush-docker-images.sh
executable file
·43 lines (35 loc) · 1.48 KB
/
push-docker-images.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# Push our docker images to a registry
set -xeuo pipefail
REGISTRY=${REGISTRY:-gomods/}
# Use the travis variables when available because travis clones different than what is on a local dev machine
# VERSION = the tag if present, otherwise the short commit hash
# BRANCH = the current branch, empty if not on a branch
if [[ "${TRAVIS-}" == "true" ]]; then
VERSION=${TRAVIS_TAG:-${TRAVIS_COMMIT::7}}
BRANCH=${TRAVIS_BRANCH}
else
TAG=$(git describe --tags --exact-match 2> /dev/null || true)
COMMIT=$(git rev-parse --short=7 HEAD)
VERSION=${VERSION:-${TAG:-${COMMIT}}}
BRANCH=${BRANCH:-$(git symbolic-ref -q --short HEAD || echo "")}
fi
# MUTABLE_TAG is the docker image tag that we will reuse between pushes, it is not an immutable tag like a commit hash or tag.
if [[ "${MUTABLE_TAG:-}" == "" ]]; then
# tagged builds
if [[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
MUTABLE_TAG="latest"
# master build
elif [[ "$BRANCH" == "master" ]]; then
MUTABLE_TAG="canary"
# branch build
else
MUTABLE_TAG=${BRANCH}
fi
fi
REPO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null && pwd )/"
docker build --build-arg VERSION=${VERSION} -t ${REGISTRY}athens:${VERSION} -f ${REPO_DIR}cmd/proxy/Dockerfile ${REPO_DIR}
# Apply the mutable tag to the immutable version
docker tag ${REGISTRY}athens:${VERSION} ${REGISTRY}athens:${MUTABLE_TAG}
docker push ${REGISTRY}athens:${VERSION}
docker push ${REGISTRY}athens:${MUTABLE_TAG}