Skip to content

Commit

Permalink
Docker: Allow default profile parameters to be configured through env…
Browse files Browse the repository at this point in the history
… variables (#6252)

The profile creation can now also be disabled altogether.
  • Loading branch information
unkcpz authored Jan 18, 2024
1 parent f35d7ae commit 06ea130
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
37 changes: 11 additions & 26 deletions .docker/aiida-core-base/s6-assets/init/aiida-prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,19 @@
# Environment.
export SHELL=/bin/bash

# Configure AiiDA.
export SETUP_DEFAULT_AIIDA_PROFILE=true
export AIIDA_PROFILE_NAME=default
export AIIDA_USER_EMAIL=aiida@localhost
export AIIDA_USER_FIRST_NAME=Giuseppe
export AIIDA_USER_LAST_NAME=Verdi
export AIIDA_USER_INSTITUTION=Khedivial
export AIIDA_PROFILE_PATH=/aiida/assets/config-quick-setup.yaml

# Check if user requested to set up AiiDA profile (and if it exists already)
if [[ ${SETUP_DEFAULT_AIIDA_PROFILE} == true ]] && ! verdi profile show ${AIIDA_PROFILE_NAME} &> /dev/null; then
NEED_SETUP_PROFILE=true;
else
NEED_SETUP_PROFILE=false;
fi

# Setup AiiDA profile if needed.
if [[ ${NEED_SETUP_PROFILE} == true ]]; then
# If the environment variable `SETUP_DEFAULT_AIIDA_PROFILE` is not set, set it to `true`.
if [[ ${SETUP_DEFAULT_AIIDA_PROFILE:-true} == true ]] && ! verdi profile show ${AIIDA_PROFILE_NAME} &> /dev/null; then

# Create AiiDA profile.
verdi quicksetup \
--non-interactive \
--profile "${AIIDA_PROFILE_NAME}" \
--email "${AIIDA_USER_EMAIL}" \
--first-name "${AIIDA_USER_FIRST_NAME}" \
--last-name "${AIIDA_USER_LAST_NAME}" \
--institution "${AIIDA_USER_INSTITUTION}" \
--config "${AIIDA_PROFILE_PATH}"
--profile "${AIIDA_PROFILE_NAME:-default}" \
--email "${AIIDA_USER_EMAIL:-aiida@localhost}" \
--first-name "${AIIDA_USER_FIRST_NAME:-Giuseppe}" \
--last-name "${AIIDA_USER_LAST_NAME:-Verdi}" \
--institution "${AIIDA_USER_INSTITUTION:-Khedivial}" \
--config "${AIIDA_CONFIG_FILE:-/aiida/assets/config-quick-setup.yaml}"

# Supress verdi version warning because we are using a development version
verdi config set warnings.development_version False
Expand Down Expand Up @@ -76,11 +61,11 @@ if [[ ${NEED_SETUP_PROFILE} == true ]]; then
verdi computer configure core.local "${computer_name}" \
--non-interactive \
--safe-interval 0.0

# Migration will run for the default profile.
verdi storage migrate --force
fi


# Show the default profile
verdi profile show || echo "The default profile is not set."

# Migration will run for the default profile.
verdi storage migrate --force
16 changes: 16 additions & 0 deletions docs/source/intro/run_docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ This image contains a fully pre-configured AiiDA environment which makes it part
$ docker run -it --name aiida-container aiidateam/aiida-core-with-services:latest bash
By default, an AiiDA profile is automatically set up inside the container.
To disable this default profile being created, set the ``SETUP_DEFAULT_AIIDA_PROFILE`` environment variable to ``false``.

The following environment variables can be set to configure the default AiiDA profile:
- ``AIIDA_PROFILE_NAME``: the name of the profile to be created (default: ``default``)
- ``AIIDA_USER_EMAIL``: the email of the default user to be created (default: ``aiida@localhost``)
- ``AIIDA_USER_FIRST_NAME``: the first name of the default user to be created (default: ``Giuseppe``)
- ``AIIDA_USER_LAST_NAME``: the last name of the default user to be created (default: ``Verdi``)
- ``AIIDA_USER_INSTITUTION``: the institution of the default user to be created (default: ``Khedivial``)
- ``AIIDA_CONFIG_FILE``: the path to the AiiDA configuration file used for other profile configuration parameters (default: ``/aiida/assets/config-quick-setup.yaml``).

These environment variables can be set when starting the container with the ``-e`` option.

Please note that the ``AIIDA_CONFIG_FILE`` variable points to a path inside the container.
Therefore, if you want to use a custom configuration file, it needs to be mounted from the host path to the container path.

.. grid-item-card:: Check setup

The profile named ``default`` is created under the ``aiida`` user.
Expand Down

0 comments on commit 06ea130

Please sign in to comment.