From 1311b3264e513230f3e84d5ce2a03d58e73407fa Mon Sep 17 00:00:00 2001
From: Gregory Ashton <gregory.ashton@ligo.org>
Date: Wed, 9 Jan 2019 17:44:48 -0600
Subject: [PATCH] Improvements to the containers

---
 .gitlab-ci.yml                            | 17 +++----
 containers/Dockerfile-test-suite-python27 | 58 +++++++++++++++++++++
 containers/Dockerfile-test-suite-python37 | 62 +++++++++++++++++++++++
 containers/Singularity.0.3.3              | 14 +++++
 setup.cfg                                 |  2 +-
 singularity/Singularity.0.3.3             | 35 -------------
 6 files changed, 141 insertions(+), 47 deletions(-)
 create mode 100644 containers/Dockerfile-test-suite-python27
 create mode 100644 containers/Dockerfile-test-suite-python37
 create mode 100644 containers/Singularity.0.3.3
 delete mode 100644 singularity/Singularity.0.3.3

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index bbba15096..183523390 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -14,12 +14,10 @@ stages:
   - deploy
 
 # test example on python 2
-python-2:
+python-2.7:
   stage: test
-  image: bilbydev/test-suite-py2
+  image: bilbydev/bilby-test-suite-python27
   before_script:
-    # Source the .bashrc for MultiNest
-    - source /root/.bashrc
     # Install the dependencies specified in the Pipfile
     - pipenv install --two --python=/opt/conda/bin/python2 --system --deploy
   script:
@@ -28,12 +26,10 @@ python-2:
     - pytest --ignore=test/utils_py3_test.py
 
 # test example on python 3
-python-3:
+python-3.7:
   stage: test
-  image: bilbydev/test-suite-py3
+  image: bilbydev/bilby-test-suite-python37
   before_script:
-    # Source the .bashrc for MultiNest
-    - source /root/.bashrc
     # Install the dependencies specified in the Pipfile
     - pipenv install --three --python=/opt/conda/bin/python --system --deploy
   script:
@@ -49,7 +45,6 @@ python-3:
 
     # Make the documentation
     - cd docs
-    - conda install -y make
     - make clean
     - make html
 
@@ -62,8 +57,8 @@ python-3:
 pages:
   stage: deploy
   dependencies:
-    - python-3
-    - python-2
+    - python-3.7
+    - python-2.7
   script:
     - mkdir public/
     - mv htmlcov/ public/
