From c8ad645d8827bdd9fedc19a8c67f22aa016f8290 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 15 Feb 2019 22:11:56 -0500 Subject: Refactor build/publish --- build.sh | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 13 deletions(-) (limited to 'build.sh') diff --git a/build.sh b/build.sh index b4249bc..cf35562 100755 --- a/build.sh +++ b/build.sh @@ -1,22 +1,76 @@ #!/bin/bash -PROJECT=astroconda/pipeline -PIPELINE="${1}" -if [[ -z ${PIPELINE} ]]; then - echo "No pipeline specified. [e.g. hst-TREE, jwst-TREE, ...]" +set -x +HUB=${3:-astroconda} +PROJECT=${HUB}/pipeline +PROJECT_VERSION="${1}" +PYTHON_VERSION="${2}" +TAGS=() +SUFFIX= +image_tag="${PROJECT_VERSION}" + +if [[ -z ${PROJECT_VERSION} ]]; then + echo "Pipeline version required [e.g. hstdp-2018.3]" exit 1 fi -PYTHON_VERSION="${2}" -if [[ -z ${PIPELINE} ]]; then - echo "Need a fully qualified python version [e.g. 3.7.1]" +if [[ -z ${PYTHON_VERSION} ]]; then + echo "Python version required [e.g. latest, 3.7.2]" exit 1 fi -SUFFIX=${PYTHON_VERSION//\./} -if [[ -z ${SUFFIX} ]]; then - echo "Unable to determine tag suffix from python version." - exit 1 +if [[ ${PYTHON_VERSION} != latest ]]; then + SUFFIX=${PYTHON_VERSION//\./} + if [[ -z ${SUFFIX} ]]; then + echo "Unable to determine tag suffix from python version." + exit 1 + fi + + image_tag="${image_tag}_py${SUFFIX}" fi -TAG="${PROJECT}:${PIPELINE}_py${SUFFIX}" -docker build -t ${TAG} --build-arg PIPELINE=${PIPELINE} --build-arg PYTHON_VERSION=${PYTHON_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 + +TAGS+=( "-t ${PROJECT}:${image_tag}" ) +PIPELINE="${PROJECT_VERSION}" +docker build ${TAGS[@]} \ + --build-arg HUB="${HUB}" \ + --build-arg PYTHON_VERSION="${PYTHON_VERSION}" \ + --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} -- cgit