Skip to content

Instantly share code, notes, and snippets.

@kforeman
Last active December 13, 2017 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kforeman/4cd9495f0222b6fbfa79ebcee993ae78 to your computer and use it in GitHub Desktop.
Save kforeman/4cd9495f0222b6fbfa79ebcee993ae78 to your computer and use it in GitHub Desktop.
demo Docker container with working PyMB
FROM ubuntu:17.04
MAINTAINER Kyle Foreman <kfor@uw.edu>
# update/install packages
RUN apt-get update --fix-missing && \
apt-get install --yes \
wget \
curl \
bzip2 \
ca-certificates \
libglib2.0-0 \
libxext6 \
libsm6 \
libxrender1 \
git \
tar \
build-essential && \
apt-get purge && \
apt-get clean
# install Anaconda (Python 2.7)
ENV APP_DIR /srv/app
RUN mkdir -p ${APP_DIR} && \
echo 'export PATH=/opt/conda/bin:${PATH}' > /etc/profile.d/conda.sh && \
wget --quiet https://repo.continuum.io/archive/Anaconda2-5.0.1-Linux-x86_64.sh -O ~/anaconda.sh && \
/bin/bash ~/anaconda.sh -b -p ${APP_DIR}/conda && \
rm ~/anaconda.sh
ENV PATH ${APP_DIR}/conda/bin:${PATH}
RUN conda config --add channels conda-forge
## TODO: move some of these into a conda environment.yaml?
# install R
RUN conda install -c conda-forge --yes r-base=3.4.1 rpy2=2.8.5
# install xarray
RUN conda install -c conda-forge --yes xarray=0.10.0
# install scikit-sparse (sksparse)
RUN conda install -c conda-forge --yes scikit-sparse=0.4.2
# install TMB
# Note: originally tried using CRAN, but not sure where it installed e.g. Eigen etc so I had trouble compiling models...
# also, this lets us install with the fancy metis orderings
# RUN Rscript -e 'install.packages("TMB", repos="http://cran.us.r-project.org")'
ENV TMB_SHA fbdd6c2a39bdb37d467b282e9a34922179fda505
ENV TMB_DIR ${APP_DIR}/conda/lib/R/library/TMB
RUN Rscript -e 'install.packages("Matrix", repos="http://cran.us.r-project.org")' && \
wget --quiet https://github.com/kaskr/adcomp/archive/${TMB_SHA}.tar.gz -O ~/tmb.tgz && \
mkdir ${TMB_DIR} && \
tar -xzvf ~/tmb.tgz --strip 1 -C ${TMB_DIR} && \
cd ${TMB_DIR} && \
make install-metis-full && \
rm ~/tmb.tgz
# install PyMB
# specify latest commit manually since I haven't setup e.g. versioneer...
ENV PYMB_SHA 2503586a5f54318c7dc328477902b0163fda45ef
ENV PYMB_DIR ${APP_DIR}/conda/lib/python2.7/site-packages/PyMB/
RUN wget --quiet https://github.com/kforeman/pymb/archive/${PYMB_SHA}.tar.gz -O ~/pymb.tgz && \
mkdir ${PYMB_DIR} && \
tar -xzvf ~/pymb.tgz --strip 1 -C ${PYMB_DIR} && \
rm ~/pymb.tgz
# monkey patch PyMB so you can use default PyMB.model.compile() args
# I'm so, so sorry, Drew
# I welcome PRs on PyMB to make this more automagic!
RUN sed -i 's/\/usr\/share\/R\/include/\/srv\/app\/conda\/lib\/R\/include/g' ${PYMB_DIR}/model.py && \
sed -i 's/\/usr\/local\/lib\/R\/site-library\/TMB\/include/\/srv\/app\/conda\/lib\/R\/library\/TMB\/include/g' ${PYMB_DIR}/model.py && \
sed -i 's/\/usr\/lib\/R\/lib/\/srv\/app\/conda\/lib\/R\/lib/g' ${PYMB_DIR}/model.py
# run a test PyMB script to make sure it actually is able to compile and run models
## Note: should remove this from the final image
## _and I bet there's some actual testing you can do with Docker that I'm not aware of_
RUN wget --quiet https://gist.githubusercontent.com/kforeman/39a9595bf2b40df82e81aa531ea855a2/raw/951e1ed37b29e45397ee75686a5baae6e01ae30e/pymb-test-script.py -O ~/pymb-test-script.py && \
python ~/pymb-test-script.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment