diff --git a/environments/payu-dev/build_inner.sh b/environments/payu-dev/build_inner.sh index 5935347..15cada4 100644 --- a/environments/payu-dev/build_inner.sh +++ b/environments/payu-dev/build_inner.sh @@ -1,14 +1,10 @@ ### Custom install inner # Fix shebang headers in payu entry points (issue with pip installed packages: https://github.com/ACCESS-NRI/MED-condaenv/issues/78) -for file in ${CONDA_INSTALLATION_PATH}/envs/${FULLENV}/bin/payu-*; do +for file in ${CONDA_INSTALLATION_PATH}/envs/${FULLENV}/bin/payu*; do # Using payu-* to modify payu-run, payu-collate, payu-sync files echo "Adding python header to $file" # Substitute the first line of file (e.g. 1s), if it starts with #! (regex ^#!/.*$), # with the python executable in the conda environment sed -i "1s|^#!/.*$|#!${CONDA_INSTALLATION_PATH}/envs/${FULLENV}/bin/python|" "$file" -done - -# Patch payu shebang header with outer python executable that launches a container when run. -# This means when payu submits qsub commands (e.g. payu run), it uses this python executable and launches a container on PBS job -sed -i "1s|^#!/.*$|#!${CONDA_SCRIPT_PATH}/${FULLENV}.d/bin/python|" "${CONDA_INSTALLATION_PATH}/envs/${FULLENV}/bin/payu" \ No newline at end of file +done \ No newline at end of file diff --git a/environments/payu-dev/config.sh b/environments/payu-dev/config.sh index 909deb5..8d2603a 100644 --- a/environments/payu-dev/config.sh +++ b/environments/payu-dev/config.sh @@ -27,4 +27,14 @@ declare -a rpms_to_remove=() declare -a replace_from_apps=() declare -a outside_commands_to_include=( "pbs_tmrsh" ) declare -a outside_files_to_copy=() -declare -a replace_with_external=() \ No newline at end of file +declare -a replace_with_external=() +declare -a launcher_commands=( + "payu-run" + "payu-collate" + "payu-sync" + "payu" + "payu-branch" + "payu-checkout" + "payu-clone" + "payu-profile" +) \ No newline at end of file diff --git a/environments/payu/build_inner.sh b/environments/payu/build_inner.sh index b24820e..e69de29 100644 --- a/environments/payu/build_inner.sh +++ b/environments/payu/build_inner.sh @@ -1,16 +0,0 @@ -### Custom install inner to build jupyter lab extensions - -# set +u -# eval "$( ${MAMBA} shell hook --shell bash)" -# micromamba activate "${CONDA_INSTALLATION_PATH}/envs/${FULLENV}" -# set -u - -# jupyter lab build - -# Patch payu shebang header with outer python executable that launches a container when run. -# This means when payu submits qsub commands (e.g. payu run), it uses this python executable and launches a container on PBS job -sed -i "1s|^#!/.*$|#!${CONDA_SCRIPT_PATH}/${FULLENV}.d/bin/python|" "${CONDA_INSTALLATION_PATH}/envs/${FULLENV}/bin/payu" -# Above command follows pattern of "sed -i '1s|pattern|replacement|' filename" -# which modifies the environment's payu executable in place (-i), -# and replaces the first line (1s), if it starts with #! (regex ^#!/.*$), -# with the payu launcher script \ No newline at end of file diff --git a/environments/payu/config.sh b/environments/payu/config.sh index d98e786..2006cfe 100644 --- a/environments/payu/config.sh +++ b/environments/payu/config.sh @@ -27,3 +27,13 @@ declare -a replace_from_apps=() declare -a outside_commands_to_include=( "pbs_tmrsh" ) declare -a outside_files_to_copy=() declare -a replace_with_external=() +declare -a launcher_commands=( + "payu-run" + "payu-collate" + "payu-sync" + "payu" + "payu-branch" + "payu-checkout" + "payu-clone" + "payu-profile" +) diff --git a/modules/common_cmd_v1 b/modules/common_cmd_v1 new file mode 100644 index 0000000..d35eb5f --- /dev/null +++ b/modules/common_cmd_v1 @@ -0,0 +1,30 @@ +#%Module1.0 + +set prefix __CONDA_BASE__/__APPS_SUBDIR__ +set package __CONDA_INSTALL_BASENAME__ + +# Prevent running this module with a running payu module +conflict payu + +# Name of this module's environment +lassign [split [module-info name] {/}] module_name module_version +set condaenv "${module_version}" +set basedir "$prefix/$package/envs/$condaenv" +if {![ file exists $basedir ]} { + # For modulenames which are $ENVIRONMENT/$VERSION, rather than conda/$ENIRONMENT-$VERSION + set condaenv "${module_name}-${module_version}" + set basedir "$prefix/$package/envs/$condaenv" +} + +set myscripts [ file normalize __CONDA_BASE__/__SCRIPT_SUBDIR__/$condaenv.d/bin ] +set overlay_path [ string map {/conda/ /envs/} $basedir ].sqsh + +module load singularity + +prepend-path CONTAINER_OVERLAY_PATH $overlay_path + +# Add launcher script directory to PATH +prepend-path PATH $myscripts + +### Extra env to get other things working +setenv OMPI_MCA_orte_launch_agent $myscripts/orted \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh index 807b5e6..d1ab3ca 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -119,16 +119,24 @@ function inner() { copy_if_changed "${override}" "${CONDA_SCRIPT_PATH}"/overrides/"${override##*/}" done mkdir -p "${CONDA_MODULE_PATH}" - copy_and_replace "${SCRIPT_DIR}"/../modules/common_v3 "${CONDA_MODULE_PATH}"/.common_v3 CONDA_BASE APPS_SUBDIR CONDA_INSTALL_BASENAME SCRIPT_SUBDIR - copy_and_replace "${SCRIPT_DIR}"/launcher_conf.sh "${CONDA_SCRIPT_PATH}"/launcher_conf.sh CONDA_BASE APPS_SUBDIR CONDA_INSTALL_BASENAME + copy_and_replace "${SCRIPT_DIR}"/../modules/"${COMMON_MODULEFILE}" "${CONDA_MODULE_PATH}"/."${COMMON_MODULEFILE}" CONDA_BASE APPS_SUBDIR CONDA_INSTALL_BASENAME SCRIPT_SUBDIR + copy_and_replace "${SCRIPT_DIR}"/launcher_conf.sh "${CONDA_SCRIPT_PATH}"/launcher_conf.sh CONDA_BASE APPS_SUBDIR CONDA_INSTALL_BASENAME CONDA_SCRIPT_PATH FULLENV ### Create symlink tree mkdir -p "${CONDA_SCRIPT_PATH}"/"${FULLENV}".d/{bin,overrides} cp "${CONDA_SCRIPT_PATH}"/{launcher.sh,launcher_conf.sh} "${CONDA_SCRIPT_PATH}"/"${FULLENV}".d/bin pushd "${CONDA_SCRIPT_PATH}"/"${FULLENV}".d/bin - for i in $( ls "${ENV_INSTALLATION_PATH}"/bin ); do - ln -s launcher.sh $i - done + if [ "${#launcher_commands[@]}" -gt 0 ]; then + # Only create launcher symlinks for the specified commands + for cmd in "${launcher_commands[@]}"; do + ln -s launcher.sh $cmd + done + else + # Create a launcher symlinks for each executable in the bin directory + for i in $( ls "${ENV_INSTALLATION_PATH}"/bin ); do + ln -s launcher.sh $i + done + fi ### Add in the outside commands for i in "${outside_commands_to_include[@]}"; do @@ -225,7 +233,7 @@ fi if [[ "${DO_UPDATE}" == "--install" ]]; then - ln -s .common_v3 "${CONDA_OUTER_BASE}"/"${MODULE_SUBDIR}"/"${MODULE_NAME}"/"${MODULE_VERSION}" + ln -s ."${COMMON_MODULEFILE}" "${CONDA_OUTER_BASE}"/"${MODULE_SUBDIR}"/"${MODULE_NAME}"/"${MODULE_VERSION}" fi pushd "${CONDA_TEMP_PATH}" diff --git a/scripts/install_config.sh b/scripts/install_config.sh index cd505df..a85c915 100644 --- a/scripts/install_config.sh +++ b/scripts/install_config.sh @@ -37,6 +37,9 @@ export CONDA_INSTALL_BASENAME="base_conda" #TODO: Eventually replace with conda # so payu modules are named payu/$MODULE_VERSION (e.g. payu/1.1.5) export MODULE_NAME="conda" +# Common modulefile to use for conda environments +export COMMON_MODULEFILE="common_cmd_v1" + ### Derived locations - extra '.' for arcane rsync magic export CONDA_SCRIPT_PATH="${CONDA_BASE}"/./"${SCRIPT_SUBDIR}" export CONDA_MODULE_PATH="${CONDA_BASE}"/./"${MODULE_SUBDIR}"/"${MODULE_NAME}" diff --git a/scripts/launcher_conf.sh b/scripts/launcher_conf.sh index 17f7040..e3e09b0 100644 --- a/scripts/launcher_conf.sh +++ b/scripts/launcher_conf.sh @@ -1,10 +1,11 @@ ### Subject to change export SINGULARITY_BINARY_PATH="/opt/singularity/bin/singularity" export CONTAINER_PATH="__CONDA_BASE__/__APPS_SUBDIR__/__CONDA_INSTALL_BASENAME__/etc/base.sif" -if [[ "${CONDA_EXE}" ]]; then - export CONDA_BASE_ENV_PATH="${CONDA_EXE//\/bin\/micromamba/}" -else - export CONDA_BASE_ENV_PATH="__CONDA_BASE__/__APPS_SUBDIR__/__CONDA_INSTALL_BASENAME__" -fi + +export CONDA_BASE_ENV_PATH="__CONDA_BASE__/__APPS_SUBDIR__/__CONDA_INSTALL_BASENAME__" declare -a bind_dirs=( "/etc" "/half-root" "/local" "/ram" "/run" "/system" "/usr" "/var/lib/sss" "/var/run/munge" "/sys/fs/cgroup" "/iointensive" ) + +# Set up the environment launcher script path - useful for scripts, such as payu, +# to know how launch the container directly +export ENV_LAUNCHER_SCRIPT_PATH="__CONDA_SCRIPT_PATH__/__FULLENV__.d/bin/launcher.sh" \ No newline at end of file