diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-02-14 23:28:25 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-02-14 23:28:25 -0500 |
commit | cf3d348296e4768cc0ec517f9bc2162f02eadd3c (patch) | |
tree | af443911fe012a5ebf99c0f55379ce6da6958932 /build.sh | |
parent | b0fa760126571f7fd22e1dfa7ee641b195639efc (diff) | |
download | docker-python-cf3d348296e4768cc0ec517f9bc2162f02eadd3c.tar.gz |
Refactor build/publish
Diffstat (limited to 'build.sh')
-rwxr-xr-x | build.sh | 76 |
1 files changed, 61 insertions, 15 deletions
@@ -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} |