Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slim image based on mambaorg/micromamba #319

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions docker-compose.slim.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
version: '3.4'

services:

database:
image: postgres:12.3
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
volumes:
- aiida-postgres-db:/var/lib/postgresql/data
healthcheck:
interval: 5s
timeout: 5s
retries: 10

messaging:
image: rabbitmq:3.8.3-management
environment:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
volumes:
- aiida-rmq-data:/var/lib/rabbitmq/

aiida:
image: 88ed76fefd33
environment:
RMQHOST: messaging
TZ: Europe/Zurich
SETUP_DEFAULT_AIIDA_PROFILE: 'true'
volumes:
- aiida-home-folder:/home/aiida
depends_on:
database:
condition: service_started
messaging:
condition: service_started
command: tail -f /dev/null

volumes:
aiida-postgres-db:
aiida-rmq-data:
aiida-home-folder:
49 changes: 49 additions & 0 deletions stack/slim/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
FROM mambaorg/micromamba:0.27-jammy
ARG NEW_MAMBA_USER=aiida
ARG NEW_MAMBA_USER_ID=1000
ARG NEW_MAMBA_USER_GID=1000

USER root
RUN usermod "--login=${NEW_MAMBA_USER}" "--home=/home/${NEW_MAMBA_USER}" \
--move-home "-u ${NEW_MAMBA_USER_ID}" "${MAMBA_USER}" && \
groupmod "--new-name=${NEW_MAMBA_USER}" \
"-g ${NEW_MAMBA_USER_GID}" "${MAMBA_USER}" && \
# Update the expected value of MAMBA_USER for the
# _entrypoint.sh consistency check.
echo "${NEW_MAMBA_USER}" > "/etc/arg_mamba_user" && \
:

ENV MAMBA_USER=$NEW_MAMBA_USER

COPY _init.sh /usr/local/bin/_init.sh
RUN chmod +x /usr/local/bin/_init.sh

COPY prepare-aiida.sh /usr/local/bin/prepare-aiida.sh
RUN chmod +x /usr/local/bin/prepare-aiida.sh

COPY --chown=$MAMBA_USER:$MAMBA_USER env.yaml /tmp/env.yaml
RUN micromamba install -y -n base -f /tmp/env.yaml && \
micromamba clean --all --yes

USER $MAMBA_USER

# Configure AiiDA profile.
COPY config-quick-setup.yaml /opt/config-quick-setup.yaml

# Configure AiiDA.
ENV SETUP_DEFAULT_AIIDA_PROFILE true
ENV AIIDA_PROFILE_NAME default
ENV AIIDA_USER_EMAIL aiida@localhost
ENV AIIDA_USER_FIRST_NAME Giuseppe
ENV AIIDA_USER_LAST_NAME Verdi
ENV AIIDA_USER_INSTITUTION Khedivial

# Make sure that the known_hosts file is present inside the .ssh folder.
RUN mkdir -p --mode=0700 /home/${MAMBA_USER}/.ssh && \
touch /home/${MAMBA_USER}/.ssh/known_hosts

RUN /usr/local/bin/_entrypoint.sh ssh-keygen -f /home/${MAMBA_USER}/.ssh/id_rsa -t rsa -b 4096 -m PEM -N ''

WORKDIR /home/${MAMBA_USER}

ENTRYPOINT [ "/usr/local/bin/_init.sh" ]
9 changes: 9 additions & 0 deletions stack/slim/_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# Start the ssh-agent
/usr/local/bin/_entrypoint.sh ssh-agent

# setup aiida
/usr/local/bin/_entrypoint.sh /usr/local/bin/prepare-aiida.sh

exec "$@"
15 changes: 15 additions & 0 deletions stack/slim/config-quick-setup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
db_engine: postgresql_psycopg2
db_backend: psql_dos
db_host: database
db_port: 5432
su_db_username: postgres
su_db_password: password
su_db_name: template1
db_name: aiida_db
db_username: aiida
db_password: password
broker_host: messaging
broker_port: 5672
broker_username: guest
broker_password: guest
11 changes: 11 additions & 0 deletions stack/slim/env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
# Using an environment name other than "base" is not recommended!
# Read https://github.com/mamba-org/micromamba-docker#multiple-environments
# if you must use a different environment name.
name: base
channels:
- conda-forge
dependencies:
- python=3.9.13
- aiida-core=2.0.4
- openssh=9.1p1
77 changes: 77 additions & 0 deletions stack/slim/prepare-aiida.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

# This script is executed whenever the docker container is (re)started.

# Debugging.
set -x

# Environment.
export SHELL=/bin/bash

# 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

# 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 /opt/config-quick-setup.yaml

# Setup and configure local computer.
computer_name=localhost

# Determine the number of physical cores as a default for the number of
# available MPI ranks on the localhost. We do not count "logical" cores,
# since MPI parallelization over hyper-threaded cores is typically
# associated with a significant performance penalty. We use the
# `psutil.cpu_count(logical=False)` function as opposed to simply
# `os.cpu_count()` since the latter would include hyperthreaded (logical
# cores).
NUM_PHYSICAL_CORES=$(python -c 'import psutil; print(int(psutil.cpu_count(logical=False)))' 2>/dev/null)
LOCALHOST_MPI_PROCS_PER_MACHINE=${LOCALHOST_MPI_PROCS_PER_MACHINE:-${NUM_PHYSICAL_CORES}}

if [ -z $LOCALHOST_MPI_PROCS_PER_MACHINE ]; then
echo "Unable to automatically determine the number of logical CPUs on this "
echo "machine. Please set the LOCALHOST_MPI_PROCS_PER_MACHINE variable to "
echo "explicitly set the number of available MPI ranks."
exit 1
fi

verdi computer show ${computer_name} || verdi computer setup \
--non-interactive \
--label "${computer_name}" \
--description "this computer" \
--hostname "${computer_name}" \
--transport core.local \
--scheduler core.direct \
--work-dir /home/${MAMBA_USER}/aiida_run/ \
--mpirun-command "mpirun -np {tot_num_mpiprocs}" \
--mpiprocs-per-machine ${LOCALHOST_MPI_PROCS_PER_MACHINE} && \
verdi computer configure core.local "${computer_name}" \
--non-interactive \
--safe-interval 0.0
fi


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

# Make sure that the daemon is not running, otherwise the migration will abort.
verdi daemon stop

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

# Daemon will start only if the database exists and is migrated to the latest version.
verdi daemon start || echo "AiiDA daemon is not running."