diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..78784d9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +# This is the Dockerfile to run Gammapy on Binder. +# + +FROM continuumio/miniconda3:4.5.4 +MAINTAINER Gammapy developers + +# compilers +RUN apt-get update && apt-get install -y build-essential +RUN pip install --upgrade pip + +# install dependencies - including the stable version of Gammapy +COPY binder.py tmp/ +RUN curl -o tmp/environment.yml https://gammapy.org/download/install/gammapy-0.8-environment.yml + +WORKDIR tmp/ +RUN conda update conda +RUN conda install -q -y pyyaml +RUN python binder.py + +# add gammapy user running the jupyter notebook process +ENV NB_USER gammapy +ENV NB_UID 1000 +ENV HOME /home/${NB_USER} + +RUN adduser --disabled-password \ + --gecos "Default user" \ + --uid ${NB_UID} \ + ${NB_USER} + +# download tutorials and datasets +RUN gammapy download notebooks --out=${HOME}/gammapy-tutorials --release=0.8 +RUN gammapy download datasets --out=${HOME}/gammapy-datasets --release=0.8 + +# setting ownerships +USER root +RUN chown -R gammapy:gammapy ${HOME} + +# start JupyterLab server in tutorials dir +USER ${NB_USER} +WORKDIR ${HOME}/gammapy-tutorials/notebooks-0.8 + +# env vars used in tutorials +ENV GAMMAPY_DATA ${HOME}/gammapy-datasets diff --git a/binder.py b/binder.py new file mode 100755 index 0000000..abd6785 --- /dev/null +++ b/binder.py @@ -0,0 +1,24 @@ +"""Install code on Binder. + +This script is executed from Dockerfile configuration file +It installs software dependencies declared in environment.yml +in the docker container built for the Binder service. +""" +import yaml +import conda.cli +from pip._internal import main as pip_main + +with open("environment.yml") as stream: + content = yaml.load(stream) + +for chan in content['channels']: + print("RUN conda config --add channels {}".format(chan)) + conda.cli.main('conda', 'config', '--add', 'channels', chan) + +for pack in content['dependencies']: + if isinstance(pack, str): + print("RUN conda install -q -y {}".format(pack)) + conda.cli.main('conda', 'install', '-y', '-q', pack) + else: + print("RUN pip install {}".format(pack['pip'][0])) + pip_main(["install", pack['pip'][0]])