442f9687fa6f66195f35e0f8d855517abb6c75c8
[alexxy/gromacs.git] / python_packaging / docker / ci.dockerfile
1 # Provide an easy-to-reproduce environment in which to test full Python functionality.
2
3 # Run with default command or specify one of the scripts to be executed through the entrypoint.
4 #
5 #    docker run --rm -ti gmxapi/ci-mpich:fr1 integrationtest
6 #
7 # Building:
8 #
9 # Requires Docker 17.05 or higher.
10 #
11 # Note to maintainers:
12 # Build from the GROMACS image at the current fork point. Tag with the feature
13 # name or the current revision.
14 #
15 #    FORKPOINT=$(git show -s --pretty=format:"%h" `git merge-base gerrit_master HEAD`)
16 #    REF=`git show -s --pretty=format:"%h"`
17 #    # or
18 #    REF="fr1"
19 #    docker build -t gmxapi/ci-mpich:${REF} --build-arg REF=${FORKPOINT} -f ci.dockerfile ..
20 #
21
22 ARG REF=latest
23
24 FROM gmxapi/gromacs-dependencies-mpich as python-base
25
26 RUN apt-get update && \
27     apt-get -yq --no-install-suggests --no-install-recommends install \
28         python3 \
29         python3-dev \
30         python3-venv && \
31     rm -rf /var/lib/apt/lists/*
32
33 # TODO: Use non-system Python installations for explicit version coverage.
34 # Consider pyenv for generic management of Python environment.
35
36 RUN groupadd -r testing && useradd -m -s /bin/bash -g testing testing
37
38 USER testing
39
40 ENV VENV /home/testing/venv
41 RUN python3 -m venv $VENV
42 RUN . $VENV/bin/activate && \
43     pip install --no-cache-dir --upgrade pip setuptools
44
45 ADD --chown=testing:testing requirements-*.txt /home/testing/gmxapi/
46
47 RUN . $VENV/bin/activate && \
48     pip install --no-cache-dir -r /home/testing/gmxapi/requirements-test.txt
49
50 #
51 # Use gromacs installation from gmxapi/gromacs image
52 #
53
54 FROM gmxapi/gromacs-mpich:$REF as gromacs
55 # This intermediate is necessary because the COPY command does not support syntax like the following:
56 #COPY --from=gmxapi/gromacs:$REF /usr/local/gromacs /usr/local/gromacs
57
58 FROM python-base
59
60 COPY --from=gromacs /usr/local/gromacs /usr/local/gromacs
61
62 ADD --chown=testing:testing src /home/testing/gmxapi/src
63 ADD --chown=testing:testing src/gmxapi /home/testing/gmxapi/src/gmxapi
64
65 # We use "--no-cache-dir" to reduce Docker image size. The other pip flags are
66 # to eliminate network access and speed up the build, since we already know we
67 # have installed the dependencies.
68 RUN . $VENV/bin/activate && \
69     (cd $HOME/gmxapi/src && \
70      GMXTOOLCHAINDIR=/usr/local/gromacs/share/cmake/gromacs \
71       pip install --no-cache-dir --no-deps --no-index --no-build-isolation . \
72     )
73
74 ADD --chown=testing:testing src/test /home/testing/gmxapi/test
75 ADD scripts /docker_entry_points
76 ADD --chown=testing:testing test /home/testing/test
77
78 ADD --chown=testing:testing sample_restraint /home/testing/sample_restraint
79
80 # TODO: (#3027) Get googletest sources locally.
81 RUN . $VENV/bin/activate && \
82     . /usr/local/gromacs/bin/GMXRC && \
83     (cd $HOME/sample_restraint && \
84      mkdir build && \
85      cd build && \
86      cmake .. \
87              -DDOWNLOAD_GOOGLETEST=ON \
88              -DGMXAPI_EXTENSION_DOWNLOAD_PYBIND=ON && \
89      make -j4 && \
90      make test && \
91      make install \
92     )
93
94 # TODO: this can be in the root user section above once it is stable
95 COPY docker/entrypoint.sh /
96
97 ENTRYPOINT ["/entrypoint.sh"]
98 CMD ["run_full"]
99
100
101 # MPI tests can be run in this container without requiring MPI on the host.
102 # (We suggest running your docker engine with multiple CPU cores allocated.)
103 #     docker run --rm -t gmxapi/ci:${REF} /home/testing/scripts/run_full_mpi.sh
104 # We should also try tests with an MPI-connected set of docker containers.
105
106 # To be able to step through with gdb, run with something like the following, replacing
107 # 'imagename' with the name of the docker image built with this recipe.
108 # docker run --rm -ti --security-opt seccomp=unconfined imagename bash