From b6830a249c5127eeecd20c49bdea4ac53da3bcdf Mon Sep 17 00:00:00 2001
From: Gilquin <laurent.gilquin@ens-lyon.fr>
Date: Fri, 7 Feb 2025 13:42:36 +0100
Subject: [PATCH] init: populate docker file

The docker folder contains the following script:
  * build.sh: to build the docker image (from the Dockerfile at the root of the project)
  * quarto_render.sh: to build the Quarto static website locally
  * scripts/install_requirements.sh: to install ubuntu packages and libraries
  * scripts/micromamba_clean_env.sh: to clean useless files/folders resulting from the micromamba environment creation

The file environment.yml is the init file used to create the micromamba environment.

Note: the build log file should not be versioned
---
 Dockerfile                             | 43 ++++++++++++
 docker/build.sh                        |  2 +-
 docker/quarto_render.sh                |  4 +-
 docker/rstudio_run.sh                  | 12 ----
 docker/scripts/install_requirements.sh | 90 ++++++++++++++++++++++++++
 docker/scripts/py_setup.sh             | 30 ---------
 environment.yml                        |  8 +--
 7 files changed, 140 insertions(+), 49 deletions(-)
 delete mode 100755 docker/rstudio_run.sh
 create mode 100755 docker/scripts/install_requirements.sh
 delete mode 100755 docker/scripts/py_setup.sh

diff --git a/Dockerfile b/Dockerfile
index 1a92907..8513aab 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,3 +1,4 @@
+<<<<<<< HEAD
 FROM mambaorg/micromamba:1.5.8 AS micromamba
 
 FROM rocker/tidyverse:latest
@@ -7,6 +8,24 @@ ARG MAMBA_USER=${DEFAULT_USER}
 ARG MAMBA_USER_ID=1000
 ARG MAMBA_USER_GID=1000
 ENV MAMBA_USER=${MAMBA_USER}
+=======
+FROM mambaorg/micromamba:2.0.5 AS micromamba
+
+FROM rocker/verse:latest AS rocker
+
+FROM docker.io/library/ubuntu:latest
+
+COPY docker/scripts/install_requirements.sh /opt/docker/bin/
+RUN /opt/docker/bin/install_requirements.sh
+
+# copy files from micromamba image
+ARG MAMBA_USER="mambauser"
+ARG MAMBA_USER_ID="57439"
+ARG MAMBA_USER_GID="57439"
+ENV MAMBA_USER=${MAMBA_USER}
+ENV MAMBA_USER_ID=${MAMBA_USER_ID}
+ENV MAMBA_USER_GID=${MAMBA_USER_GID}
+>>>>>>> ef3d886 (init: populate docker file)
 ENV MAMBA_ROOT_PREFIX="/opt/conda"
 ENV MAMBA_EXE="/bin/micromamba"
 
@@ -16,6 +35,7 @@ COPY --from=micromamba /usr/local/bin/_activate_current_env.sh \
     /usr/local/bin/_dockerfile_setup_root_prefix.sh \
     /usr/local/bin/_dockerfile_shell.sh \
     /usr/local/bin/
+<<<<<<< HEAD
 
 # setup mamba user
 RUN /usr/local/bin/_dockerfile_initialize_user_accounts.sh && \
@@ -33,3 +53,26 @@ RUN /bin/micromamba create -f /opt/environment.yml && \
 
 # python setup
 RUN /opt/docker/bin/py_setup.sh
+=======
+# setup mamba user
+RUN /usr/local/bin/_dockerfile_initialize_user_accounts.sh && \
+    /usr/local/bin/_dockerfile_setup_root_prefix.sh
+# install micromamba env
+SHELL ["/usr/local/bin/_dockerfile_shell.sh"]
+COPY environment.yml /opt/environment.yml
+COPY docker/scripts/micromamba_clean_env.sh /opt/docker/bin/
+ENV MAMBA_ENV_DIR="/opt/conda/envs/igfl_python"
+RUN /bin/micromamba create -f /opt/environment.yml && \
+    /bin/micromamba clean -a -y && \
+    chown -R "${MAMBA_USER}":"${MAMBA_USER}" "${MAMBA_ENV_DIR}" && \
+    /opt/docker/bin/micromamba_clean_env.sh
+
+
+# install pandoc (required for quarto)
+COPY --from=rocker /rocker_scripts/install_pandoc.sh \
+    /rocker_scripts/install_quarto.sh \
+    /opt/docker/bin/
+RUN /opt/docker/bin/install_pandoc.sh
+# install latest version of quarto
+RUN /opt/docker/bin/install_quarto.sh 1.6.40
+>>>>>>> ef3d886 (init: populate docker file)
diff --git a/docker/build.sh b/docker/build.sh
index 080185a..35f81c1 100755
--- a/docker/build.sh
+++ b/docker/build.sh
@@ -1,4 +1,4 @@
 #!/usr/bin/bash
 PROJECT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd | xargs dirname )
 cd "$PROJECT_DIR" || exit
-docker build -t "${USER}/can-py-basis:latest" -f "Dockerfile" . 2>&1 | tee "docker/build.log"
+docker build -t "${USER}/igfl-python:latest" -f "Dockerfile" . 2>&1 | tee "docker/build.log"
diff --git a/docker/quarto_render.sh b/docker/quarto_render.sh
index 9a5153b..c1b50de 100755
--- a/docker/quarto_render.sh
+++ b/docker/quarto_render.sh
@@ -4,6 +4,6 @@ docker run \
     --rm \
     -v "${PROJECT_DIR}":"${PROJECT_DIR}" \
     -w "${PROJECT_DIR}" \
