Skip to content
Snippets Groups Projects
Commit b6830a24 authored by Gilquin's avatar Gilquin
Browse files

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
parent e0f6606d
No related branches found
No related tags found
No related merge requests found
<<<<<<< HEAD
FROM mambaorg/micromamba:1.5.8 AS micromamba FROM mambaorg/micromamba:1.5.8 AS micromamba
FROM rocker/tidyverse:latest FROM rocker/tidyverse:latest
...@@ -7,6 +8,24 @@ ARG MAMBA_USER=${DEFAULT_USER} ...@@ -7,6 +8,24 @@ ARG MAMBA_USER=${DEFAULT_USER}
ARG MAMBA_USER_ID=1000 ARG MAMBA_USER_ID=1000
ARG MAMBA_USER_GID=1000 ARG MAMBA_USER_GID=1000
ENV MAMBA_USER=${MAMBA_USER} 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_ROOT_PREFIX="/opt/conda"
ENV MAMBA_EXE="/bin/micromamba" ENV MAMBA_EXE="/bin/micromamba"
...@@ -16,6 +35,7 @@ COPY --from=micromamba /usr/local/bin/_activate_current_env.sh \ ...@@ -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_setup_root_prefix.sh \
/usr/local/bin/_dockerfile_shell.sh \ /usr/local/bin/_dockerfile_shell.sh \
/usr/local/bin/ /usr/local/bin/
<<<<<<< HEAD
# setup mamba user # setup mamba user
RUN /usr/local/bin/_dockerfile_initialize_user_accounts.sh && \ RUN /usr/local/bin/_dockerfile_initialize_user_accounts.sh && \
...@@ -33,3 +53,26 @@ RUN /bin/micromamba create -f /opt/environment.yml && \ ...@@ -33,3 +53,26 @@ RUN /bin/micromamba create -f /opt/environment.yml && \
# python setup # python setup
RUN /opt/docker/bin/py_setup.sh 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)
#!/usr/bin/bash #!/usr/bin/bash
PROJECT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd | xargs dirname ) PROJECT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd | xargs dirname )
cd "$PROJECT_DIR" || exit 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"
...@@ -4,6 +4,6 @@ docker run \ ...@@ -4,6 +4,6 @@ docker run \
--rm \ --rm \
-v "${PROJECT_DIR}":"${PROJECT_DIR}" \ -v "${PROJECT_DIR}":"${PROJECT_DIR}" \
-w "${PROJECT_DIR}" \ -w "${PROJECT_DIR}" \
--name can-py-basis-quarto \ --name igfl-python-quarto \
${USER}/can-py-basis:latest \ ${USER}/igfl-python:latest \
bash -c "quarto render ." bash -c "quarto render ."
#!/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
#!/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/*
#!/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/'
name: py_basis name: igfl_python
channels: channels:
- bokeh
- conda-forge - conda-forge
dependencies: dependencies:
- python=3.11.9 - python=3.11.9
...@@ -8,6 +7,7 @@ dependencies: ...@@ -8,6 +7,7 @@ dependencies:
- pandas=2.2.2 - pandas=2.2.2
- matplotlib=3.9.1 - matplotlib=3.9.1
- seaborn=0.13.2 - seaborn=0.13.2
- plotly=5.23.0 - jupyter
- bokeh=3.5.1 - nbformat
- nbclient
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment