Skip to content

Commit

Permalink
New conda environments in ~/.conda/ by default (#348)
Browse files Browse the repository at this point in the history
Before this change, a new conda environment with `conda create --name new-env` would
be located in `/opt/conda/envs`, but that's no good since it will not be persisted between
container invocation.

In this PR, I modify the conda config so that the new environments are created in `~/.conda/envs/`
by default.
  • Loading branch information
danielhollas authored Jan 4, 2023
1 parent e893381 commit e957633
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stack/base-with-services/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ WORKDIR /opt/

ARG AIIDA_VERSION

RUN mamba create -n aiida-core-services --yes \
RUN mamba create -p /opt/conda/envs/aiida-core-services --yes \
aiida-core.services=${AIIDA_VERSION} \
rabbitmq-server=3.8.14 \
&& mamba clean --all -f -y && \
Expand Down
7 changes: 7 additions & 0 deletions stack/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ fi\n' >> "/home/${NB_USER}/.bashrc"
# Add ~/.local/bin to PATH where the dependencies get installed via pip
ENV PATH=${PATH}:/home/${NB_USER}/.local/bin

# Add conda envs_dirs in home directory,
# which will persist between container invocation
# NOTE: The order here is important!
# We want conda to create environments in ~/.conda/ by default
RUN conda config --system --add envs_dirs /opt/conda
RUN conda config --system --add envs_dirs "~/.conda/envs"

USER ${NB_USER}

WORKDIR "/home/${NB_USER}"
Expand Down
3 changes: 3 additions & 0 deletions tests/test_aiidalab.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def test_aiidalab_available(aiidalab_exec, nb_user, variant):
def test_create_conda_environment(aiidalab_exec, nb_user):
output = aiidalab_exec("conda create -y -n tmp", user=nb_user).decode().strip()
assert "conda activate tmp" in output
# New conda environments should be created in ~/.conda/envs/
output = aiidalab_exec("conda env list", user=nb_user).decode().strip()
assert f"/home/{nb_user}/.conda/envs/tmp" in output


def test_correct_python_version_installed(aiidalab_exec, python_version):
Expand Down

0 comments on commit e957633

Please sign in to comment.