summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Dockerfile5
-rwxr-xr-xbuild.sh76
2 files changed, 64 insertions, 17 deletions
diff --git a/Dockerfile b/Dockerfile
index 55a4ee0..bccb66e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,6 @@
-ARG BASE_VERSION=${BASE_VERSION:latest-}
-FROM astroconda/base:${BASE_VERSION}
+ARG HUB=${HUB:-astroconda}
+ARG BASE_VERSION=${BASE_VERSION:-latest}
+FROM ${HUB}/base:${BASE_VERSION}
LABEL maintainer="jhunk@stsci.edu" \
vendor="Space Telescope Science Institute"
diff --git a/build.sh b/build.sh
index 0e8e3c2..d57a03c 100755
--- a/build.sh
+++ b/build.sh
@@ -1,24 +1,70 @@
#!/bin/bash
-PROJECT=astroconda/python
-PYTHON_VERSION="${1}"
-if [[ -z ${PYTHON_VERSION} ]]; then
- echo "Need a fully qualified Python version to build. [e.g. 3.7.1]"
+HUB=${3:-astroconda}
+PROJECT=${HUB}/python
+PROJECT_VERSION="${1}"
+BASE_IMG_VERSION=${2:-latest}
+TAGS=()
+
+if [[ -z ${PROJECT_VERSION} ]]; then
+ echo "Python version required [e.g. 3.7.1]"
exit 1
fi
-BASE_VERSION="${2}"
-if [[ -z ${BASE_VERSION} ]]; then
- BASE_VERSION="latest"
-fi
+set -x
+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
-is_tag_latest=$([[ -f LATEST ]] && [[ $(<LATEST) == ${PYTHON_VERSION} ]] && echo yes)
+TAGS+=( "-t ${PROJECT}:${PROJECT_VERSION}" )
+is_tag_latest=$([[ -f LATEST ]] && [[ $(<LATEST) == ${PROJECT_VERSION} ]] && echo yes)
if [[ -n ${is_tag_latest} ]]; then
- tag_latest="-t ${PROJECT}:latest"
+ TAGS+=( "-t ${PROJECT}:latest" )
+ TAGS+=( "-t ${PROJECT}:${PROJECT_VERSION_MAJOR}" )
+ TAGS+=( "-t ${PROJECT}:${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}" )
fi
-
-docker build -t ${PROJECT}:${PYTHON_VERSION} \
- ${tag_latest} \
- --build-arg PYTHON_VERSION=${PYTHON_VERSION} \
- --build_arg BASE_VERSION=${BASE_VERSION} \
+docker build ${TAGS[@]} \
+ --build-arg HUB="${HUB}" \
+ --build-arg PYTHON_VERSION="${PROJECT_VERSION}" \
+ --build-arg BASE_VERSION="${BASE_IMG_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}"
+ rv=$?
+ if [[ ${rv} == 0 ]]; then
+ break
+ fi
+ (( retry++ ))
+done
+
+exit ${rv}