summaryrefslogtreecommitdiff
path: root/build.sh
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2019-02-14 23:29:56 -0500
committerGitHub <noreply@github.com>2019-02-14 23:29:56 -0500
commitaef4801ac3de2a87a32123effa49223082e18aac (patch)
treeaf443911fe012a5ebf99c0f55379ce6da6958932 /build.sh
parentb0fa760126571f7fd22e1dfa7ee641b195639efc (diff)
parentcf3d348296e4768cc0ec517f9bc2162f02eadd3c (diff)
downloaddocker-python-aef4801ac3de2a87a32123effa49223082e18aac.tar.gz
Merge pull request #2 from jhunkeler/refactor-build
Refactor build/publish
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh76
1 files changed, 61 insertions, 15 deletions
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}