diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-01-31 14:24:24 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2019-01-31 14:24:24 -0500 |
commit | 30ea4ba9222c0d9b24bf401639eddef4e5b9ef89 (patch) | |
tree | 13ee9f133b6cc3fc6b6ce6aeef48d1347e125569 | |
download | docker-pipeline-nb-30ea4ba9222c0d9b24bf401639eddef4e5b9ef89.tar.gz |
Initial commit
-rw-r--r-- | Dockerfile | 21 | ||||
-rwxr-xr-x | build.sh | 10 | ||||
-rw-r--r-- | etc/pip/000-dummy | 0 | ||||
-rwxr-xr-x | etc/pkgs/000-dummy.sh | 2 | ||||
-rwxr-xr-x | etc/pkgs/001-tini.sh | 18 | ||||
-rwxr-xr-x | etc/pkgs/002-nodejs.sh | 17 | ||||
-rwxr-xr-x | etc/pkgs/003-jupyter.sh | 15 | ||||
-rwxr-xr-x | etc/tasks/001-packages.sh | 41 | ||||
-rwxr-xr-x | etc/tasks/002-python-packages.sh | 38 | ||||
-rwxr-xr-x | etc/tasks/999-clean.sh | 17 | ||||
-rwxr-xr-x | scripts/build.sh | 34 | ||||
-rwxr-xr-x | scripts/start.sh | 6 |
12 files changed, 219 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9a23c2d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +ARG PIPELINE +FROM astroconda/pipeline:${PIPELINE} +LABEL maintainer="jhunk@stsci.edu" \ + vendor="Space Telescope Science Institute" + +WORKDIR "${TOOLCHAIN_BUILD}" + +COPY scripts/ ${TOOLCHAIN_BUILD}/bin +COPY etc/ ${TOOLCHAIN_BUILD}/etc + +USER "${USER_ACCT}" + +RUN sudo chown -R ${USER_ACCT}: ${TOOLCHAIN_BUILD} \ + && bin/build.sh \ + && sudo rm -rf "${TOOLCHAIN_BUILD}" + +WORKDIR "${USER_HOME}" + +EXPOSE 8888 +ENTRYPOINT ["tini", "-g", "--"] +CMD ["start.sh"] diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..98eefb1 --- /dev/null +++ b/build.sh @@ -0,0 +1,10 @@ +#!/bin/bash +PROJECT=astroconda/pipeline-nb +PIPELINE="${1}" +if [[ -z ${PIPELINE} ]]; then + echo "Need a pipeline verison [i.e. hstdp-2018.3a_py###]" + exit 1 +fi +docker build --pull -t ${PROJECT}:${PIPELINE} \ + --build-arg PIPELINE=${PIPELINE} \ + . diff --git a/etc/pip/000-dummy b/etc/pip/000-dummy new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/etc/pip/000-dummy diff --git a/etc/pkgs/000-dummy.sh b/etc/pkgs/000-dummy.sh new file mode 100755 index 0000000..06bd986 --- /dev/null +++ b/etc/pkgs/000-dummy.sh @@ -0,0 +1,2 @@ +#!/bin/bash +exit 0 diff --git a/etc/pkgs/001-tini.sh b/etc/pkgs/001-tini.sh new file mode 100755 index 0000000..44bb172 --- /dev/null +++ b/etc/pkgs/001-tini.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -x + +sudo yum install -y cmake glibc-static || exit 1 +git clone https://github.com/krallin/tini.git +export CFLAGS="${CFLAGS} -DPR_SET_CHILD_SUBREAPER=36 -DPR_GET_CHILD_SUBREAPER=37" + +pushd tini + git checkout v0.18.0 + mkdir -p build + pushd build + cmake .. + make + install -m755 tini ${TOOLCHAIN_BIN} + popd +popd + +rm -rf tini diff --git a/etc/pkgs/002-nodejs.sh b/etc/pkgs/002-nodejs.sh new file mode 100755 index 0000000..b52a229 --- /dev/null +++ b/etc/pkgs/002-nodejs.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -x + +name=node +version=v10.15.0 +srcdir=${name}-${version} +tarball=${srcdir}.tar.gz +url=https://nodejs.org/dist/${version}/${tarball} + +curl -LO "${url}" +tar xf "${tarball}" +pushd "${srcdir}" + export CFLAGS="${CFLAGS} -fPIC" + ./configure --prefix=${TOOLCHAIN} + make -j${_maxjobs} + make install +popd diff --git a/etc/pkgs/003-jupyter.sh b/etc/pkgs/003-jupyter.sh new file mode 100755 index 0000000..dfc312a --- /dev/null +++ b/etc/pkgs/003-jupyter.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -x + +pip install --upgrade --progress-bar=off \ + notebook==5.7.2 \ + jupyterhub==0.9.4 \ + jupyterlab==0.35.4 + +jupyter labextension install @jupyterlab/hub-extension@^0.12.0 +jupyter notebook --generate-config -y + +# Clean up +npm cache clean --force +rm -rf ${TOOLCHAIN}/share/jupyter/lab/staging +rm -rf /home/${USER_ACCT}/.cache/yarn diff --git a/etc/tasks/001-packages.sh b/etc/tasks/001-packages.sh new file mode 100755 index 0000000..5d20ee7 --- /dev/null +++ b/etc/tasks/001-packages.sh @@ -0,0 +1,41 @@ +#!/bin/bash +set -x + +sysconfdir="${TOOLCHAIN_BUILD}/etc" +reqdir=${sysconfdir}/pkgs +blddir=builds + +function pre() +{ + if [[ ! -d ${reqdir} ]]; then + # Nothing there, but maybe that's on purpose. + exit 0 + fi + mkdir -p "${blddir}" + pushd ${blddir} &>/dev/null +} + +function build() +{ + pre + # Iterate over binary package build scripts + for req in ${reqdir}/* + do + chmod +x "${req}" + "${req}" + retval=$? + if [[ ${retval} != 0 ]]; then + echo "BUILD FAILED: ${req}" + exit ${retval} + fi + done + post +} + +function post() +{ + popd &>/dev/null + [[ -d ${blddir} ]] && rm -rf "${blddir}" +} + +build diff --git a/etc/tasks/002-python-packages.sh b/etc/tasks/002-python-packages.sh new file mode 100755 index 0000000..bcd0b6f --- /dev/null +++ b/etc/tasks/002-python-packages.sh @@ -0,0 +1,38 @@ +#!/bin/bash +set -x + +sysconfdir="${TOOLCHAIN_BUILD}/etc" +reqdir=${sysconfdir}/pip + +function pre() +{ + if [[ ! -d ${reqdir} ]]; then + # Nothing there, but maybe that's on purpose. + exit 0 + fi +} + +function build() +{ + pre + # Iterate over pip requirement files + for req in ${reqdir}/* + do + pip install --upgrade --progress-bar=off -r "${req}" + retval=$? + if [[ ${retval} != 0 ]]; then + echo "BUILD FAILED: ${req}" + exit ${retval} + fi + done + post +} + +function post() +{ + rm -rf ~/.cache/pip + [[ -d src ]] && rm -rf src || true + [[ -f gmon.out ]] && rm -rf gmon.out || true +} + +build diff --git a/etc/tasks/999-clean.sh b/etc/tasks/999-clean.sh new file mode 100755 index 0000000..44f5d16 --- /dev/null +++ b/etc/tasks/999-clean.sh @@ -0,0 +1,17 @@ +#!/bin/bash +if [[ ! -f /.dockerenv ]]; then + echo "This script cannot be executed outside of a docker container." + exit 1 +fi + +sudo yum clean all + +sudo rm -rf "${HOME}/.astropy" +sudo rm -rf "${HOME}"/* +sudo rm -rf /tmp/* +sudo rm -rf /var/cache/yum + +for logfile in /var/log/* +do + [[ -f ${logfile} ]] && sudo truncate --size=0 "${logfile}" +done diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..63f0a00 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,34 @@ +#!/bin/bash -x + +prefix="${TOOLCHAIN}" +taskdir=${TOOLCHAIN_BUILD}/etc/tasks + +export _maxjobs=$(getconf _NPROCESSORS_ONLN) +export PATH="${prefix}/bin:${PATH}" +export CFLAGS="-I${prefix}/include" +export LDFLAGS="-L${prefix}/lib -Wl,-rpath=${prefix}/lib" +export PKG_CONFIG_PATH="${prefix}/lib/pkgconfig" +export PREFIX="${prefix}" + +if [[ ! -d ${taskdir} ]]; then + echo "No tasks. ${taskdir} does not exist." + exit 1 +fi + +printenv | sort + +for task in ${taskdir}/* +do + # Check for execution permission + if [[ ! -x ${task} ]]; then + echo "Skipping: ${task}" + continue + fi + echo "Executing: ${task}" + ${task} + retval=$? + if [[ ${retval} != 0 ]]; then + echo "TASK FAILED: ${task}" + exit ${retval} + fi +done diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100755 index 0000000..6298bbd --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,6 @@ +#!/bin/bash +if [[ ${#} == 0 ]]; then + exec "bash" +else + exec "${@}" +fi |