Minor clean-up to sample_restraint tests.
[alexxy/gromacs.git] / python_packaging / sample_restraint / Dockerfile
1 # Build docker image with sample plugin `myplugin`.
2
3 # From the root directory of the repository (where this Dockerfile is), build an image named "restraint_test" with
4 #     docker build -t sample_restraint .
5 # Note that public images for dockerhub are build with `docker build -t gmxapi/sample_restraint:tag .`
6 #
7 # Launch an ephemeral container with
8 #     docker run --rm -ti -p 8888:8888 sample_restraint
9 # for the Jupyter notebook server, or, for just a shell
10 #     docker run --rm -ti sample_restraint bash
11 # The container will be removed when the process (notebook server or shell) exits.
12 # To create and run a named container, do something like the following.
13 #     docker run -ti --name restraint_test sample_restraint
14 #
15 # Test with
16 #     docker run --cpus 2 --rm -ti sample_restraint bash -c \
17 #         "cd /home/jovyan/sample_restraint/tests && mpiexec -n 2 python -m mpi4py -m pytest"
18 # or replace `gmxapi/sample_restraint:devel` with your local image name
19
20
21 # The base image is available on DockerHub, but you can also build your own from the gmxapi repository.
22 FROM gmxapi/gmxapi:0.0.7
23
24 # Hot fix: clean out accidental cruft from an upstream base image.
25 RUN rm -rf /home/jovyan/sample_restraint /home/jovyan/plugin-build
26
27 # Grab some additional useful biomolecular simulation analysis tools.
28 RUN conda config --add channels conda-forge
29 RUN conda install mdanalysis
30
31 # This is a bit risky and troublesome, but I want to test the current repo state without committing.
32 # Another problem is that changes to directories do not trigger build cache invalidation!
33 COPY --chown=1000 CMakeLists.txt README.md /home/jovyan/sample_restraint/
34 COPY --chown=1000 cmake/ /home/jovyan/sample_restraint/cmake/
35 COPY --chown=1000 docs/ /home/jovyan/sample_restraint/docs/
36 COPY --chown=1000 src/ /home/jovyan/sample_restraint/src/
37 COPY --chown=1000 tests/ /home/jovyan/sample_restraint/tests/
38 COPY --chown=1000 examples/example.ipynb /home/jovyan/sample_restraint/examples/
39 COPY --chown=1000 examples/job.sh /home/jovyan/sample_restraint/examples/
40 COPY --chown=1000 examples/restrained-ensemble.py /home/jovyan/sample_restraint/examples/
41 COPY --chown=1000 examples/strip_notebook.py /home/jovyan/sample_restraint/examples/
42
43 # Prune the directory after removed or find will try to descend into a nonexistant directory
44 RUN find /home/jovyan -name __pycache__ -exec rm -rf \{\} \; -prune
45
46 # Build and install the plugin in the Conda virtual environment from the scipy-jupyter base image.
47 RUN mkdir /home/jovyan/plugin-build && \
48     (cd /home/jovyan/plugin-build && \
49     GROMACS_DIR=/home/jovyan/install/gromacs gmxapi_DIR=/home/jovyan/install/gromacs \
50         cmake ../sample_restraint -DPYTHON_EXECUTABLE=/opt/conda/bin/python && \
51     LD_LIBRARY_PATH=/opt/conda/lib make && \
52     make tests && \
53     make test && \
54     make install) && \
55     PYTHONPATH=plugin-build/src/pythonmodule CONDA_DIR=/opt/conda \
56         /opt/conda/bin/python -m pytest sample_restraint/tests --verbose
57
58 # The jupyter notebook server might not pick this up, but we can make it a little easier to find the
59 # `gmx` binary from the default user shell.
60 RUN echo "source install/gromacs/bin/GMXRC.bash" >> /home/jovyan/.profile