Skip to content

Commit 0465605

Browse files
authored
Merge pull request #45 from linea-it/mamba
Updated pipelines (Mamba env)
2 parents 36b4afb + 4595756 commit 0465605

11 files changed

Lines changed: 58 additions & 114 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,13 @@ cp orchestration/backend/sh/slurm_env.sh slurm-worker/env.sh
291291
vi slurm-worker/env.sh # edit file
292292
```
293293

294-
With Conda loaded, run:
294+
With `micromamba` available in `PATH`, run:
295295
```bash
296296
source slurm-worker/env.sh
297297
```
298298

299+
The script defaults to `MAMBA_ROOT_PREFIX=${APP_DIR}/micromamba` and will create the `orchestration` environment there if it does not exist.
300+
299301
And start the application:
300302
```bash
301303
slurm_worker_manager start

backend/Dockerfile

Lines changed: 23 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,51 @@
1-
# FROM debian:buster-slim as base
21
FROM python:3.11-slim as base
32

4-
# # If this is set to a non-empty string, Python won’t try
5-
# # to write .pyc files on the import of source modules
63
ENV PYTHONDONTWRITEBYTECODE=1
7-
8-
# # Force the stdout and stderr streams to be unbuffered.
9-
# # This option has no effect on the stdin stream.
104
ENV PYTHONUNBUFFERED=1
5+
ENV MAMBA_ROOT_PREFIX=/opt/micromamba
116

12-
# Create Group: conda
13-
RUN groupadd -r conda --gid 900
7+
RUN groupadd -r mamba --gid 900
148

