diff --git a/.travis.yml b/.travis.yml index 55da4db..025335e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,11 @@ - +sudo: true +#Required for docker build +dist: trusty language: python +services: + - docker + matrix: include: - os: linux @@ -43,7 +48,7 @@ install: conda create --yes -n test python="2.7"; fi - source activate test - - conda install --yes numpy scipy matplotlib pip nose vtk + - conda install --yes numpy scipy matplotlib pip nose vtk sip=4.18 - conda install --yes -c https://conda.anaconda.org/dlr-sc pythonocc-core - pip install setuptools - pip install enum34 @@ -51,9 +56,13 @@ install: - pip install coveralls - pip install coverage - python setup.py install - -script: coverage run test.py - + +script: + - coverage run test.py + # Docker in travis works only with linux. + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then + docker run -u root docker.io/pygemdocker/pygem:latest /bin/sh -c "cd /home/PyGeM/build/PyGeM; coverage run test.py"; + fi after_success: - coveralls diff --git a/README.md b/README.md index b72006a..8552cef 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,34 @@ To uninstall the package you have to rerun the installation and record the insta > cat installed_files.txt | xargs rm -rf ``` +Alternatively, a way to run the PyGeM library is to use our prebuilt and high-performance Docker images. +Docker containers are extremely lightweight, secure, and are based on open standards that run on all major Linux distributions, macOS and Microsoft Windows platforms. + +Install Docker for your platform by following [these instructions](https://docs.docker.com/engine/getstarted/step_one/). +If using the Docker Toolbox (macOS versions < 10.10 or Windows versions < 10), make sure you run all commands inside the Docker Quickstart Terminal. + +Now we will pull the docker.io/pygemdocker/pygem image from our cloud infrastructure: +```bash +> docker pull docker.io/pygemdocker/pygem:latest +``` +Docker will pull the latest tag of the image pygemdocker/pygem from docker.io. The download is around 3.246 GB. The image is a great place to start experimenting with PyGeM and includes all dependencies already compiled for you. +Once the download is complete you can start PyGeM for the first time. Just run: +```bash +> docker run -ti pygemdocker/pygem:latest +``` +To facilitate the devoloping, using the text editor,version control and other tools already installed on your computers, +it is possible to share files from the host into the container: + +```bash +> docker run -ti -v $(pwd):/home/PyGeM/shared pygemdocker/pygem:latest +``` +To allow the X11 forwarding in the container, on Linux system just run: + +```bash +> docker run -ti --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $(pwd):/home/PyGeM/shared pygemdocker/pygem:latest +``` + +For Windows system, you need to install Cygwin/X version and running the command in Cygwin terminal. While for mac system, you need to install xquartz. ## Documentation **PyGeM** uses [Sphinx](http://www.sphinx-doc.org/en/stable/) for code documentation. To build the html versions of the docs simply: diff --git a/dockerfiles/Dockerfile b/dockerfiles/Dockerfile new file mode 100644 index 0000000..f67b9c9 --- /dev/null +++ b/dockerfiles/Dockerfile @@ -0,0 +1,86 @@ +FROM phusion/baseimage:0.9.19 + +# Get Ubuntu updates +USER root +RUN apt-get update -q && \ + apt-get upgrade -y -o Dpkg::Options::="--force-confold" && \ + apt-get -y install sudo && \ + apt-get -y install locales && \ + echo "C.UTF-8 UTF-8" > /etc/locale.gen && \ + locale-gen && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# Set locale environment +ENV LC_ALL=C.UTF-8 \ + LANG=C.UTF-8 \ + LANGUAGE=C.UTF-8 + +# OpenBLAS threads should be 1 to ensure performance +RUN echo 1 > /etc/container_environment/OPENBLAS_NUM_THREADS && \ + echo 0 > /etc/container_environment/OPENBLAS_VERBOSE + + +# Set up user so that we do not run as root +RUN useradd -m -s /bin/bash -G sudo,docker_env PyGeM && \ + echo "PyGeM:docker" | chpasswd && \ + echo "PyGeM ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + +RUN touch /etc/service/syslog-forwarder/down +COPY set-home-permissions.sh /etc/my_init.d/set-home-permissions.sh +RUN chmod +x /etc/my_init.d/set-home-permissions.sh + +USER PyGeM +ENV HOME /home/PyGeM +RUN touch $HOME/.sudo_as_admin_successful && \ + mkdir $HOME/shared && \ + mkdir $HOME/build +VOLUME /home/PyGeM/shared + +WORKDIR /home/PyGeM +ENTRYPOINT ["sudo","/sbin/my_init","--quiet","--","sudo","-u","PyGeM","/bin/bash","-l","-c"] +CMD ["/bin/bash","-i"] + +# utilities and libraries +USER root +RUN apt-get update -y; apt-get install -y --force-yes --fix-missing --no-install-recommends curl git unzip tree subversion vim cmake bison g++ gfortran openmpi-bin pkg-config wget libpcre3-dev bison flex swig libglu1-mesa pyqt4-dev-tools +RUN apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +RUN id PyGeM +RUN chown -R PyGeM:PyGeM $HOME + +RUN cd /tmp && \ + wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh && \ + chmod +x miniconda.sh && \ + bash miniconda.sh -b -p /usr/local/miniconda && \ + rm /tmp/* +ENV PATH=/usr/local/miniconda/bin:$PATH + +RUN echo "PATH=/usr/local/miniconda/bin:$PATH" >> ~/.profile +RUN /bin/bash -c 'source ~/.profile' + +RUN hash -r && \ + conda config --set always_yes yes --set changeps1 no && \ + conda update -q conda +RUN conda info -a && \ + conda create --yes -n test python="2.7"; + +RUN /bin/bash -c 'source activate test' +# The default sip version has api that is not compatible with qt4. +RUN conda install --yes numpy scipy matplotlib pip nose vtk sip=4.18 +RUN conda install --yes -c https://conda.anaconda.org/dlr-sc pythonocc-core &&\ + pip install setuptools && \ + pip install enum34 && \ + pip install numpy-stl && \ + pip install coveralls && \ + pip install coverage + +RUN cd $HOME && \ + cd build && \ + git clone https://github.com/mathLab/PyGeM.git && \ + cd PyGeM && \ + python setup.py install + +USER PyGeM + + diff --git a/dockerfiles/set-home-permissions.sh b/dockerfiles/set-home-permissions.sh new file mode 100644 index 0000000..7e3c6d8 --- /dev/null +++ b/dockerfiles/set-home-permissions.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# User can pass e.g. --env HOST_UID=1003 so that UID in the container matches +# with the UID on the host. This is useful for Linux users, Mac and Windows +# already do transparent mapping of shared volumes. +if [ "$HOST_UID" ]; then + usermod -u $HOST_UID PyGeM +fi +if [ "$HOST_GID" ]; then + groupmod -g $HOST_GID PyGeM +fi +# This makes sure that all files in /home/fenics are accessible by the user +# fenics. We exclude the folder ~/shared to reduce IO out to the host. Docker +# for Mac, Docker for Windows and the UID/GID trick above should mean that file +# permissions work seamlessly now. +cd /home/PyGeM +find . -maxdepth 1 | grep -v "./shared" | xargs chown -R PyGeM:PyGeM +