summaryrefslogtreecommitdiff
path: root/build.sh
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2019-02-14 10:07:54 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2019-02-14 10:07:54 -0500
commit13fac75cd115ce484321cac1b079483bc9c58d5f (patch)
treeb8723d4ee5fd228e06b2d186993a5a5e1f571ae5 /build.sh
parentb62b65159d9edac9b8f8d3429e455cf7b25f0904 (diff)
downloaddocker-base-13fac75cd115ce484321cac1b079483bc9c58d5f.tar.gz
Deterministic refactor
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh59
1 files changed, 54 insertions, 5 deletions
diff --git a/build.sh b/build.sh
index 0254885..29f9980 100755
--- a/build.sh
+++ b/build.sh
@@ -1,9 +1,58 @@
#!/bin/bash
-PROJECT=astroconda/base
-VERSION="${1}"
-if [[ -z ${VERSION} ]]; then
- echo "Project version required [e.g. 1.2.3]"
+set -x
+HUB=${3:-astroconda}
+PROJECT=${HUB}/base
+PROJECT_VERSION="${1}"
+TAGS=()
+
+if [[ -z ${PROJECT_VERSION} ]]; then
+ echo "Project version required [e.g. 1.2.3... \$(git describe)]"
exit 1
fi
-docker build -t ${PROJECT}:latest -t ${PROJECT}:${VERSION} .
+read \
+ PROJECT_VERSION_MAJOR \
+ PROJECT_VERSION_MINOR \
+ PROJECT_VERSION_PATCH <<< ${PROJECT_VERSION//\./ }
+
+case "${HUB}" in
+ *amazonaws\.com)
+ if ! type -p aws; then
+ echo "awscli client not installed"
+ exit 1
+ fi
+ REGION="$(awk -F'.' '{print $(NF-2)}' <<< ${HUB})"
+ $(aws ecr get-login --no-include-email --region ${REGION})
+ unset REGION
+ ;;
+ *)
+ # Assume default index
+ docker login
+ ;;
+esac
+
+TAGS+=( "-t ${PROJECT}:${PROJECT_VERSION}" )
+is_tag_latest=$([[ -f LATEST ]] && [[ $(<LATEST) == ${PROJECT_VERSION} ]] && echo yes)
+if [[ -n ${is_tag_latest} ]]; then
+ TAGS+=( "-t ${PROJECT}:latest" )
+ TAGS+=( "-t ${PROJECT}:${PROJECT_VERSION_MAJOR}" )
+ TAGS+=( "-t ${PROJECT}:${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}" )
+fi
+
+docker build ${TAGS[@]} .
+
+max_retry=4
+retry=0
+set +e
+while (( retry != max_retry ))
+do
+ echo "Push attempt #$(( retry + 1 ))"
+ docker push "${PROJECT}"
+ rv=$?
+ if [[ ${rv} == 0 ]]; then
+ break
+ fi
+ (( retry++ ))
+done
+
+exit ${rv}