diff --git a/containers/Dockerfile-test-suite-python27 b/containers/Dockerfile-test-suite-python27
new file mode 100644
index 000000000..fc8d72841
--- /dev/null
+++ b/containers/Dockerfile-test-suite-python27
@@ -0,0 +1,58 @@
+FROM ubuntu:18.04
+
+LABEL name="bilby Base Enterprise Linux 7" \
+maintainer="Gregory Ashton <gregory.ashton@ligo.org>" \
+date="20190104"
+
+ENV PATH /opt/conda/bin:$PATH
+
+# Install backend
+RUN apt-get update --fix-missing \
+&& apt-get install -y libglib2.0-0 libxext6 libsm6 libxrender1 libgl1-mesa-glx \
+dh-autoreconf build-essential libarchive-dev wget curl git libhdf5-serial-dev
+
+# Install python2.7
+RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda2-4.5.11-Linux-x86_64.sh -O ~/miniconda.sh && \
+/bin/bash ~/miniconda.sh -b -p /opt/conda && \
+rm ~/miniconda.sh && \
+ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
+echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
+echo "conda activate base" >> ~/.bashrc
+
+# Install conda-installable programs
+RUN conda install -y numpy>=1.9 scipy>=0.16 matplotlib>=2.0 pandas
+
+RUN conda install -c conda-forge deepdish
+
+# Install requirements
+RUN pip install --upgrade pip \
+&& pip install --upgrade setuptools \
+&& pip install future \
+pycondor>=0.5 \
+configargparse \
+flake8 \
+mock \
+pipenv \
+coverage \
+pytest-cov \
+coverage-badge
+
+# Install additional bilby requirements
+RUN pip install corner lalsuite astropy gwpy theano
+
+# Install samplers
+RUN pip install cpnest dynesty emcee nestle ptemcee pymc3 pymultinest
+
+# Install pymultinest requirements
+RUN apt-get install -y libblas3 libblas-dev liblapack3 liblapack-dev \
+libatlas3-base libatlas-base-dev cmake build-essential gfortran
+
+# Install pymultinest
+RUN git clone https://github.com/JohannesBuchner/MultiNest \
+&& (cd MultiNest/build && cmake .. && make)
+
+ENV LD_LIBRARY_PATH $HOME/MultiNest/lib:
+
+# Install Polychord
+RUN git clone https://github.com/PolyChord/PolyChordLite.git \
+&& (cd PolyChordLite && make pypolychord  MPI= && python setup.py install)
diff --git a/containers/Dockerfile-test-suite-python37 b/containers/Dockerfile-test-suite-python37
new file mode 100644
index 000000000..beecf97ae
--- /dev/null
+++ b/containers/Dockerfile-test-suite-python37
@@ -0,0 +1,62 @@
+FROM ubuntu:18.04
+
+LABEL name="bilby Base Enterprise Linux 7" \
+maintainer="Gregory Ashton <gregory.ashton@ligo.org>" \
+date="20190104"
+
+ENV PATH /opt/conda/bin:$PATH
+
+# Install backend
+RUN apt-get update --fix-missing \
+&& apt-get install -y libglib2.0-0 libxext6 libsm6 libxrender1 libgl1-mesa-glx \
+dh-autoreconf build-essential libarchive-dev wget curl git libhdf5-serial-dev
+
+# Install python3.7
+RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-4.5.11-Linux-x86_64.sh -O ~/miniconda.sh && \
+/bin/bash ~/miniconda.sh -b -p /opt/conda && \
+rm ~/miniconda.sh && \
+/opt/conda/bin/conda clean -tipsy && \
+ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
+echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
+echo "conda activate base" >> ~/.bashrc
+
+# Install conda-installable programs
+RUN conda install -y numpy>=1.9 scipy>=0.16 matplotlib>=2.0 pandas
+
+RUN conda install -c conda-forge deepdish
+
+# Install requirements
+RUN pip install --upgrade pip \
+&& pip install --upgrade setuptools \
+&& pip install future \
+pycondor>=0.5 \
+configargparse \
+flake8 \
+mock \
+pipenv \
+coverage \
+pytest-cov \
+coverage-badge
+
+# Install documentation requirements
+RUN pip install sphinx numpydoc nbsphinx sphinx_rtd_theme sphinx-tabs
+
+# Install additional bilby requirements
+RUN pip install corner lalsuite astropy gwpy theano
+
+# Install samplers
+RUN pip install cpnest dynesty emcee nestle ptemcee pymc3 pymultinest
+
+# Install pymultinest requirements
+RUN apt-get install -y libblas3 libblas-dev liblapack3 liblapack-dev \
+libatlas3-base libatlas-base-dev cmake build-essential gfortran
+
+# Install pymultinest
+RUN git clone https://github.com/JohannesBuchner/MultiNest \
+&& (cd MultiNest/build && cmake .. && make)
+
+ENV LD_LIBRARY_PATH $HOME/MultiNest/lib:
+
+# Install Polychord
+RUN git clone https://github.com/PolyChord/PolyChordLite.git \
+&& (cd PolyChordLite && make pypolychord  MPI= && python setup.py install)
diff --git a/containers/Singularity.0.3.3 b/containers/Singularity.0.3.3
new file mode 100644
index 000000000..fe1506c75
--- /dev/null
+++ b/containers/Singularity.0.3.3
@@ -0,0 +1,14 @@
+Bootstrap: docker
+From: bilbydev/bilby-test-suite-python37
+
+%help
+A singularity container for running bilby scripts. To use, simply execute the
+container, providing the bilby_script and any additional arguments. E.g.,
+
+./name_of_this_container.simg run_script.py
+
+%post
+pip install bilby==0.3.3
+
+%runscript
+exec /opt/conda/bin/python "$@"
diff --git a/setup.cfg b/setup.cfg
index 5451ba470..2c867fe83 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,7 +1,7 @@
 [flake8]
 exclude = .git,docs,build,dist,test,*__init__.py
 max-line-length = 160
-ignore = E129
+ignore = E129 W504 W605
 
 [tool:pytest]
 addopts =
diff --git a/singularity/Singularity.0.3.3 b/singularity/Singularity.0.3.3
deleted file mode 100644
index 5a7eb1170..000000000
--- a/singularity/Singularity.0.3.3
+++ /dev/null
@@ -1,35 +0,0 @@
-Bootstrap: debootstrap
-OSVersion: bionic
-MirrorURL: http://us.archive.ubuntu.com/ubuntu/
-
-%help
-A singularity container for running bilby scripts. Built from Ubuntu 18.04,
-this contains all the software to run bilby. Available samplers are "dynesty"
-and "nestle". Other samplers will be added in the future.
-
-%post
-apt-get update && apt-get install -y --no-install-recommends apt-utils
-apt-get install -y curl
-apt-get install -y gcc
-apt-get install -y libgl1-mesa-glx
-apt-get install -y libdpkg-perl
-apt-get install -y python3
-apt-get install -y python3-dev
-apt-get install -y python3-distutils
-curl -sS https://bootstrap.pypa.io/get-pip.py | python3
-pip install --upgrade pip
-pip install future
-pip install corner
-pip install numpy>=1.9
-pip install matplotlib>=2.0
-pip install scipy>=0.16
-pip install pandas
-pip install deepdish
-pip install mock
-pip install dynesty
-pip install nestle
-pip install astropy
-pip install lalsuite
-pip install urllib3
-pip install gwpy
-pip install bilby==0.3.3
-- 
GitLab