-    --name can-py-basis-quarto \
-    ${USER}/can-py-basis:latest \
+    --name igfl-python-quarto \
+    ${USER}/igfl-python:latest \
     bash -c "quarto render ."
diff --git a/docker/rstudio_run.sh b/docker/rstudio_run.sh
deleted file mode 100755
index 732528f..0000000
--- a/docker/rstudio_run.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/usr/bin/bash
-PROJECT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd  | xargs dirname )
-docker run \
-    --rm \
-    -it \
-    -v "${PROJECT_DIR}":"${PROJECT_DIR}" \
-    -w "${PROJECT_DIR}" \
-    -e USERID="$(id -u)" \
-    -e GROUPID="$(id -g)" \
-    -p 8787:8787 \
-    --name can-py-basis-rstudio \
-    ${USER}/can-py-basis:latest
diff --git a/docker/scripts/install_requirements.sh b/docker/scripts/install_requirements.sh
new file mode 100755
index 0000000..29afd61
--- /dev/null
+++ b/docker/scripts/install_requirements.sh
@@ -0,0 +1,90 @@
+#!/usr/bin/bash -eu
+
+# a function to install apt packages only if they are not installed
+function apt_install() {
+    if ! dpkg -s "$@" >/dev/null 2>&1; then
+        if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
+            apt-get update
+        fi
+        apt-get install -y --no-install-recommends "$@"
+    fi
+}
+
+
+source /etc/os-release
+apt-get update
+apt-get -y install locales
+
+READLINE_VERSION=8
+if [ "${UBUNTU_CODENAME}" == "bionic" ]; then
+    READLINE_VERSION=7
+fi
+
+# install system libraries
+apt_install \
+    bash-completion \
+    ca-certificates \
+    file \
+    fonts-texgyre \
+    g++ \
+    gfortran \
+    gsfonts \
+    libblas-dev \
+    libbz2-* \
+    libcurl4 \
+    "libicu[0-9][0-9]" \
+    liblapack-dev \
+    libpcre2* \
+    libjpeg-turbo* \
+    libpangocairo-* \
+    libpng16* \
+    "libreadline${READLINE_VERSION}" \
+    libtiff* \
+    liblzma* \
+    libxt6 \
+    make \
+    tzdata \
+    unzip \
+    zip \
+    zlib1g
+
+BUILDDEPS="curl \
+    default-jdk \
+    devscripts \
+    libbz2-dev \
+    libcairo2-dev \
+    libcurl4-openssl-dev \
+    libpango1.0-dev \
+    libjpeg-dev \
+    libicu-dev \
+    libpcre2-dev \
+    libpng-dev \
+    libreadline-dev \
+    libtiff5-dev \
+    liblzma-dev \
+    libx11-dev \
+    libxt-dev \
+    perl \
+    rsync \
+    subversion \
+    tcl-dev \
+    tk-dev \
+    texinfo \
+    texlive-extra-utils \
+    texlive-fonts-recommended \
+    texlive-fonts-extra \
+    texlive-latex-recommended \
+    texlive-latex-extra \
+    x11proto-core-dev \
+    xauth \
+    xfonts-base \
+    xvfb \
+    wget \
+    zlib1g-dev"
+
+# shellcheck disable=SC2086
+apt_install ${BUILDDEPS}
+
+apt-get autoremove -y
+apt-get autoclean -y
+rm -rf /var/lib/apt/lists/*
diff --git a/docker/scripts/py_setup.sh b/docker/scripts/py_setup.sh
deleted file mode 100755
index 55269f5..0000000
--- a/docker/scripts/py_setup.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/usr/bin/bash -eu
-
-# install reticulate
-apt-get update -qq && \
-    install2.r --error --skipinstalled --ncpus -1 reticulate && \
-    rm -rf /tmp/downloaded_packages && \
-    strip /usr/local/lib/R/site-library/*/libs/*.so
-
-# setup python path at RStudio launch time
-cat <<EOF >"/home/${DEFAULT_USER}/.config/rstudio/rstudio-prefs.json"
-{
-    "save_workspace": "never",
-    "always_save_history": false,
-    "reuse_sessions_for_project_links": true,
-    "posix_terminal_shell": "bash",
-    "python_project_environment_automatic_activate": true,
-    "python_path": "${MAMBA_ENV_DIR}/bin/python"
-}
-EOF
-
-# setup reticulate environment variables
-cat <<EOF >"/home/${DEFAULT_USER}/.Rprofile"
-Sys.setenv("RETICULATE_PYTHON_ENV"="${MAMBA_ENV_DIR}")
-Sys.setenv("RETICULATE_CONDA"="${MAMBA_EXE}")
-EOF
-chown "${DEFAULT_USER}":"${DEFAULT_USER}" "/home/${DEFAULT_USER}/.Rprofile"
-
-# change matplotlib default figure dpi
-"${MAMBA_ENV_DIR}/bin/python" -c "import matplotlib; print(matplotlib.matplotlib_fname())" | \
-    xargs sed -i 's/^#figure.dpi:.*/figure.dpi:          300/'
diff --git a/environment.yml b/environment.yml
index ade8e42..bf4488f 100644
--- a/environment.yml
+++ b/environment.yml
@@ -1,6 +1,5 @@
-name: py_basis
+name: igfl_python
 channels:
-  - bokeh
   - conda-forge
 dependencies:
   - python=3.11.9
@@ -8,6 +7,7 @@ dependencies:
   - pandas=2.2.2
   - matplotlib=3.9.1
   - seaborn=0.13.2
-  - plotly=5.23.0
-  - bokeh=3.5.1
+  - jupyter
+  - nbformat
+  - nbclient
 
-- 
GitLab