diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-02-18 14:56:14 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-02-18 14:56:14 -0500 |
commit | 34575a023b19cdafcae0db945a8c8d8e44e3455f (patch) | |
tree | 5d60646540700cdc5fc1e7ee1c719b3c94e16a7d /build.sh | |
parent | 30ea4ba9222c0d9b24bf401639eddef4e5b9ef89 (diff) | |
download | docker-pipeline-nb-34575a023b19cdafcae0db945a8c8d8e44e3455f.tar.gz |
Refactor build/publish
Diffstat (limited to 'build.sh')
-rwxr-xr-x | build.sh | 62 |
1 files changed, 55 insertions, 7 deletions
@@ -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} |