15-
# Instalacao Miniconda
169
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
1710
&& apt-get -y install --no-install-recommends \
18-
procps \
19-
gcc \
20-
ca-certificates \
21-
wget \
22-
python3-dev \
23-
build-essential \
24-
&& apt-get clean \
11+
procps gcc ca-certificates wget bzip2 python3-dev build-essential && \
12+
apt-get clean \
2513
&& rm -rf /var/lib/apt/lists/* \
26-
&& mkdir -p /opt/conda \
27-
&& wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /opt/conda/miniconda.sh \
28-
&& bash /opt/conda/miniconda.sh -b -u -p /opt/conda \
29-
&& rm -rf /opt/conda/miniconda.sh \
30-
&& /opt/conda/bin/conda init bash \
31-
&& find /opt/conda/ -follow -type f -name '*.a' -delete \
32-
&& find /opt/conda/ -follow -type f -name '*.js.map' -delete \
33-
&& /opt/conda/bin/conda clean -afy \
34-
&& chmod =2775 /opt/conda \
35-
&& ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh
36-
37-
ENV PATH /opt/conda/bin:$PATH
38-
39-
#-------------- Python 3.11 Environment Stage --------------
40-
FROM base as env_base
41-
COPY ./environment.yml .
42-
43-
# Set environment variable to automatically accept conda TOS
44-
ENV CONDA_ALWAYS_YES=true
45-
ENV CONDA_AUTO_ACTIVATE_BASE=false
14+
&& mkdir -p /opt/micromamba \
15+
&& wget -qO- https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj -C /usr/local/bin --strip-components=1 bin/micromamba && find /opt/micromamba/ -follow -type f -name '*.a' -delete \
16+
&& find /opt/micromamba/ -follow -type f -name '*.js.map' -delete \
17+
&& chmod =2775 /opt/micromamba
4618

47-
# Accept conda terms of service using exact commands from error message
48-
RUN /opt/conda/bin/conda config --set always_yes true && \
49-
/opt/conda/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main && \
50-
/opt/conda/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r && \
51-
/opt/conda/bin/conda config --set channel_priority flexible && \
52-
/opt/conda/bin/conda update -n base -c defaults conda && \
53-
/opt/conda/bin/conda env create -f environment.yml
19+
ENV PATH /usr/local/bin:/opt/micromamba/bin:$PATH
5420

55-
# RUN conda install -c conda-forge uwsgi
21+
FROM base as env_base
22+
COPY ./environment.yml .
5623

57-
# Install python packages
24+
RUN micromamba create --root-prefix "$MAMBA_ROOT_PREFIX" -y -f environment.yml \
25+
&& micromamba clean --all --yes
5826
COPY ./requirements.txt /tmp/pip-tmp/
59-
RUN /bin/bash --login -c "source /opt/conda/bin/activate \
60-
&& conda activate orchestration \
61-
&& pip install --upgrade pip wheel setuptools \
62-
&& pip --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
63-
&& rm -rf /tmp/pip-tmp"
27+
RUN micromamba run --root-prefix "$MAMBA_ROOT_PREFIX" -n orchestration pip install --upgrade pip wheel setuptools \
28+
&& micromamba run --root-prefix "$MAMBA_ROOT_PREFIX" -n orchestration pip --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
29+
&& rm -rf /tmp/pip-tmp \
30+
&& micromamba clean --all --yes
6431

6532
FROM base
6633

67-
# Python 3.11 environment
68-
COPY --chown=:conda --chmod=775 --from=env_base /opt/conda/envs/orchestration /opt/conda/envs/orchestration
34+
COPY --chown=:mamba --chmod=775 --from=env_base /opt/micromamba/envs/orchestration /opt/micromamba/envs/orchestration
6935

70-
# add user so we can run things as non-root
71-
# https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user
7236
ARG USERNAME=orch
7337
ARG USERID=1000
7438
ARG GROUPID=1000
7539
ARG BASEDIR=/app
7640

7741
ENV BASE_DIR ${BASEDIR}
7842
ENV LOG_DIR ${LOG_DIR}
43+
ENV ORCHESTRATION_ENV_PREFIX /opt/micromamba/envs/orchestration
44+
ENV MAMBA_ROOT_PREFIX ${BASEDIR}/.micromamba
45+
ENV PATH /opt/micromamba/envs/orchestration/bin:/usr/local/bin:/opt/micromamba/bin:$PATH
7946

80-
RUN mkdir -p ${BASE_DIR}
47+
RUN mkdir -p ${BASE_DIR} ${BASE_DIR}/.micromamba
8148

82-
# Copy app files into container
8349
WORKDIR $BASE_DIR
8450
COPY . $BASE_DIR
8551

@@ -89,20 +55,14 @@ RUN mkdir -p ${BASE_DIR}/django_static \
8955
${BASE_DIR}/core/migrations \
9056
&& chmod -R g+w ${BASE_DIR}
9157

92-
# Create group
9358
RUN groupadd --gid ${GROUPID} $USERNAME
94-
95-
# Create user
9659
RUN useradd --uid ${USERID} --gid ${GROUPID} --shell /bin/bash --create-home ${USERNAME}
9760
RUN usermod -a -G ${GROUPID},900 ${USERNAME}
9861
RUN chown -R ${USERID}:${GROUPID} ${BASE_DIR}
9962

10063
COPY --chmod=0775 ./sh/entrypoint.sh /entrypoint.sh
10164

102-
# Switch to non-priviliged user and run app
10365
USER $USERNAME
104-
RUN /bin/bash --login -c "conda init bash \
105-
&& echo 'source ${BASE_DIR}/sh/env.sh' >> ~/.bashrc \
106-
&& source ~/.bashrc"
66+
RUN /bin/bash -lc "echo 'source ${BASE_DIR}/sh/env.sh' >> ~/.bashrc"
10767

10868
ENTRYPOINT [ "/entrypoint.sh" ]

backend/environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: orchestration
22
channels:
3-
- defaults
43
- conda-forge
54
dependencies:
65
- python=3.10.8

backend/sh/env.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/bin/bash --login
22

3-
echo "Activating environment"
4-
conda activate orchestration
3+
export MICROMAMBA_BIN="${MICROMAMBA_BIN:-micromamba}"
4+
export ORCHESTRATION_ENV_PREFIX="${ORCHESTRATION_ENV_PREFIX:-/opt/micromamba/envs/orchestration}"
5+
export MAMBA_ROOT_PREFIX="${MAMBA_ROOT_PREFIX:-${BASE_DIR}/.micromamba}"
6+
export ORCHESTRATION_ENV_NAME="${ORCHESTRATION_ENV_NAME:-orchestration}"
7+
export PATH="${ORCHESTRATION_ENV_PREFIX}/bin:${PATH}"

backend/sh/slurm_env.sh

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,37 @@
22

33
export APP_DIR= # e.g.: /data/apps/app.orch/dev
44
export BASE_DIR= # e.g.: ${APP_DIR}/orchestration
5-
export CONDA_PATH= # e.g.: ${APP_DIR}/miniconda3/bin/activate
5+
export MAMBA_ROOT_PREFIX= # e.g.: ${APP_DIR}/micromamba
6+
export MICROMAMBA_BIN= # e.g.: /usr/local/bin/micromamba
67
export RABBITMQ_ENV= # e.g.: /home/app.orch/rabbitmq/.env
78
export WORKER_NAME="slurm"
9+
export ORCHESTRATION_ENV_NAME="orchestration"
810

911
set -a
10-
. $RABBITMQ_ENV # environment variables related to rabbitmq running on srvorch-dev server
11-
. $BASE_DIR/.env
12+
. "$RABBITMQ_ENV"
13+
. "$BASE_DIR/.env"
1214
set +a
1315

14-
echo "Activating environment"
16+
MICROMAMBA_BIN="${MICROMAMBA_BIN:-micromamba}"
17+
MAMBA_ROOT_PREFIX="${MAMBA_ROOT_PREFIX:-${APP_DIR}/micromamba}"
18+
ENV_PREFIX="${MAMBA_ROOT_PREFIX}/envs/${ORCHESTRATION_ENV_NAME}"
1519

16-
# shellcheck source=/data/apps/app.orch/dev/miniconda3/bin/activate
17-
source $CONDA_PATH || { echo "Failed to activate Conda environment"; exit 1; }
20+
if ! command -v "$MICROMAMBA_BIN" >/dev/null 2>&1; then
21+
echo "Failed to find micromamba in PATH. Set MICROMAMBA_BIN or update PATH."
22+
exit 1
23+
fi
1824

1925
if [ ! -d "$PIPELINES_DIR" ]; then
2026
echo "Error: PIPELINES_DIR not defined."
2127
exit 1
2228
fi
2329

24-
HASENV=$(conda env list | grep 'orchestration ')
25-
26-
if [ -z "$HASENV" ]; then
30+
if [ ! -d "$ENV_PREFIX" ]; then
2731
echo "Create virtual environment..."
28-
conda env create -f $BASE_DIR/backend/environment.yml
32+
"$MICROMAMBA_BIN" create --root-prefix "$MAMBA_ROOT_PREFIX" -y -f "$BASE_DIR/backend/environment.yml"
2933
echo "Virtual environment created and packages installed."
3034
fi
3135

32-
conda activate orchestration
33-
34-
export PATH=$PATH:$BASE_DIR/backend/sh/
36+
export PATH="$ENV_PREFIX/bin:$BASE_DIR/backend/sh/:$PATH"
3537

3638
umask g+w

deploy/env.sh.template

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
export APP_DIR=/scripts/app.orch/[dev|production]
44
export BASE_DIR=${APP_DIR}/orchestration
55

6-
## Conda settings
76
export XDG_CACHE_HOME=${APP_DIR}/.cache
8-
export CONDA_PKGS_DIRS=${APP_DIR}/.conda/pkgs
9-
export CONDA_PATH=${APP_DIR}/miniconda3/bin/activate
10-
source $CONDA_PATH
7+
export MAMBA_ROOT_PREFIX=${APP_DIR}/micromamba
8+
export MICROMAMBA_BIN=${MICROMAMBA_BIN:-micromamba}
9+
export ORCHESTRATION_ENV_NAME=${ORCHESTRATION_ENV_NAME:-slurm-worker}
1110

12-
conda activate slurm-worker
11+
eval "$(${MICROMAMBA_BIN} shell hook --shell bash)"
12+
micromamba activate "${ORCHESTRATION_ENV_NAME}"
1313

1414
export WORKER_NAME="slurm"
1515
export SLURM_EXECUTOR="slurm"
@@ -22,11 +22,8 @@ export PATH=$PATH:$BASE_DIR/backend/sh/
2222

2323
umask g+w
2424

25-
## TNO settings
26-
## Database Connections URI
2725
export DB_ADMIN_URI=
2826
export DB_CATALOG_URI=
2927
export EXECUTION_ENV="linea"
3028
export PLANETARY_EPHEMERIS_FILEPATH=
3129
export LEAP_SECONDS_FILEPATH=
32-

deploy/environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: slurm-worker
22
channels:
3-
- defaults
43
- conda-forge
54
dependencies:
65
- python=3.12

deploy/install_pipelines.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ fi
66

77
echo "The directory containing the pipelines is: " "$PIPELINES_DIR"
88

9-
source $(dirname $CONDA_EXE)/activate || { echo "Failed to activate Conda environment"; exit 1; }
9+
MICROMAMBA_BIN="${MICROMAMBA_BIN:-micromamba}"
10+
if ! command -v "$MICROMAMBA_BIN" >/dev/null 2>&1; then
11+
echo "Failed to find micromamba in PATH"
12+
exit 1
13+
fi
1014

1115
for pipe in $( ls ${PIPELINES_DIR}/*/install.sh)
1216
do

0 commit comments

Comments
 (0)