aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Dockerfile54
-rw-r--r--LICENSE29
-rwxr-xr-xbuild.sh31
-rwxr-xr-xpublish.sh32
-rwxr-xr-xspawner.sh3
-rwxr-xr-xwith_env36
6 files changed, 185 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..4364f1a
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,54 @@
+ARG PYTHON_VERSION=${PYTHON_VERSION:-latest}
+FROM astroconda/datb-tc-python:${PYTHON_VERSION}
+
+# Declare environment
+ENV OPT=/opt \
+ HOME=/home/jenkins \
+ PYTHONUNBUFFERED=1
+
+# Toolchain
+RUN yum update -y && yum install -y \
+ bzip2-devel \
+ curl \
+ git \
+ glibc-devel.i686 \
+ glibc-devel \
+ hg \
+ java-1.8.0-openjdk-devel \
+ kernel-devel \
+ libX11-devel \
+ mesa-libGL \
+ mesa-libGLU \
+ ncurses-devel \
+ openssh-server \
+ subversion \
+ sudo \
+ wget \
+ zlib-devel \
+ && yum clean all
+
+# SSH Server configuration
+# Create 'jenkins' user
+# Configure sudoers
+RUN sed -i 's|#UseDNS.*|UseDNS no|' /etc/ssh/sshd_config \
+ && ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa \
+ && ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa \
+ && groupadd jenkins \
+ && useradd -g jenkins -m -d $HOME -s /bin/bash jenkins \
+ && echo "jenkins:jenkins" | chpasswd \
+ && echo "jenkins ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers \
+ && chown -R jenkins:jenkins ${TOOLCHAIN}
+
+
+# Inject custom handlers
+RUN curl -L https://github.com/krallin/tini/releases/download/v0.18.0/tini-static-amd64 > /usr/bin/tini \
+ && chmod +x /usr/bin/tini
+
+ADD with_env /usr/local/bin
+ADD spawner.sh /usr/local/bin
+
+WORKDIR ${HOME}
+
+EXPOSE 22
+ENTRYPOINT ["tini", "-g", "--", "spawner.sh"]
+CMD ["/bin/bash"]
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..0693ef5
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,29 @@
+BSD 3-Clause License
+
+Copyright (c) 2019, AstroConda
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the name of the copyright holder nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..379e31b
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,31 @@
+PYTHON_VERSION=${PYTHON_VERSION:-}
+HUB=${HUB:-}
+
+if [[ -n ${1} ]]; then
+ PYTHON_VERSION=${1}
+fi
+
+if [[ -n ${2} ]]; then
+ HUB=${2}
+fi
+
+
+if [[ -z ${PYTHON_VERSION} ]]; then
+ echo "Missing python version (format: x.y.z)"
+ exit 1
+fi
+
+if [[ -z ${HUB} ]]; then
+ echo "Missing dockerhub repo (format: reponame)"
+ exit 1
+fi
+
+short_version=${PYTHON_VERSION/./}
+if [[ ${#short_version} < 2 ]]; then
+ echo "Python version is too short. Must be in x.y.z format"
+ exit 1
+fi
+short_version=${short_version:0:2}
+IMAGE="buildsys-py${short_version}"
+
+docker build --build-arg PYTHON_VERSION=${PYTHON_VERSION} -t buildsys-py${short_version} .
diff --git a/publish.sh b/publish.sh
new file mode 100755
index 0000000..9a0fa45
--- /dev/null
+++ b/publish.sh
@@ -0,0 +1,32 @@
+PYTHON_VERSION=${PYTHON_VERSION:-}
+HUB=${HUB:-}
+
+if [[ -n ${1} ]]; then
+ PYTHON_VERSION=${1}
+fi
+
+if [[ -n ${2} ]]; then
+ HUB=${2}
+fi
+
+
+if [[ -z ${PYTHON_VERSION} ]]; then
+ echo "Missing python version (format: x.y.z)"
+ exit 1
+fi
+
+if [[ -z ${HUB} ]]; then
+ echo "Missing dockerhub repo (format: reponame)"
+ exit 1
+fi
+
+short_version=${PYTHON_VERSION/./}
+if [[ ${#short_version} < 2 ]]; then
+ echo "Python version is too short. Must be in x.y.z format"
+ exit 1
+fi
+short_version=${short_version:0:2}
+IMAGE="buildsys-py${short_version}"
+
+docker tag ${IMAGE} ${HUB}/${IMAGE}
+docker push ${HUB}/${IMAGE}
diff --git a/spawner.sh b/spawner.sh
new file mode 100755
index 0000000..94bee44
--- /dev/null
+++ b/spawner.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+limit="${TIMEOUT:-45m}"
+exec timeout -sTERM ${limit} "$@"
diff --git a/with_env b/with_env
new file mode 100755
index 0000000..c94e8b9
--- /dev/null
+++ b/with_env
@@ -0,0 +1,36 @@
+#!/bin/bash
+set +x
+environ=base
+commands=()
+
+while [[ $# > 0 ]]
+do
+ key="$1"
+ case $key in
+ -n|--name)
+ environ="$2"
+ shift 2
+ ;;
+ *)
+ commands+=("$1")
+ shift
+ ;;
+ esac
+done
+
+
+type conda &>/dev/null
+if [[ $? != 0 ]]; then
+ venv_root=${HOME}/.venvs
+ venv_path=${venv_root}/${environ}
+
+ [[ ! -d ${venv_root} ]] && mkdir -p ${venv_root}
+ [[ ! -d ${venv_path} ]] && python -m venv "${venv_path}"
+
+ source "${venv_path}/bin/activate"
+else
+ source activate ${environ}
+fi
+
+"${commands[@]}"
+exit $?