1- # FROM debian:buster-slim as base
21FROM 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
63ENV PYTHONDONTWRITEBYTECODE=1
7-
8- # # Force the stdout and stderr streams to be unbuffered.
9- # # This option has no effect on the stdin stream.
104ENV 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
169RUN 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
5826COPY ./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
6532FROM 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
7236ARG USERNAME=orch
7337ARG USERID=1000
7438ARG GROUPID=1000
7539ARG BASEDIR=/app
7640
7741ENV BASE_DIR ${BASEDIR}
7842ENV 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
8349WORKDIR $BASE_DIR
8450COPY . $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
9358RUN groupadd --gid ${GROUPID} $USERNAME
94-
95- # Create user
9659RUN useradd --uid ${USERID} --gid ${GROUPID} --shell /bin/bash --create-home ${USERNAME}
9760RUN usermod -a -G ${GROUPID},900 ${USERNAME}
9861RUN chown -R ${USERID}:${GROUPID} ${BASE_DIR}
9962
10063COPY --chmod=0775 ./sh/entrypoint.sh /entrypoint.sh
10164
102- # Switch to non-priviliged user and run app
10365USER $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
10868ENTRYPOINT [ "/entrypoint.sh" ]
0 commit comments