Skip to content

Commit

Permalink
Add binder files
Browse files Browse the repository at this point in the history
  • Loading branch information
Bultako committed May 28, 2019
1 parent d32cc71 commit e3e1b29
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This is the Dockerfile to run Gammapy on Binder.
#

FROM continuumio/miniconda3:4.5.4
MAINTAINER Gammapy developers <gammapy@googlegroups.com>

# 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
24 changes: 24 additions & 0 deletions binder.py
Original file line number Diff line number Diff line change
@@ -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]])

0 comments on commit e3e1b29

Please sign in to comment.