diff --git a/bin/yashchiki b/bin/yashchiki index fd6f377d86a699a98eede00919b825951f052b1d..53c68f267e7535692d6c01865a55d519c2d82eed 100644 --- a/bin/yashchiki +++ b/bin/yashchiki @@ -52,7 +52,7 @@ parser = argparse.ArgumentParser( # mandatory parser.add_argument( - "style", type=str, choices=["visionary", "asic"], + "style", type=str, choices=["visionary", "asic", "f27"], help="Style of container to build.") parser.add_argument( "spack_dir", type=pathlib.Path, diff --git a/bin/yashchiki_deploy_container.sh b/bin/yashchiki_deploy_container.sh index b43ed8c69901385636aaafe2ab365ded960f4ca3..c7abccc709e515ee5310de76262ed4215f77169e 100755 --- a/bin/yashchiki_deploy_container.sh +++ b/bin/yashchiki_deploy_container.sh @@ -16,6 +16,7 @@ DATE=$(date --iso) declare -A CONTAINER_PREFIX_LUT CONTAINER_PREFIX_LUT[visionary]="" CONTAINER_PREFIX_LUT[asic]="asic" +CONTAINER_PREFIX_LUT[f27]="f27" CONTAINER_PREFIX=${CONTAINER_PREFIX_LUT[$CONTAINER_STYLE]} diff --git a/share/yashchiki/styles/f27/config.yaml b/share/yashchiki/styles/f27/config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7b8f7f4c4a1db63c8a449d3e23a2264f1c6bc8fa --- /dev/null +++ b/share/yashchiki/styles/f27/config.yaml @@ -0,0 +1,7 @@ +docker_base_image: "debian:bullseye" +dependency_python: "3.8.2" +spack_gcc: + # Whether to build the specified gcc via spack or assume existance. + build: true + # Version to use as compiler for spack build. + version: "11.2.0" diff --git a/share/yashchiki/styles/f27/create_recipe.sh b/share/yashchiki/styles/f27/create_recipe.sh new file mode 100755 index 0000000000000000000000000000000000000000..5d31589b67e9964bfa18287c679920ba9c249e2b --- /dev/null +++ b/share/yashchiki/styles/f27/create_recipe.sh @@ -0,0 +1,159 @@ +#!/bin/bash + +ROOT_DIR="$(dirname "$(dirname "$(dirname "$(dirname "$(dirname "$(readlink -m "${BASH_SOURCE[0]}")")")")")")" +source "${ROOT_DIR}/lib/yashchiki/commons.sh" + +# create container description file +# * based on Debian buster (minimal) + a few extra packages (e.g. git, python, ...) +# * bind mount spack's fetch-cache and ccache into the container -> speed up stuff +# * bind mount spack's buildcache into the container -> speed up stuff +# * copy spack installation script into container +# * create "spack" user in the container and run spack installation script as spack user +# (-> installs to /opt/spack, and creates views) +# * provide "apps" which set environment variables to appropriate views +cat <<EOF >"${YASHCHIKI_RECIPE_PATH}" +Bootstrap: docker +From: ${DOCKER_BASE_IMAGE} + +%setup + # bind-mount spack-folder as moving involves copying the complete download cache + mkdir \${SINGULARITY_ROOTFS}/opt/spack + mount --no-mtab --bind "${YASHCHIKI_SPACK_PATH}" "\${SINGULARITY_ROOTFS}/opt/spack" + # bind-mount ccache + mkdir \${SINGULARITY_ROOTFS}/opt/ccache + mount --no-mtab --bind "${YASHCHIKI_CACHES_ROOT}/spack_ccache" "\${SINGULARITY_ROOTFS}/opt/ccache" + # bind-mount build_cache + mkdir -p "\${SINGULARITY_ROOTFS}${BUILD_CACHE_INSIDE}" + # create buildcache directory if it does not exist + [ ! -d "${BUILD_CACHE_OUTSIDE}" ] && mkdir -p "${BUILD_CACHE_OUTSIDE}" + # mount the full build cache folder into container because some files might be symlinked to other buildcaches + mount --no-mtab --bind "${BASE_BUILD_CACHE_OUTSIDE}" "\${SINGULARITY_ROOTFS}${BASE_BUILD_CACHE_INSIDE}" + # bind-mount preserved packages in case the build fails + mkdir -p "\${SINGULARITY_ROOTFS}${PRESERVED_PACKAGES_INSIDE}" + mount --no-mtab --bind "${PRESERVED_PACKAGES_OUTSIDE}" "\${SINGULARITY_ROOTFS}${PRESERVED_PACKAGES_INSIDE}" + # bind-mount tmp-folder + mkdir -p "\${SINGULARITY_ROOTFS}/tmp/spack" + mount --no-mtab --bind "${JOB_TMP_SPACK}" "\${SINGULARITY_ROOTFS}/tmp/spack" + # bind-mount spack config tmp-folder + mkdir -p "\${SINGULARITY_ROOTFS}/tmp/spack_config" + mount --no-mtab --bind "${YASHCHIKI_SPACK_CONFIG}" "\${SINGULARITY_ROOTFS}/tmp/spack_config" + # copy install scripts + mkdir "\${SINGULARITY_ROOTFS}/${SPACK_INSTALL_SCRIPTS}" + rsync -av --chmod 0755 "${ROOT_DIR}"/share/yashchiki/styles/${CONTAINER_STYLE}/*.sh "\${SINGULARITY_ROOTFS}/${SPACK_INSTALL_SCRIPTS}" + rsync -av --chmod 0755 "${ROOT_DIR}"/lib/yashchiki/*.sh "\${SINGULARITY_ROOTFS}/${SPACK_INSTALL_SCRIPTS}" + rsync -av "${ROOT_DIR}"/lib/yashchiki/*.awk "\${SINGULARITY_ROOTFS}/${SPACK_INSTALL_SCRIPTS}" + rsync -av "${ROOT_DIR}"/share/yashchiki/patches "\${SINGULARITY_ROOTFS}/${SPACK_INSTALL_SCRIPTS}" + mkdir -p "\${SINGULARITY_ROOTFS}/${META_DIR_INSIDE}" + rsync -av "${META_DIR_OUTSIDE}/" "\${SINGULARITY_ROOTFS}/${META_DIR_INSIDE}" + # init scripts for user convenience + mkdir -p "\${SINGULARITY_ROOTFS}/opt/init" + rsync -av "${ROOT_DIR}"/share/yashchiki/misc-files/init/*.sh "\${SINGULARITY_ROOTFS}/opt/init" + +%files + # NOTE: Due to a bug in singularity 2.6 all paths in this section _cannot_ + # be surrounded in quotes.. ergo there should be no spaces in filenames! If + # there are, I pray for your poor soul that escaping them works.. + # --obreitwi, 17-02-19 # 23:45:51 + # provide spack command to login shells + ${ROOT_DIR}/share/yashchiki/misc-files/setup-spack.sh /etc/profile.d/setup-spack.sh + ${ROOT_DIR}/share/yashchiki/misc-files/locale.gen /etc/locale.gen + ${ROOT_DIR}/share/yashchiki/misc-files/locale.alias /etc/locale.alias + ${ROOT_DIR}/share/yashchiki/misc-files/sudoers /etc/sudoers + + # ECM (2024-04-30) need nvidia stuff for py-cupy + /usr/lib/nvidia + /usr/lib/x86_64-linux-gnu/nvidia + /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1 + /etc/alternatives/nvidia--libnvidia-ml.so.1-x86_64-linux-gnu + /usr/lib/x86_64-linux-gnu/libnvidia-ptxjitcompiler.so.1 + /etc/alternatives/nvidia--libnvidia-ptxjitcompiler.so.1-x86_64-linux-gnu + /usr/lib/x86_64-linux-gnu/libcuda.so + /etc/alternatives/nvidia--libcuda.so-x86_64-linux-gnu + /usr/lib/x86_64-linux-gnu/libcuda.so.1 + /etc/alternatives/nvidia--libcuda.so.1-x86_64-linux-gnu + +%post + + ls /usr/lib/x86_64-linux-gnu/libcuda* + + # create a fingerprint by which we can identify the container from within + cat /proc/sys/kernel/random/uuid > /opt/fingerprint + + # prerequisites + "${SPACK_INSTALL_SCRIPTS}/install_prerequisites.sh" || exit 1 + # cannot specify permissions in files-section + chmod 440 /etc/sudoers + chown root:root /etc/sudoers + # install locales + locale-gen + # propagate environment variables to container recipe + export DEPENDENCY_PYTHON="${DEPENDENCY_PYTHON}" + export YASHCHIKI_BUILD_SPACK_GCC="${YASHCHIKI_BUILD_SPACK_GCC}" + export YASHCHIKI_SPACK_GCC="${YASHCHIKI_SPACK_GCC}" + export YASHCHIKI_SPACK_GCC_VERSION="${YASHCHIKI_SPACK_GCC_VERSION}" + export YASHCHIKI_JOBS="${YASHCHIKI_JOBS}" + export YASHCHIKI_SPACK_CONFIG="/tmp/spack_config" + export YASHCHIKI_CACHES_ROOT="${YASHCHIKI_CACHES_ROOT}" + export YASHCHIKI_BUILD_CACHE_NAME="${YASHCHIKI_BUILD_CACHE_NAME}" + export YASHCHIKI_BUILD_CACHE_ON_FAILURE_NAME="${YASHCHIKI_BUILD_CACHE_ON_FAILURE_NAME}" + export YASHCHIKI_SPACK_VERBOSE="${YASHCHIKI_SPACK_VERBOSE}" + export CONTAINER_STYLE="${CONTAINER_STYLE}" + # Improve efficiency by installing system packages in the background (even + # though we set the number of worker to \${YASHCHIKI_JOBS}, often times - e.g. when + # concretizing - only one process will be active.) + # NOTE: For this to work all spack-related dependencies need to be + # specified under "Inlucde:" above. install_system_dependencies.sh should + # only install packages that are needed once the container finished + # building! + # We kill the main process in case of errors in order to have no silent + # fails! + PID_MAIN="\$\$" + ( "${SPACK_INSTALL_SCRIPTS}/install_system_dependencies.sh" \ + || kill \${PID_MAIN} ) & + "${SPACK_INSTALL_SCRIPTS}/complete_spack_install_routine_called_in_post_as_root.sh" + # system dependencies might not have installed by now + # currently, singularity needs some dependendencies from apt as well, so + # wait till we are finished with system dependencies + wait + "${SPACK_INSTALL_SCRIPTS}/install_singularity_as_root.sh" || \ + ( + sudo -Eu spack "${SPACK_INSTALL_SCRIPTS}/preserve_built_spack_packages.sh" && + exit 1 # propagate the error + ) + # apply some system-level patching (TODO: remove this as soon as gccxml dependency is gone) + "${SPACK_INSTALL_SCRIPTS}/manual_system_level_patching_routine_called_in_post_as_root.sh" +EOF + +# create appenvs for all views... +# append apps for each spackview... +generate_appenv() { +local name_app="$1" +local name_view="$2" +cat <<EOF +%appenv ${name_app} + # there can only be one app loaded at any time + export VIEW_ENV=${name_view} + SVF=/opt/spack_views/\${VIEW_ENV} + export PATH=\${SVF}/bin\${PATH:+:}\${PATH} + export PYTHONHOME=\${SVF} + export SPACK_PYTHON_BINARY=\${SVF}/bin/python + export MANPATH=\${SVF}/man:\${SVF}/share/man\${MANPATH:+:}\${MANPATH} + export LIBRARY_PATH=\${SVF}/lib:\${SVF}/lib64\${LIBRARY_PATH:+:}\${LIBRARY_PATH} + export LD_LIBRARY_PATH=\${SVF}/lib:\${SVF}/lib64\${LD_LIBRARY_PATH:+:}\${LD_LIBRARY_PATH} + export TCLLIBPATH=\${SVF}/lib\${TCLLIBPATH:+:}\${TCLLIBPATH} + export CPATH=\${SVF}/include\${CPATH:+:}\${CPATH} + export C_INCLUDE_PATH=\${SVF}/include\${C_INCLUDE_PATH:+:}\${C_INCLUDE_PATH} + export CPLUS_INCLUDE_PATH=\${SVF}/include\${CPLUS_INCLUDE_PATH:+:}\${CPLUS_INCLUDE_PATH} + export QUIET_CPATH=\${CPATH} + export QUIET_C_INCLUDE_PATH=\${C_INCLUDE_PATH} + export QUIET_CPLUS_INCLUDE_PATH=\${CPLUS_INCLUDE_PATH} + export PKG_CONFIG_PATH=\${SVF}/lib/pkgconfig:\${SVF}/lib64/pkgconfig:\${SVF}/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig\${PKG_CONFIG_PATH:+:}\${PKG_CONFIG_PATH} + export CMAKE_PREFIX_PATH=\${SVF}\${CMAKE_PREFIX_PATH:+:}\${CMAKE_PREFIX_PATH} +EOF +} +for view in "${spack_views[@]}"; do + # generate app + ( + generate_appenv "${view}" "${view}" + ) >> "${YASHCHIKI_RECIPE_PATH}" +done diff --git a/share/yashchiki/styles/f27/install_prerequisites.sh b/share/yashchiki/styles/f27/install_prerequisites.sh new file mode 120000 index 0000000000000000000000000000000000000000..f1997f144bde310e449505dd18ce41fd03686bcf --- /dev/null +++ b/share/yashchiki/styles/f27/install_prerequisites.sh @@ -0,0 +1 @@ +../visionary/install_prerequisites.sh \ No newline at end of file diff --git a/share/yashchiki/styles/f27/install_system_dependencies.sh b/share/yashchiki/styles/f27/install_system_dependencies.sh new file mode 120000 index 0000000000000000000000000000000000000000..e75d34238ee346a8e7697ca0085b0392ae18b906 --- /dev/null +++ b/share/yashchiki/styles/f27/install_system_dependencies.sh @@ -0,0 +1 @@ +../visionary/install_system_dependencies.sh \ No newline at end of file diff --git a/share/yashchiki/styles/f27/manual_system_level_patching_routine_called_in_post_as_root.sh b/share/yashchiki/styles/f27/manual_system_level_patching_routine_called_in_post_as_root.sh new file mode 120000 index 0000000000000000000000000000000000000000..92ca01d392859017c18f10593de39f77306ce904 --- /dev/null +++ b/share/yashchiki/styles/f27/manual_system_level_patching_routine_called_in_post_as_root.sh @@ -0,0 +1 @@ +../visionary/manual_system_level_patching_routine_called_in_post_as_root.sh \ No newline at end of file diff --git a/share/yashchiki/styles/f27/spack_collection.sh b/share/yashchiki/styles/f27/spack_collection.sh new file mode 100644 index 0000000000000000000000000000000000000000..d8220e262a8113e6cfcebdb9326b27fee3159f9e --- /dev/null +++ b/share/yashchiki/styles/f27/spack_collection.sh @@ -0,0 +1,55 @@ +# All spack packages that should be fetched/installed in the container +spack_packages=( + "f27-ido ^${DEPENDENCY_PYTHON} %${YASHCHIKI_SPACK_GCC}" + "f27-niklas ^${DEPENDENCY_PYTHON} %${YASHCHIKI_SPACK_GCC}" +) + +spack_views=(\ + ido + niklas +) + +spack_views_no_default_gcc=( +) + +spack_views_gccxml=( +) + + +spack_gid="nogroup" + +spack_create_user_cmd() { + adduser spack --uid 888 --no-create-home --home /opt/spack --disabled-password --system --shell /bin/bash +} + +# all views get the default gcc except those in spack_views_no_default_gcc +# (defined above) +spack_add_to_view_with_dependencies["${YASHCHIKI_SPACK_GCC}"]="no" +spack_add_to_view["${YASHCHIKI_SPACK_GCC}"]="$( + for viewname in "${spack_views[@]+"${spack_views[@]}"}"; do + # check if the current view matches any view that does not get the + # default gcc + # Note: Currently this allow partial matches + if printf "%s\n" "${spack_views_no_default_gcc[@]+"${spack_views_no_default_gcc[@]}"}" \ + | grep -qF "${viewname}"; then + continue + fi + echo ${viewname} + done | tr '\n' ' ' +)" + +## Add gccxml to those views that still depend on it +spack_add_to_view_gccxml="$( + for viewname in "${spack_views[@]+"${spack_views[@]}"}"; do + # check if the current view matches any view that gets gccxml + # Note: Currently this allow partial matches + if printf "%s\n" "${spack_views_gccxml[@]+"${spack_views_gccxml[@]}"}" \ + | grep -qF "${viewname}"; then + echo ${viewname} + fi + done | tr '\n' ' ' +)" +if [[ "$spack_add_to_view_gccxml" != "" ]]; then + spack_add_to_view_with_dependencies["gccxml"]="no" + spack_add_to_view["gccxml"]="$spack_add_to_view_gccxml" +fi diff --git a/share/yashchiki/styles/f27/spack_custom_view.sh b/share/yashchiki/styles/f27/spack_custom_view.sh new file mode 100644 index 0000000000000000000000000000000000000000..c3284695656d128822a4ca74ab0688a0c6737418 --- /dev/null +++ b/share/yashchiki/styles/f27/spack_custom_view.sh @@ -0,0 +1,6 @@ +cat <<EOF + +${MY_SPACK_CMD} ${SPACK_ARGS_VIEW[@]+"${SPACK_ARGS_VIEW[@]}"} view -d yes symlink -i ${MY_SPACK_VIEW_PREFIX}/ido $(get_latest_hash f27-ido "^${DEPENDENCY_PYTHON}") +${MY_SPACK_CMD} ${SPACK_ARGS_VIEW[@]+"${SPACK_ARGS_VIEW[@]}"} view -d yes symlink -i ${MY_SPACK_VIEW_PREFIX}/niklas $(get_latest_hash f27-niklas "^${DEPENDENCY_PYTHON}") + +EOF