diff --git a/conda/apptainer.def b/conda/apptainer.def new file mode 100644 index 00000000..41235c77 --- /dev/null +++ b/conda/apptainer.def @@ -0,0 +1,16 @@ +Bootstrap: docker +From: ubuntu:22.04 + +%environment + export HOME=/casa/home + +%post + mkdir /casa + apt update + +%runscript + echo "Start casa container" + export PATH=/casa/conda/bin:$PATH + export LD_LIBRARY_PATH=/casa/conda/lib:$LD_LIBRARY_PATH + + exec "$@" diff --git a/conda/setup_conda b/conda/setup_conda index cf090bf7..878f4f72 100755 --- a/conda/setup_conda +++ b/conda/setup_conda @@ -4,6 +4,7 @@ set -e set -x casaconda="$1" +script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) if [ -z "$casaconda" ]; then echo "Missing destination directory" @@ -14,141 +15,43 @@ if [ ! -e "$casaconda" ]; then mkdir "$casaconda" fi +if [ ! -e "$casaconda/home" ]; then + mkdir "$casaconda/home" + for f in .gitconfig .git-credentials; do + if [ -e "$HOME/$f" ]; then + cp "$HOME/$f" "$casaconda/home" + fi + done +fi + system_image="$casaconda/system" if [ ! -e "$system_image" ]; then - apptainer build --sandbox --disable-cache "$casaconda/system" docker://ubuntu:22.04 - apptainer run --fakeroot --writable "$system_image" mkdir /conda - apptainer run --fakeroot --writable "$system_image" apt update + apptainer build --sandbox "$casaconda/system" "$script_dir/apptainer.def" fi if [ ! -e "$casaconda/Miniforge3-Linux-x86_64.sh" ]; then wget -O "$casaconda/Miniforge3-Linux-x86_64.sh" https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh fi -apptainer="apptainer run -B $casaconda/conda:/conda $system_image" -conda="$apptainer /conda/bin/conda" +apptainer="apptainer run --containall $mounts-B $casaconda:/casa -B /tmp $system_image" +root_apptainer="apptainer run --writable --fakeroot --containall -B $casaconda:/casa -B /tmp $system_image" + +conda="$apptainer /casa/conda/bin/conda" if [ ! -e "$casaconda/conda" ]; then mkdir "$casaconda/conda" - cd "$casaconda" - apptainer run -B "$casaconda/conda:/conda" "$system_image" sh "./Miniforge3-Linux-x86_64.sh" -u -b -p "/conda" + $apptainer sh "/casa/Miniforge3-Linux-x86_64.sh" -u -b -p "/casa/conda" $conda update conda -y fi -script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - -cp -a "$script_dir/setup_run_apt" "$casaconda/conda/" -apptainer run --fakeroot --writable -B $casaconda/conda:/conda "$system_image" /conda/setup_run_apt - -cp -a "$script_dir/setup_run_conda" "$casaconda/conda/" -$apptainer /conda/setup_run_conda +for script in setup_run_apt setup_run_conda setup_run_compiled; do + cp -a "$script_dir/$script" "$casaconda" + $root_apptainer /casa/$script +done -# -# Dev environment -# - -# Source version control -version_control_packages=( - git - git-lfs - #! git-man - #! subversion still necessary ? -) - -# Configure/build toolchain -toolchain_packages=( - automake - clang - cmake - #! cmake-curses-gui - gxx - gcc - gfortran - #! libc-dev - make - pkg-config - #! pyqt5-dev - #! pyqt5-dev-tools - #! python3-sip-dev - #! qtchooser -) - -# Development tools and convenience utilities -development_tools=( - ack-grep - bash-completion - emacs-nox - flake8 - gdb - gdbserver - valgrind - gedit - git-man - gitg - gitk - kate - kdiff3 - kompare - kwrite - locate - meld - nano - python2 # only for flake8 tests of casa-distro - python3-autopep8 - python3-objgraph - python3-venv - spyder - strace - tox - vim - xterm - xdot -) - -# Documentation building -documentation_building_packages=( - doxygen - ghostscript - graphviz - nbconvert #? was jupyter-nbconvert - pandoc - sphinx - sphinx-gallery - #! texlive-latex-base - #! texlive-latex-extra # needed by doxygen to render LaTeX formulas - #! texlive-fonts-recommended - wkhtmltopdf -) - -brainvisa_standard_dev_dependencies=( - #! libasound2-dev - libblitz #? was libblitz0-dev - boost-cpp #? was libboost-dev - #! libboost-filesystem-dev - #! libboost-system-dev - dcmtk #? was libdcmtk-dev - libexpat #? was libexpat1-dev - #! libgl1-mesa-dev - libglib #? was libglib2.0-dev - libglu #? was libglu1-mesa-dev - libjpeg-turbo #? was libjpeg-dev - #! libminc-dev - netcdf4 #? was libnetcdf-dev - #! libomp-dev # OpenMP with the clang compiler - #! libopenjp2-7-dev - libpng #? was libpng-dev - #! libqt5x11extras5-dev - #! libqwt-qt5-dev - libsigcpp #? was libsigc++-2.0-dev - #! libspnav-dev - libsvm #? was libsvm-dev - libtiff #? was libtiff-dev - #! libvtk9-dev - #! libvtk9-qt-dev - libxml2 #? was libxml2-dev - #! qttools5-dev - #! qtmultimedia5-dev - #! qttools5-dev-tools - #! zlib1g-dev -) +if [ ! -e "$casaconda/src" ]; then + $apptainer git clone https://github.com/sapetnioc/brainvisa-submodules /casa/src + $apptainer git -C /casa/src submodule update --init --recursive +fi -"$conda" install -y ${version_control_packages[@]} ${toolchain_packages[@]} ${documentation_building_packages[@]} ${brainvisa_standard_dev_dependencies[@]} +# Update all sources +$apptainer git -C /casa/src submodule foreach ls diff --git a/conda/setup_dev_conda b/conda/setup_dev_conda new file mode 100755 index 00000000..1fe8e495 --- /dev/null +++ b/conda/setup_dev_conda @@ -0,0 +1,124 @@ +#! /bin/bash + +# +# Setup dev dependencies with conda +# + +set -x +set -e + +conda=/casa/conda/bin/conda + +if [ -e /casa/conda/bin/nano ]; then + # if nano is installed, we assume that this script has already been + # executed. + echo "setup_dev_conda already executed => execution canceled" + exit 0 +fi + +# Source version control +version_control_packages=( + git + git-lfs + #! git-man + #! subversion still necessary ? +) + +# Configure/build toolchain +toolchain_packages=( + automake + clang + cmake + #! cmake-curses-gui + gxx + gcc + gfortran + #! libc-dev + make + pkg-config + #! pyqt5-dev + #! pyqt5-dev-tools + #! python3-sip-dev + #! qtchooser +) + +# Development tools and convenience utilities +development_tools=( + ack-grep + bash-completion + emacs-nox + flake8 + gdb + gdbserver + valgrind + gedit + git-man + gitg + gitk + kate + kdiff3 + kompare + kwrite + locate + meld + nano + python2 # only for flake8 tests of casa-distro + python3-autopep8 + python3-objgraph + python3-venv + spyder + strace + tox + vim + xterm + xdot +) + +# Documentation building +documentation_building_packages=( + doxygen + ghostscript + graphviz + nbconvert #? was jupyter-nbconvert + pandoc + sphinx + sphinx-gallery + #! texlive-latex-base + #! texlive-latex-extra # needed by doxygen to render LaTeX formulas + #! texlive-fonts-recommended + wkhtmltopdf +) + +brainvisa_standard_dev_dependencies=( + #! libasound2-dev + libblitz #? was libblitz0-dev + boost-cpp #? was libboost-dev + #! libboost-filesystem-dev + #! libboost-system-dev + dcmtk #? was libdcmtk-dev + libexpat #? was libexpat1-dev + #! libgl1-mesa-dev + libglib #? was libglib2.0-dev + libglu #? was libglu1-mesa-dev + libjpeg-turbo #? was libjpeg-dev + #! libminc-dev + netcdf4 #? was libnetcdf-dev + #! libomp-dev # OpenMP with the clang compiler + #! libopenjp2-7-dev + libpng #? was libpng-dev + #! libqt5x11extras5-dev + #! libqwt-qt5-dev + libsigcpp #? was libsigc++-2.0-dev + #! libspnav-dev + libsvm #? was libsvm-dev + libtiff #? was libtiff-dev + #! libvtk9-dev + #! libvtk9-qt-dev + libxml2 #? was libxml2-dev + #! qttools5-dev + #! qtmultimedia5-dev + #! qttools5-dev-tools + #! zlib1g-dev +) + +$conda install -y ${version_control_packages[@]} ${toolchain_packages[@]} ${documentation_building_packages[@]} ${brainvisa_standard_dev_dependencies[@]} diff --git a/conda/setup_run_compiled b/conda/setup_run_compiled new file mode 100755 index 00000000..815c314c --- /dev/null +++ b/conda/setup_run_compiled @@ -0,0 +1,51 @@ +#! /bin/bash + +# +# Setup run dependencies requiring software compilation +# + +set -x +set -e + +if [ -e /casa/conda/lib/pkgconfig/libopenjp2.pc ]; then + # if libopenjp2.pc is installed, we assume that this script has already been + # executed. + echo "setup_run_compiled already executed => execution canceled" + exit 0 +fi + +# MIRCen's fork of openslide with support for CZI format +# +tmp=$(mktemp -d) + +cd "$tmp" +wget https://github.com/uclouvain/openjpeg/archive/refs/tags/v2.5.0.tar.gz +tar xf v2.5.0.tar.gz +cd openjpeg-2.5.0 +mkdir build +cd build +cmake .. -DCMAKE_BUILD_TYPE=Release "-DCMAKE_INSTALL_PREFIX=/casa/conda" +make +make install +cp libopenjp2.pc /casa/conda/lib/pkgconfig/ + +cd "$tmp" +git clone --depth=1 https://github.com/MIRCen/openslide.git +cd openslide +autoreconf --install +./configure --prefix="/casa/conda" +make -j$(nproc) +make install + +# reinstall libminc 4.0.0 because newer versions can't properly read freesurfer +# .mgz files +cd "$tmp" +git clone https://github.com/BIC-MNI/libminc.git --single-branch --branch libminc-2-3-00 +cd libminc +cmake . -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DLIBMINC_BUILD_SHARED_LIBS=ON -DLIBMINC_MINC1_SUPPORT=ON "-DCMAKE_INSTALL_PREFIX=/casa/conda" +make -j$(nproc) +make install +cd .. +rm -rf libminc + +rm -Rf "$tmp" diff --git a/conda/setup_run_conda b/conda/setup_run_conda index 0d2bf8cd..607e4091 100755 --- a/conda/setup_run_conda +++ b/conda/setup_run_conda @@ -7,7 +7,14 @@ set -x set -e -conda=/conda/bin/conda +if [ -e /casa/conda/bin/git ]; then + # if git is installed, we assume that this script has already been + # executed. + echo "setup_run_conda already executed => execution canceled" + exit 0 +fi + +conda=/casa/conda/bin/conda build_dependencies=( # General build dependencies (notably useful for pip-compiled packages) @@ -121,45 +128,6 @@ headless_anatomist_dependencies=( $conda install -y ${build_dependencies[@]} ${fsl_runtime_dependencies[@]} ${matlab_runtime_dependencies[@]} ${generally_useful_packages[@]} ${headless_anatomist_dependencies[@]} -export PATH="/conda/bin:$PATH" -export LD_LIBRARY_PATH="/conda/lib:$LD_LIBRARY_PATH" - -# MIRCen's fork of openslide with support for CZI format -# -tmp=$(mktemp -d) - -cd "$tmp" -wget https://github.com/uclouvain/openjpeg/archive/refs/tags/v2.5.0.tar.gz -tar xf v2.5.0.tar.gz -cd openjpeg-2.5.0 -mkdir build -cd build -cmake .. -DCMAKE_BUILD_TYPE=Release "-DCMAKE_INSTALL_PREFIX=/conda" -make -make install -cp libopenjp2.pc /conda/lib/pkgconfig/ - -cd "$tmp" -git clone --depth=1 https://github.com/MIRCen/openslide.git -cd openslide -autoreconf --install -./configure --prefix="/conda" -make -j$(nproc) -make install - -# reinstall libminc 4.0.0 because newer versions can't properly read freesurfer -# .mgz files -cd "$tmp" -git clone https://github.com/BIC-MNI/libminc.git --single-branch --branch libminc-2-3-00 -cd libminc -cmake . -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DLIBMINC_BUILD_SHARED_LIBS=ON -DLIBMINC_MINC1_SUPPORT=ON "-DCMAKE_INSTALL_PREFIX=/conda" -make -j$(nproc) -make install -cd .. -rm -rf libminc - -rm -Rf "$tmp" - pip_installed_dependencies=( 'pydantic>=1.9'