From 47148254912dad64dc77435a28a2aeb4900c066c Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Wed, 13 Mar 2024 09:26:12 +0100 Subject: [PATCH] Update base docker image and README for testing (#210) --- .docker/cp2k-code.yml | 1 - .docker/{opt => init}/add-codes.sh | 2 +- .docker/my_init.d/add-codes.sh | 7 ----- .docker/my_init.d/add-pgsql-bin-to-path.sh | 8 ----- .../dependencies.d/aiida-prepare | 0 .docker/s6-rc.d/cp2k-code-setup/timeout-up | 1 + .docker/s6-rc.d/cp2k-code-setup/type | 1 + .docker/s6-rc.d/cp2k-code-setup/up | 7 +++++ .docker/user/cp2k-code-setup | 0 .github/workflows/ci.yml | 4 +-- Dockerfile | 15 +++++----- README.md | 29 +++++++++++++++++++ 12 files changed, 48 insertions(+), 27 deletions(-) rename .docker/{opt => init}/add-codes.sh (66%) delete mode 100755 .docker/my_init.d/add-codes.sh delete mode 100755 .docker/my_init.d/add-pgsql-bin-to-path.sh create mode 100644 .docker/s6-rc.d/cp2k-code-setup/dependencies.d/aiida-prepare create mode 100644 .docker/s6-rc.d/cp2k-code-setup/timeout-up create mode 100644 .docker/s6-rc.d/cp2k-code-setup/type create mode 100644 .docker/s6-rc.d/cp2k-code-setup/up create mode 100644 .docker/user/cp2k-code-setup diff --git a/.docker/cp2k-code.yml b/.docker/cp2k-code.yml index eccd1b82..48cdb682 100644 --- a/.docker/cp2k-code.yml +++ b/.docker/cp2k-code.yml @@ -2,7 +2,6 @@ label: cp2k computer: localhost description: default_calc_job_plugin: cp2k -on_computer: True filepath_executable: /usr/bin/cp2k append_text: prepend_text: diff --git a/.docker/opt/add-codes.sh b/.docker/init/add-codes.sh similarity index 66% rename from .docker/opt/add-codes.sh rename to .docker/init/add-codes.sh index a4f0d537..5e19b3ca 100755 --- a/.docker/opt/add-codes.sh +++ b/.docker/init/add-codes.sh @@ -7,4 +7,4 @@ set -x export SHELL=/bin/bash # Install cp2k code. -verdi code show cp2k@localhost || verdi code create core.code.installed --config /opt/aiida-cp2k/.docker/cp2k-code.yml --non-interactive +verdi code show cp2k@localhost || verdi code create core.code.installed --config /home/aiida/aiida-cp2k/.docker/cp2k-code.yml --non-interactive diff --git a/.docker/my_init.d/add-codes.sh b/.docker/my_init.d/add-codes.sh deleted file mode 100755 index 96ce5692..00000000 --- a/.docker/my_init.d/add-codes.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -set -em - -su -c /opt/add-codes.sh aiida - -# Make /opt/aiida-cp2k folder editable for the $SYSTEM_USER. -chown -R ${SYSTEM_USER}:${SYSTEM_USER} /opt/aiida-cp2k/ diff --git a/.docker/my_init.d/add-pgsql-bin-to-path.sh b/.docker/my_init.d/add-pgsql-bin-to-path.sh deleted file mode 100755 index 4bd71683..00000000 --- a/.docker/my_init.d/add-pgsql-bin-to-path.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -set -em - -# The following works in non-interactive mode -sed -i '1i export PATH=${PATH}:/opt/conda/envs/pgsql/bin/' /home/aiida/.bashrc - -# The following works in interactive mode -echo 'export PATH=${PATH}:/opt/conda/envs/pgsql/bin/' >> /home/aiida/.bashrc diff --git a/.docker/s6-rc.d/cp2k-code-setup/dependencies.d/aiida-prepare b/.docker/s6-rc.d/cp2k-code-setup/dependencies.d/aiida-prepare new file mode 100644 index 00000000..e69de29b diff --git a/.docker/s6-rc.d/cp2k-code-setup/timeout-up b/.docker/s6-rc.d/cp2k-code-setup/timeout-up new file mode 100644 index 00000000..573541ac --- /dev/null +++ b/.docker/s6-rc.d/cp2k-code-setup/timeout-up @@ -0,0 +1 @@ +0 diff --git a/.docker/s6-rc.d/cp2k-code-setup/type b/.docker/s6-rc.d/cp2k-code-setup/type new file mode 100644 index 00000000..bdd22a18 --- /dev/null +++ b/.docker/s6-rc.d/cp2k-code-setup/type @@ -0,0 +1 @@ +oneshot diff --git a/.docker/s6-rc.d/cp2k-code-setup/up b/.docker/s6-rc.d/cp2k-code-setup/up new file mode 100644 index 00000000..4d07d014 --- /dev/null +++ b/.docker/s6-rc.d/cp2k-code-setup/up @@ -0,0 +1,7 @@ +#!/command/execlineb -S0 + +with-contenv + +foreground { s6-echo "Setting up CP2K code" } + +/etc/init/add-codes.sh diff --git a/.docker/user/cp2k-code-setup b/.docker/user/cp2k-code-setup new file mode 100644 index 00000000..e69de29b diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b4dc74c..9a5febff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,9 +47,9 @@ jobs: - name: Create container from aiida_cp2k_test image and test the plugin inside run: | export DOCKERID=`docker run -d aiida_cp2k_test` - docker exec --tty $DOCKERID wait-for-services + sleep 5 docker logs $DOCKERID - docker exec --tty --user aiida $DOCKERID /bin/bash -l -c 'cd /opt/aiida-cp2k/ && py.test --cov aiida_cp2k --cov-append .' + docker exec --tty --user aiida $DOCKERID /bin/bash -l -c 'cd /home/aiida/aiida-cp2k/ && py.test --cov aiida_cp2k --cov-append .' pre-commit: diff --git a/Dockerfile b/Dockerfile index edfff037..cc0efbd5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,13 +5,13 @@ # For further information on the license, see the LICENSE.txt file. # ############################################################################### -FROM aiidateam/aiida-core:2.1.2 +FROM aiidateam/aiida-core-with-services:2.5.0 # To prevent the container to exit prematurely. ENV KILL_ALL_RPOCESSES_TIMEOUT=50 -WORKDIR /opt/ +USER root # Install statically linked CP2K which is a considerably newer release than Debian builtin. # The statically linked CP2K is a non-MPI binary, but we're running all tests with 1 MPI proc. RUN set -ex ; \ @@ -21,16 +21,15 @@ RUN set -ex ; \ echo "1e6fccf901873ebe9c827f45fb29331f599772f6e6281e988d8956c7a3aa143c /usr/bin/cp2k" | sha256sum -c ; \ chmod +x /usr/bin/cp2k +USER aiida # Install aiida-cp2k plugin. -COPY . aiida-cp2k +COPY --chown="${SYSTEM_UID}:${SYSTEM_GID}" . /home/aiida/aiida-cp2k RUN pip install ./aiida-cp2k[dev,docs] # Install coverals. RUN pip install coveralls # Install the cp2k code. -COPY .docker/opt/add-codes.sh /opt/ -COPY .docker/my_init.d/add-codes.sh /etc/my_init.d/50_add-codes.sh - -# Add PGSQL bin folder to PATH. -COPY .docker/my_init.d/add-pgsql-bin-to-path.sh /etc/my_init.d/50_add-pgsql-bin-to-path.sh +COPY .docker/init/add-codes.sh /etc/init/ +COPY .docker/s6-rc.d/cp2k-code-setup /etc/s6-overlay/s6-rc.d/cp2k-code-setup +COPY .docker/user/cp2k-code-setup /etc/s6-overlay/s6-rc.d/user/contents.d/cp2k-code-setup diff --git a/README.md b/README.md index 01d6debe..37c89eba 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ pip install -e . # Also installs aiida, if missing (but not postgres/rabbitmq). ## For maintainers +### Release + To create a new release, clone the repository, install development dependencies with `pip install '.[dev]'`, and then execute `bumpver update --major/--minor/--patch`. This will: @@ -43,6 +45,33 @@ Additional notes: - The release tag (e.g. a/b/rc) is determined from the last release. Use the `--tag` option to override the release tag. +### Testing + +To run the tests, you need to have Docker installed in your system. +Once this is done, you can build the Docker image with the following command: + +```bash +docker build -t aiida_cp2k_test . +``` +Then, you can launch the container: + +```bash +DOKERID=`docker run -it aiida_cp2k_test` +``` +This will remeber the container ID in the variable `DOKERID`. +You can then run the tests with the following command: + +```bash +docker exec --tty --user aiida $DOCKERID /bin/bash -l -c 'cd /home/aiida/aiida-cp2k/ && pytest' +``` + +To enter the container for manual testing do: + +```bash +docker exec -it --user aiida $DOCKERID bash +``` + + ## License MIT