#!/usr/bin/env sh set -o errexit set -o pipefail set -o nounset source ${CI_PROJECT_DIR}/ci/stack_env.sh mkdir -p ${STACK_LOCATION} cd ${STACK_LOCATION} echo "Setting up spack" if [ ! -d spack/.git ]; then git clone https://github.com/spack/spack.git else git -C spack fetch # git -C spack pull fi git -C spack checkout $SPACK_VERSION echo "Adding spack system config file" if [ ! -e ${SPACK_SYSTEM_CONFIG_PATH}/spack.yaml ] then spack/bin/spack env create ${environment} fi for file in mirrors packages concretizer config spack definitions modules do if [ -e "${STACK_CONFIG_PATH}/${file}.yaml" ]; then echo "Copying ${STACK_CONFIG_PATH}/${file}.yaml to ${SPACK_SYSTEM_CONFIG_PATH}" cp "${STACK_CONFIG_PATH}/${file}.yaml" \ ${SPACK_SYSTEM_CONFIG_PATH} cp "${STACK_CONFIG_PATH}/${file}.yaml" spack/etc/spack fi if [ -e "${STACK_CONFIG_PATH}/${file}_stack.yaml" ]; then echo "Copying ${STACK_CONFIG_PATH}/${file}_stack.yaml to ${SPACK_SYSTEM_CONFIG_PATH}" cp "${STACK_CONFIG_PATH}/${file}_stack.yaml" \ ${SPACK_SYSTEM_CONFIG_PATH} fi if [ -e "${STACK_CONFIG_PATH}/${file}_${environment}.yaml" ]; then echo "Copying ${STACK_CONFIG_PATH}/${file}_${environment}.yaml to ${SPACK_SYSTEM_CONFIG_PATH}/${file}_env.yaml" cp "${STACK_CONFIG_PATH}/${file}_${environment}.yaml" \ ${SPACK_SYSTEM_CONFIG_PATH}/${file}_env.yaml fi done cp -r "${STACK_CONFIG_PATH}/templates" ${SPACK_SYSTEM_CONFIG_PATH} cat <<EOF > ${SPACK_SYSTEM_CONFIG_PATH}/config_stack.yaml config: template_dirs: - ${SPACK_SYSTEM_CONFIG_PATH}/templates EOF cat <<EOF > ${SPACK_SYSTEM_CONFIG_PATH}/modules_stack.yaml modules: default: roots: lmod: ${STACK_LOCATION}/spack/share/spack/lmod/${environment} tcl: ${STACK_LOCATION}/spack/share/spack/modules/${environment} EOF mirrors=$(jq -Mrc ' .spack.mirrors | to_entries | map(select(.value.type="relative")) | map(" \(.key): \(env.STACK_LOCATION)/\(.value.url)") | .[] ' ${STACK_CONFIG}) cat <<EOF > ${SPACK_SYSTEM_CONFIG_PATH}/mirrors.yaml mirrors: ${mirrors} EOF cp "${SPACK_SYSTEM_CONFIG_PATH}/mirrors.yaml" spack/etc/spack echo "Setting up packages" if [ -e ${SPACK_SYSTEM_CONFIG_PATH}/packages.yaml ] then mv ${SPACK_SYSTEM_CONFIG_PATH}/packages.yaml packages.yaml.old fi echo "packages:" > ${SPACK_SYSTEM_CONFIG_PATH}/packages.yaml export system_compiler=$(jq -Mrc ' .stack | .system_arch as $arch | .system_compiler | to_entries | .[].value | "\(.compiler)@\(.version) \($arch)" ' ${STACK_CONFIG}) jq -Mrc ' .stack.system_packages | map(" \(.):\n require:\n - spec: \"%\(env.system_compiler)\"") | .[] ' ${STACK_CONFIG} >> ${SPACK_SYSTEM_CONFIG_PATH}/packages.yaml if [ -e packages.yaml.old ] then yq eval-all --inplace 'select(fileIndex==0) *+ select(fileIndex==1)' \ ${SPACK_SYSTEM_CONFIG_PATH}/packages.yaml packages.yaml.old rm packages.yaml.old fi cp "${SPACK_SYSTEM_CONFIG_PATH}/packages.yaml" spack/etc/spack echo "Setting up extra repos" EXTERNAL_REPOS=$(jq -r '.spack.repos | keys[]' ${STACK_CONFIG}) spack_external_repos="${SPACK_SYSTEM_CONFIG_PATH}/external_repos" mkdir -p ${spack_external_repos} echo "repos:" > ${SPACK_SYSTEM_CONFIG_PATH}/repos.yaml for repo in ${EXTERNAL_REPOS} do repo_branch=$(jq -r ".spack.repos.\"${repo}\".branch" ${STACK_CONFIG}) echo " - ${spack_external_repos}/${repo}" echo " - ${spack_external_repos}/${repo}" >> ${SPACK_SYSTEM_CONFIG_PATH}/repos.yaml if [ ! -d ${spack_external_repos}/${repo} ]; then echo "Cloning repo: ${repo}" url_branch=$(jq -r ".spack.repos.\"${repo}\".url" ${STACK_CONFIG}) git clone -b ${repo_branch} ${url_branch} ${spack_external_repos}/${repo} else echo "Update repo: ${repo}" git -C ${spack_external_repos}/$repo fetch git -C ${spack_external_repos}/$repo checkout ${repo_branch} git -C ${spack_external_repos}/$repo pull fi done cp "${SPACK_SYSTEM_CONFIG_PATH}/repos.yaml" spack/etc/spack echo "Setting up buildcache" spack/bin/spack gpg trust \ $GPG_PRIVATE_KEY if [ ! -d ${MOUNT_POINT}/buildcache/build_cache ]; then spack/bin/spack gpg publish \ -d ${MOUNT_POINT}/buildcache fi if ! spack/bin/spack mirror list | grep buildcache; then echo "Add buildcache in mirrors" spack/bin/spack mirror add \ --type binary \ --scope system \ buildcache file://${MOUNT_POINT}/buildcache fi spack/bin/spack buildcache keys \ --install \ --trust #spack/bin/spack buildcache update-index /buildcache