summaryrefslogtreecommitdiff
path: root/build.sh
diff options
context:
space:
mode:
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh62
1 files changed, 55 insertions, 7 deletions
diff --git a/build.sh b/build.sh
index 98eefb1..ee5a19f 100755
--- a/build.sh
+++ b/build.sh
@@ -1,10 +1,58 @@
#!/bin/bash
-PROJECT=astroconda/pipeline-nb
-PIPELINE="${1}"
-if [[ -z ${PIPELINE} ]]; then
- echo "Need a pipeline verison [i.e. hstdp-2018.3a_py###]"
+set -x
+HUB=${2:-astroconda}
+PROJECT=${HUB}/pipeline-nb
+PROJECT_VERSION="${1}"
+TAGS=()
+image_tag="${PROJECT_VERSION}"
+
+if [[ -z ${PROJECT_VERSION} ]]; then
+ echo "Pipeline version required [e.g. hstdp-snapshot, hstdp-2018.3_py###]"
exit 1
fi
-docker build --pull -t ${PROJECT}:${PIPELINE} \
- --build-arg PIPELINE=${PIPELINE} \
- .
+
+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}:${image_tag}" )
+PIPELINE="${PROJECT_VERSION}"
+docker build ${TAGS[@]} \
+ --build-arg HUB="${HUB}" \
+ --build-arg PIPELINE="${PROJECT_VERSION}" \
+ .
+
+rv=$?
+if (( rv > 0 )); then
+ echo "Failed... Image not published"
+ exit ${rv}
+fi
+
+
+max_retry=4
+retry=0
+set +e
+while (( retry != max_retry ))
+do
+ echo "Push attempt #$(( retry + 1 ))"
+ docker push "${PROJECT}:${image_tag}"
+ rv=$?
+ if [[ ${rv} == 0 ]]; then
+ break
+ fi
+ (( retry++ ))
+done
+
+exit ${rv}