Files
athens/scripts/push-docker-images.sh
Rob j Loranger 2f524d27c3 add build details to binary (#866)
* poc

* finish JSON, remove uneeded methods, update docker file, finish script details

* build.Details didn't need to be exported

* typo

* somehow missed this

* should default to false

* Fix some things

remove commit SHA as build script will now create a hybrid for version
as in the push-docker-images.sh script, code shamelessly stolen.

change JSON function to Data and return a struct, the caller can do what
they like with that data, i.e. marshall JSON for a response body.

* add struct tags

* use build script in docker image

* newline in build.sh

* use previously generated version for binary build

* Working docker args

removed script build.sh, was not really needed.

date is generated automatically during docker build process.

VERSION will be set to 'Not Specified', or the version set during
our CI docker build/push step. A user can set their own version during
build using ldflags.

* remove old comment re: script

* Yikes

Almost forgot to remove my testing junk

* GitHub on my phone is hard
2018-11-09 10:32:55 -08:00

44 lines
1.5 KiB
Bash
Executable File

#!/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 a stable 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="stable"
# 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}proxy:${VERSION} -f ${REPO_DIR}cmd/proxy/Dockerfile ${REPO_DIR}
# Apply the mutable tag to the immutable version
docker tag ${REGISTRY}proxy:${VERSION} ${REGISTRY}proxy:${MUTABLE_TAG}
docker push ${REGISTRY}proxy:${VERSION}
docker push ${REGISTRY}proxy:${MUTABLE_TAG}