Skip to content

Commit

Permalink
refactor(python): switch from mamba to conda (#214)
Browse files Browse the repository at this point in the history
* switch to conda

* remove pre-installed extension from vscode
  • Loading branch information
avouacr authored Jul 12, 2024
1 parent 813ff61 commit 32ea1d6
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 46 deletions.
8 changes: 4 additions & 4 deletions jupyter/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ RUN /opt/install-jupyterlab.sh && \
# Install JupyterLab extensions
pip3 install jupyterlab-git && \
# If using Conda and Julia is installed, make its kernel available in Jupyter
if command -v julia && [ -n "$MAMBA_DIR" ]; then \
if command -v julia && [ -n "$CONDA_DIR" ]; then \
julia -e 'using Pkg; pkg"add IJulia"; pkg"precompile"' && \
mv "${HOME}/.local/share/jupyter/kernels/julia"* "${MAMBA_DIR}/share/jupyter/kernels/"; \
mv "${HOME}/.local/share/jupyter/kernels/julia"* "${CONDA_DIR}/share/jupyter/kernels/"; \
fi && \
# If R is installed, make its kernel available in Jupyter
if command -v R; then \
Expand All @@ -20,11 +20,11 @@ RUN /opt/install-jupyterlab.sh && \
# Generate jupyter server config
jupyter server --generate-config && \
# Fix permissions
chown -R ${USERNAME}:${GROUPNAME} ${HOME} ${MAMBA_DIR} && \
chown -R ${USERNAME}:${GROUPNAME} ${HOME} ${CONDA_DIR} && \
# Clean
jupyter lab clean && \
rm -rf /var/lib/apt/lists/* && \
if command -v mamba; then \
if command -v conda; then \
conda clean --all -f -y; \
fi

Expand Down
2 changes: 1 addition & 1 deletion jupyter/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ commandTests:
- name: "Does the binary exists?"
command: "which"
args: ["jupyter-lab"]
expectedOutput: ["/usr/local/bin/jupyter-lab|/opt/mamba/bin/jupyter-lab"]
expectedOutput: ["/usr/local/bin/jupyter-lab|/opt/conda/bin/jupyter-lab"]
- name: "Does the binary exists?"
command: "which"
args: ["duckdb"]
Expand Down
4 changes: 2 additions & 2 deletions python-datascience/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ USER root
COPY conda-env.yml .

RUN ls -larth /opt/
RUN mamba env update -n base -f conda-env.yml && \
RUN conda env update -n base -f conda-env.yml && \
# Install Python packages not available on conda-forge
pip3 install opencv-python-headless && \
# Install Julia
/opt/install-julia.sh && \
# Install Quarto latest version
/opt/install-quarto.sh && \
# Fix permissions
chown -R ${USERNAME}:${GROUPNAME} ${HOME} ${MAMBA_DIR} ${JULIA_DIR} && \
chown -R ${USERNAME}:${GROUPNAME} ${HOME} ${CONDA_DIR} ${JULIA_DIR} && \
# Clean
rm conda-env.yml && \
conda clean --all -f -y && \
Expand Down
8 changes: 4 additions & 4 deletions python-datascience/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ commandTests:
expectedOutput: ["/usr/local/bin/argo"]
- name: "Does the binary exists?"
command: "which"
args: ["mamba"]
expectedOutput: ["/opt/mamba/bin/mamba"]
args: ["conda"]
expectedOutput: ["/opt/conda/bin/conda"]
- name: "Does the binary exists?"
command: "which"
args: ["python"]
expectedOutput: ["/opt/mamba/bin/python"]
expectedOutput: ["/opt/conda/bin/python"]
- name: "Does the binary exists?"
command: "which"
args: ["pip"]
expectedOutput: ["/opt/mamba/bin/pip"]
expectedOutput: ["/opt/conda/bin/pip"]
- name: "Does the binary exists?"
command: "which"
args: ["julia"]
Expand Down
24 changes: 11 additions & 13 deletions python-minimal/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,29 @@ LABEL maintainer="InseeFrLab <innovation@insee.fr>"
ARG PYTHON_VERSION="3.12.4"
ENV PYTHON_VERSION=${PYTHON_VERSION}

ENV MAMBA_DIR="/opt/mamba"
ENV PATH="${MAMBA_DIR}/bin:${PATH}"
ENV CONDA_DIR="/opt/conda"
ENV PATH="${CONDA_DIR}/bin:${PATH}"

USER root

COPY conda-env.yml .

RUN wget -q "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" -O miniforge.sh && \
# Install mambaforge latest version
/bin/bash miniforge.sh -b -p "${MAMBA_DIR}" && \
RUN /opt/install-conda.sh && \
# Set specified Python version in base Conda env
mamba install python=="${PYTHON_VERSION}" && \
conda install python=="${PYTHON_VERSION}" && \
# Pin Python version to prevent Conda from upgrading it
touch ${MAMBA_DIR}/conda-meta/pinned && \
echo "python==${PYTHON_VERSION}" >> ${MAMBA_DIR}/conda-meta/pinned && \
touch ${CONDA_DIR}/conda-meta/pinned && \
echo "python==${PYTHON_VERSION}" >> ${CONDA_DIR}/conda-meta/pinned && \
# Install essential Python packages
mamba env update -n base -f conda-env.yml && \
conda env update -n base -f conda-env.yml && \
# Install duckdb extensions
mamba run -n base python /opt/install-duckdb-extensions.py && \
conda run -n base python /opt/install-duckdb-extensions.py && \
# Activate custom Conda env by default in shell
echo ". ${MAMBA_DIR}/etc/profile.d/conda.sh && conda activate" >> ${HOME}/.bashrc && \
echo ". ${CONDA_DIR}/etc/profile.d/conda.sh && conda activate" >> ${HOME}/.bashrc && \
# Fix permissions
chown -R ${USERNAME}:${GROUPNAME} ${HOME} ${MAMBA_DIR} && \
chown -R ${USERNAME}:${GROUPNAME} ${HOME} ${CONDA_DIR} && \
# Clean
rm miniforge.sh conda-env.yml && \
rm conda-env.yml && \
conda clean --all -f -y && \
rm -rf /var/lib/apt/lists/*

Expand Down
8 changes: 4 additions & 4 deletions python-minimal/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ commandTests:
expectedOutput: ["/usr/local/bin/argo"]
- name: "Does the binary exists?"
command: "which"
args: ["mamba"]
expectedOutput: ["/opt/mamba/bin/mamba"]
args: ["conda"]
expectedOutput: ["/opt/conda/bin/conda"]
- name: "Does the binary exists?"
command: "which"
args: ["python"]
expectedOutput: ["/opt/mamba/bin/python"]
expectedOutput: ["/opt/conda/bin/python"]
- name: "Does the binary exists?"
command: "which"
args: ["pip"]
expectedOutput: ["/opt/mamba/bin/pip"]
expectedOutput: ["/opt/conda/bin/pip"]
- name: "Does the binary exists?"
command: "which"
args: ["duckdb"]
Expand Down
2 changes: 1 addition & 1 deletion python-pytorch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN if ! [[ -z "${CUDA_VERSION}" ]]; then \
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu; \
fi && \
# Fix permissions
chown -R ${USERNAME}:${GROUPNAME} ${HOME} ${MAMBA_DIR} && \
chown -R ${USERNAME}:${GROUPNAME} ${HOME} ${CONDA_DIR} && \
# Clean
conda clean --all -f -y && \
rm -rf /var/lib/apt/lists/*
Expand Down
8 changes: 4 additions & 4 deletions python-pytorch/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ commandTests:
expectedOutput: ["/usr/local/bin/argo"]
- name: "Does the binary exists?"
command: "which"
args: ["mamba"]
expectedOutput: ["/opt/mamba/bin/mamba"]
args: ["conda"]
expectedOutput: ["/opt/conda/bin/conda"]
- name: "Does the binary exists?"
command: "which"
args: ["python"]
expectedOutput: ["/opt/mamba/bin/python"]
expectedOutput: ["/opt/conda/bin/python"]
- name: "Does the binary exists?"
command: "which"
args: ["pip"]
expectedOutput: ["/opt/mamba/bin/pip"]
expectedOutput: ["/opt/conda/bin/pip"]
- name: "Does the binary exists?"
command: "which"
args: ["duckdb"]
Expand Down
2 changes: 1 addition & 1 deletion python-tensorflow/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ USER root

RUN pip3 install tensorflow && \
# Fix permissions
chown -R ${USERNAME}:${GROUPNAME} ${HOME} ${MAMBA_DIR} && \
chown -R ${USERNAME}:${GROUPNAME} ${HOME} ${CONDA_DIR} && \
# Clean
conda clean --all -f -y && \
rm -rf /var/lib/apt/lists/*
Expand Down
8 changes: 4 additions & 4 deletions python-tensorflow/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ commandTests:
expectedOutput: ["/usr/local/bin/argo"]
- name: "Does the binary exists?"
command: "which"
args: ["mamba"]
expectedOutput: ["/opt/mamba/bin/mamba"]
args: ["conda"]
expectedOutput: ["/opt/conda/bin/conda"]
- name: "Does the binary exists?"
command: "which"
args: ["python"]
expectedOutput: ["/opt/mamba/bin/python"]
expectedOutput: ["/opt/conda/bin/python"]
- name: "Does the binary exists?"
command: "which"
args: ["pip"]
expectedOutput: ["/opt/mamba/bin/pip"]
expectedOutput: ["/opt/conda/bin/pip"]
- name: "Does the binary exists?"
command: "which"
args: ["duckdb"]
Expand Down
8 changes: 8 additions & 0 deletions scripts/install-conda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e

# Install Conda via Miniforge
wget -q "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" -O miniforge.sh
chmod +x miniforge.sh
./miniforge.sh -b -p "${CONDA_DIR}"
rm miniforge.sh
4 changes: 2 additions & 2 deletions scripts/install-julia.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ tar xzf julia.tar.gz -C "${JULIA_DIR}" --strip-components=1
rm julia.tar.gz

# Show Julia where conda libraries are
if command -v mamba ; then \
if command -v conda ; then \
mkdir /etc/julia && \
echo "push!(Libdl.DL_LOAD_PATH, \"${MAMBA_DIR}/lib\")" >> /etc/julia/juliarc.jl; \
echo "push!(Libdl.DL_LOAD_PATH, \"${CONDA_DIR}/lib\")" >> /etc/julia/juliarc.jl; \
fi

# Update and install basic Julia packages
Expand Down
4 changes: 2 additions & 2 deletions scripts/install-jupyterlab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ function apt_install() {
fi
}

if command -v mamba ; then
mamba install -y jupyterlab
if command -v conda ; then
conda install -y jupyterlab
else
if [ "`which pip3`" = "" ]; then
apt_install python3-pip
Expand Down
4 changes: 2 additions & 2 deletions scripts/onyxia-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ fi

if [[ "$DARK_MODE" == "true" ]]; then
if command -v jupyter-lab; then
mkdir ${MAMBA_DIR}/share/jupyter/lab/settings
echo "{\"@jupyterlab/apputils-extension:themes\": {\"theme\": \"JupyterLab Dark\"}}" > ${MAMBA_DIR}/share/jupyter/lab/settings/overrides.json;
mkdir ${CONDA_DIR}/share/jupyter/lab/settings
echo "{\"@jupyterlab/apputils-extension:themes\": {\"theme\": \"JupyterLab Dark\"}}" > ${CONDA_DIR}/share/jupyter/lab/settings/overrides.json;
fi
if command -v code-server; then
jq '. + {"workbench.colorTheme": "Default Dark Modern"}' ${HOME}/.local/share/code-server/User/settings.json > ${HOME}/tmp.settings.json && mv ${HOME}/tmp.settings.json ${HOME}/.local/share/code-server/User/settings.json
Expand Down
2 changes: 1 addition & 1 deletion scripts/onyxia-set-repositories.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if [ "`which conda`" != "" ]; then
echo "configuration conda (add channels)"
conda config --add channels $CONDA_REPOSITORY
conda config --remove channels conda-forge
conda config --remove channels conda-forge --file /opt/mamba/.condarc
conda config --remove channels conda-forge --file /opt/conda/.condarc
fi

if [[ -n "$PATH_TO_CA_BUNDLE" ]]; then
Expand Down
1 change: 0 additions & 1 deletion vscode/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ RUN code-server --install-extension ms-toolsai.jupyter && \
code-server --install-extension ms-kubernetes-tools.vscode-kubernetes-tools && \
code-server --install-extension ms-azuretools.vscode-docker && \
code-server --install-extension njpwerner.autodocstring && \
code-server --install-extension redhat.vscode-yaml && \
code-server --install-extension mhutchie.git-graph && \
code-server --install-extension rangav.vscode-thunder-client && \
code-server --install-extension hediet.vscode-drawio && \
Expand Down

0 comments on commit 32ea1d6

Please sign in to comment.