summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2019-02-18 14:56:14 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2019-02-18 14:56:14 -0500
commit34575a023b19cdafcae0db945a8c8d8e44e3455f (patch)
tree5d60646540700cdc5fc1e7ee1c719b3c94e16a7d
parent30ea4ba9222c0d9b24bf401639eddef4e5b9ef89 (diff)
downloaddocker-pipeline-nb-34575a023b19cdafcae0db945a8c8d8e44e3455f.tar.gz
Refactor build/publish
-rw-r--r--Dockerfile7
-rwxr-xr-xbuild.sh62
-rwxr-xr-xscripts/start.sh13
3 files changed, 70 insertions, 12 deletions
diff --git a/Dockerfile b/Dockerfile
index 9a23c2d..d23cb50 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,11 +1,12 @@
+ARG HUB
ARG PIPELINE
-FROM astroconda/pipeline:${PIPELINE}
+FROM ${HUB}/pipeline:${PIPELINE}
LABEL maintainer="jhunk@stsci.edu" \
vendor="Space Telescope Science Institute"
WORKDIR "${TOOLCHAIN_BUILD}"
-COPY scripts/ ${TOOLCHAIN_BUILD}/bin
+COPY scripts/build.sh ${TOOLCHAIN_BUILD}/bin/
COPY etc/ ${TOOLCHAIN_BUILD}/etc
USER "${USER_ACCT}"
@@ -19,3 +20,5 @@ WORKDIR "${USER_HOME}"
EXPOSE 8888
ENTRYPOINT ["tini", "-g", "--"]
CMD ["start.sh"]
+
+COPY scripts/start.sh /usr/local/bin
diff --git a/build.sh b/build.sh
index 98eefb1..ee5a19f 100755
--- a/build.sh
+++ b/build.sh
@@ -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}
diff --git a/scripts/start.sh b/scripts/start.sh
index 6298bbd..c773303 100755
--- a/scripts/start.sh
+++ b/scripts/start.sh
@@ -1,6 +1,13 @@
#!/bin/bash
-if [[ ${#} == 0 ]]; then
- exec "bash"
-else
+set -vxe
+if [[ "${@}" == bash* ]]; then
exec "${@}"
fi
+
+if [[ -n ${JUPYTER_API_TOKEN} ]]; then
+ exec jupyterhub-singleuser --ip=0.0.0.0 "${@}"
+elif [[ -n ${JUPYTER_ENABLE_LAB} ]]; then
+ exec jupyter labhub --ip=0.0.0.0 "${@}"
+else
+ exec jupyter notebook --ip=0.0.0.0 "${@}"
+fi