diff --git a/.github/actions/create-dev-env/action.yml b/.github/actions/create-dev-env/action.yml index b8b3d3d40..8cae2abd9 100644 --- a/.github/actions/create-dev-env/action.yml +++ b/.github/actions/create-dev-env/action.yml @@ -21,7 +21,5 @@ runs: python-version: 3.x - name: Install Dev Dependencies 📦 - run: | - pip install --upgrade pip - pip install --upgrade -r docker/requirements-dev.txt + run: pip install -r requirements-docker.txt shell: bash diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..45d808de8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,47 @@ +# syntax=docker/dockerfile:1 +FROM ghcr.io/astral-sh/uv:0.2.18 as uv +FROM ghcr.io/aiidalab/full-stack:2024.1021 + +USER ${NB_USER} + +ENV QE_VERSION "7.2" + +# 1. Install Quantum Espresso into a conda environment +RUN mamba create -n quantum-espresso --yes qe=${QE_VERSION} && \ + mamba clean --all -f -y + +# 2. Prepare AiiDA profile and localhost computer +# (we do this here for better caching during Docker build) +RUN bash /usr/local/bin/before-notebook.d/20_start-postgresql.sh && \ + bash /usr/local/bin/before-notebook.d/40_prepare-aiida.sh && \ + verdi daemon stop && \ + mamba run -n aiida-core-services pg_ctl stop + +# 3. Copy the whole repo +ENV QE_APP_FOLDER ${AIIDALAB_APPS}/quantum-espresso +COPY --chown=${NB_UID}:${NB_GID} . ${QE_APP_FOLDER} + +WORKDIR ${QE_APP_FOLDER} +# 4.Install python dependencies +# Use uv instead of pip to speed up installation, per docs: +# https://github.com/astral-sh/uv/blob/main/docs/guides/docker.md#using-uv-temporarily +# Use the same constraint file as pip +ENV UV_CONSTRAINT ${PIP_CONSTRAINT} +RUN --mount=from=uv,source=/uv,target=/bin/uv \ + # Remove all untracked files and directories. + git clean -fx && \ + uv pip install --system --no-cache . + +# 5. Install the QE pseudopotentials and codes +RUN bash /usr/local/bin/before-notebook.d/20_start-postgresql.sh && \ + python -m aiidalab_qe install-qe && \ + python -m aiidalab_qe install-pseudos && \ + mamba run -n aiida-core-services pg_ctl stop + +USER root +COPY ./before-notebook.d/* /usr/local/bin/before-notebook.d/ +RUN fix-permissions "${CONDA_DIR}" && \ + fix-permissions "/home/${NB_USER}" + +USER ${NB_USER} +WORKDIR "/home/${NB_USER}" diff --git a/before-notebook.d/00_untar_home.sh b/before-notebook.d/00_untar_home.sh new file mode 100644 index 000000000..e81f23beb --- /dev/null +++ b/before-notebook.d/00_untar_home.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# +set -euo pipefail + +home="/home/${NB_USER}" + +if [[ ! -d ${home} ]]; then + echo "Directory $home does not exist!" + exit 1 +fi + +# Untar home archive file to restore home directory if it is empty +if [[ $(ls -A ${home} | wc -l) = "0" ]];then + if [ -f /opt/home.tar ]; then + # untar /opt/home.tar to /home/jovyan to restore home directory + echo "Untarring /opt/home.tar to /home/jovyan" + tar -xf /opt/home.tar -C /home/jovyan + fi +fi diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index cc6dc423c..000000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,52 +0,0 @@ -# syntax=docker/dockerfile:1 -FROM ghcr.io/astral-sh/uv:0.2.18 as uv -FROM base-image - -USER ${NB_USER} - -ENV QE_VERSION ${QE_VERSION} -RUN mamba create -p /opt/conda/envs/quantum-espresso --yes \ - qe=${QE_VERSION} \ - && mamba clean --all -f -y && \ - fix-permissions "${CONDA_DIR}" && \ - fix-permissions "/home/${NB_USER}" - -# Copy whole repo and pre-install the dependencies and app to the tmp folder. -# In the before notebook scripts the app will be re-installed by moving it to the app folder. -ENV PREINSTALL_APP_FOLDER ${CONDA_DIR}/aiidalab-qe -COPY --chown=${NB_UID}:${NB_GID} --from=src . ${PREINSTALL_APP_FOLDER} - -# Using uv to speed up installation, per docs: -# https://github.com/astral-sh/uv/blob/main/docs/guides/docker.md#using-uv-temporarily -# Use the same constraint file as PIP -ENV UV_CONSTRAINT ${PIP_CONSTRAINT} -RUN --mount=from=uv,source=/uv,target=/bin/uv \ - cd ${PREINSTALL_APP_FOLDER} && \ - # Remove all untracked files and directories. For example the setup lock flag file. - git clean -fx && \ - # It is important to install from `aiidalab install` to mimic the exact installation operation as - # from the app store. - # The command wil first install the dependencies from list by parsing setup config files, - # (for `aiidalab/aiidalab<23.03.2` the `setup.py` should be in the root folder of the app https://github.com/aiidalab/aiidalab/pull/382). - # and then the app and restart the daemon in the end. - # But since the aiida profile not yet exists, the daemon restart will fail but it is not a problem. - # Because we only need the dependencies to be installed. - # aiidalab install --yes --python ${CONDA_DIR}/bin/python "quantum-espresso@file://${PREINSTALL_APP_FOLDER}" && \ - # However, have to use `pip install` explicitly because `aiidalab install` call `pip install --user` which will install the app to `/home/${NB_USER}/.local`. - # It won't cause issue for docker but for k8s deployment the home folder is not bind mounted to the pod and the dependencies won't be found. (see issue in `jupyter/docker-stacks` https://github.com/jupyter/docker-stacks/issues/815) - uv pip install --system --no-cache . && \ - fix-permissions "${CONDA_DIR}" && \ - fix-permissions "/home/${NB_USER}" - -# The app version is used for installing the app when first time the container is started. -ARG APP_VERSION -ENV APP_VERSION ${APP_VERSION} - -# Download the QE pseudopotentials to the folder for afterware installation. -ENV PSEUDO_FOLDER ${CONDA_DIR}/pseudo -RUN mkdir -p ${PSEUDO_FOLDER} && \ - python -m aiidalab_qe download-pseudos --dest ${PSEUDO_FOLDER} - -COPY before-notebook.d/* /usr/local/bin/before-notebook.d/ - -WORKDIR "/home/${NB_USER}" diff --git a/docker/before-notebook.d/70_prepare-qe-executable.sh b/docker/before-notebook.d/70_prepare-qe-executable.sh deleted file mode 100644 index 41ba2d391..000000000 --- a/docker/before-notebook.d/70_prepare-qe-executable.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -e - -# Debugging. -set -x - -# Copy quantum espresso env to user space. -mkdir -p /home/${NB_USER}/.conda/envs -if [ ! -d /home/${NB_USER}/.conda/envs/quantum-espresso-${QE_VERSION} ]; then - ln -s /opt/conda/envs/quantum-espresso /home/${NB_USER}/.conda/envs/quantum-espresso-${QE_VERSION} - - # Install qe so the progress bar not shown in the notebook when first time using app. - echo "Installing qe." - python -m aiidalab_qe install-qe -else - echo "Quantum ESPRESSO app is already installed." -fi diff --git a/docker/before-notebook.d/71_install-qeapp.sh b/docker/before-notebook.d/71_install-qeapp.sh deleted file mode 100644 index 849d92849..000000000 --- a/docker/before-notebook.d/71_install-qeapp.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -# Debugging. -set -x - -# Install qeapp if it is not already installed. -if aiidalab list | grep -q quantum-espresso; then - echo "Quantum ESPRESSO app is already installed." -else - echo "Installing Quantum ESPRESSO app." - # Install by move the repo folder that is already in the image. - mv ${PREINSTALL_APP_FOLDER} /home/${NB_USER}/apps/quantum-espresso -fi - -# Install the pseudo libraries if not already installed. -if aiida-pseudo list | grep -q "no pseudo potential families"; then - echo "Installing pseudo potential families." - python -m aiidalab_qe install-pseudos --source ${PSEUDO_FOLDER} -else - echo "Pseudo potential families are already installed." -fi diff --git a/docker/build.json b/docker/build.json deleted file mode 100644 index 44dc1b92a..000000000 --- a/docker/build.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "variable": { - "AIIDALAB_BASE_IMAGE": { - "default": "ghcr.io/aiidalab/full-stack:2024.1019" - }, - "QE_VERSION": { - "default": "7.2" - } - } -} diff --git a/docker/docker-bake.hcl b/docker/docker-bake.hcl deleted file mode 100644 index 97017844f..000000000 --- a/docker/docker-bake.hcl +++ /dev/null @@ -1,27 +0,0 @@ -# docker-bake.hcl for building QeApp images -group "default" { - targets = ["qe"] -} - -variable "QE_VERSION" { -} - -variable "BASE_IMAGE" { - default = "aiidalab/full-stack:latest" -} - -variable "ORGANIZATION" { - default = "aiidalab" -} - -target "qe" { - tags = ["${ORGANIZATION}/qe:newly-baked"] - context = "." - contexts = { - src = ".." - base-image = "docker-image://${BASE_IMAGE}" - } - args = { - "QE_VERSION" = "${QE_VERSION}" - } -} diff --git a/docker/requirements-dev.txt b/requirements-docker.txt similarity index 100% rename from docker/requirements-dev.txt rename to requirements-docker.txt