Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions Dockerfiles/e4s-new/_common/build-and-install-python.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/bash -e

## Helpers
. utilities.sh

require_env \
CACHE_ONLY \
PYTHON_MIRROR \
PYTHON_PATH \
PYTHON_VERSION \
SPACK_CORE_ROOT

sys_arch=$(arch)
if [[ $sys_arch == "aarch64" ]]; then
spack_target=aarch64
elif [[ $sys_arch == "x86_64" ]]; then
spack_target=x86_64_v3
elif [[ $sys_arch == "ppc64le" ]]; then
spack_target=ppc64le
else
_err "ERROR: Cannot process system architecture"
exit 1
fi

. /etc/os-release
cmd . $SPACK_CORE_ROOT/share/spack/setup-env.sh
if [[ $ID == "rocky" ]] ; then
source scl_source enable gcc-toolset-13
fi
cmd spack -e . compiler find
cmd spack -e . config add packages:all:require:[target=$spack_target]
cmd spack -e . add python@$PYTHON_VERSION +bz2+crypt+ctypes+dbm~debug+libxml2+lzma+optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tkinter+uuid+zlib

if ! is_true $CACHE_ONLY ; then
export AWS_ACCESS_KEY_ID=$(cat /run/secrets/AWS_ACCESS_KEY_ID)
export AWS_SECRET_ACCESS_KEY=$(cat /run/secrets/AWS_SECRET_ACCESS_KEY)

multi_cmd "$(cat <<EOF

## Build from source + push to cache (use padding to enable flexibility in installation)
spack config add 'config:install_tree:padded_length:256'
spack mirror add --autopush remote s3://$PYTHON_MIRROR
spack env activate -d .
spack gpg trust /run/secrets/SIGNING_KEY
spack concretize -f | tee concretize.log
spack env depfile -o Makefile
spack config add "config:db_lock_timeout:120"
spack config add "config:connect_timeout:60"
make -j16 -k SPACK_COLOR=always --output-sync=recurse || true
spack install
spack env deactivate

## Update buildcache index
spack buildcache update-index --keys remote

## Cleanup
spack mirror rm remote
spack config remove "config:install_tree:padded_length"

EOF
)"

fi


multi_cmd "$(cat <<EOF

## Install from cache into final location
spack mirror add --scope site remote https://$PYTHON_MIRROR
spack buildcache keys -it
spack config add "config:install_tree:root:$PYTHON_PATH/pkgs"
spack config add "config:install_tree:projections:all:'{name}-{version}'"
spack config add "config:db_lock_timeout:120"
spack config add "config:connect_timeout:60"
spack -e . install --cache-only

## Install pip
spack load python
which python | grep $PYTHON_VERSION
wget -q https://bootstrap.pypa.io/get-pip.py
python get-pip.py
which pip | grep $PYTHON_VERSION

## Cleanup
rm -rf .spack-env

EOF
)"
62 changes: 62 additions & 0 deletions Dockerfiles/e4s-new/_common/build-and-install-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash -e

## Helpers
. utilities.sh

require_env \
CACHE_ONLY \
SPACK_CORE_ROOT \
TOOLS_MIRROR \
TOOLS_PATH

cmd . $SPACK_CORE_ROOT/share/spack/setup-env.sh

if ! is_true $CACHE_ONLY ; then
export AWS_ACCESS_KEY_ID=$(cat /run/secrets/AWS_ACCESS_KEY_ID)
export AWS_SECRET_ACCESS_KEY=$(cat /run/secrets/AWS_SECRET_ACCESS_KEY)

multi_cmd "$(cat <<EOF

## Build from source + push to cache (use padding to enable flexibility in installation)
spack config add 'config:install_tree:padded_length:256'
spack mirror add --autopush remote s3://$TOOLS_MIRROR
spack env activate -d .
spack gpg trust /run/secrets/SIGNING_KEY
spack concretize -f | tee concretize.log
spack env depfile -o Makefile
spack config add "config:db_lock_timeout:120"
spack config add "config:connect_timeout:60"
make -j16 -k SPACK_COLOR=always --output-sync=recurse || true
spack install
spack env deactivate

## Update buildcache index
spack buildcache update-index --keys remote

## Cleanup
spack mirror rm remote
spack config remove "config:install_tree:padded_length"

EOF
)"

fi


multi_cmd "$(cat <<EOF

## Install from cache into final location
spack mirror add --scope site remote https://$TOOLS_MIRROR
spack buildcache keys -it
spack config add "config:install_tree:root:$TOOLS_PATH/pkgs"
spack config add "config:install_tree:projections:all:'{name}-{version}'"
spack config add "config:db_lock_timeout:120"
spack config add "config:connect_timeout:60"
spack -e . config add "view: $TOOLS_PATH/view"
spack -e . install -j3 -p3 --cache-only

## Cleanup
rm -rf .spack-env

EOF
)"
127 changes: 127 additions & 0 deletions Dockerfiles/e4s-new/_common/build-argparse.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/bin/bash -e

if ! declare -F utilities_are_available >/dev/null 2>&1; then
echo error: expected utility functions not found in environment
exit 1
fi

valid_targets=""

set_valid_targets() {
valid_targets="$@"
}

check_usage() {
if is_empty valid_targets; then
_err "error: check_usage: cannot check usage without valid_targets; valid_targets is empty"
exit 1
fi

usage() {
export valid_targets
echo "usage: $0 [--cache-only] <$(echo $valid_targets | tr ' ' '|')>"
exit 1
}

# argument parsing adapted from:
# StackOverflow user Robert Siemer April 20, 2015
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
set -o errexit -o pipefail -o noclobber -o nounset
getopt --test > /dev/null && true
if [[ $? -ne 4 ]]; then
echo 'I’m sorry, `getopt --test` failed in this environment.'
exit 1
fi
LONGOPTS=cache-only,help
OPTIONS=h
PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@") || usage
eval set -- "$PARSED"
cache_only=false

while true; do
case "$1" in
--cache-only)
cache_only=true
shift
;;
-h|--help)
usage
exit 0
;;
--)
shift
break
;;
*)
echo "Programming error"
exit 3
;;
esac
done
set +o noclobber

if [[ $# -ne 1 ]]; then
fail=1
else
target=$1
target_is_valid="no"
for valid_target in $valid_targets; do
if [[ $target == "$valid_target" ]]; then
target_is_valid=yes
break
fi
done
if [[ $target_is_valid == "no" ]]; then
fail=1
fi
fi
if is_set fail; then
usage
exit 1
fi
}

check_usage_no_pos_args() {
usage() {
export valid_targets
echo "usage: $0 [--cache-only]"
exit 1
}

# argument parsing adapted from:
# StackOverflow user Robert Siemer April 20, 2015
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
set -o errexit -o pipefail -o noclobber -o nounset
getopt --test > /dev/null && true
if [[ $? -ne 4 ]]; then
echo 'I’m sorry, `getopt --test` failed in this environment.'
exit 1
fi
LONGOPTS=cache-only,help
OPTIONS=h
PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@") || usage
eval set -- "$PARSED"
cache_only=false

while true; do
case "$1" in
--cache-only)
cache_only=true
shift
;;
-h|--help)
usage
exit 0
;;
--)
shift
break
;;
*)
echo "Programming error"
exit 3
;;
esac
done
set +o noclobber
}
6 changes: 6 additions & 0 deletions Dockerfiles/e4s-new/_common/spack.python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
spack:
concretizer:
reuse: false
unify: when_possible

specs: []
13 changes: 13 additions & 0 deletions Dockerfiles/e4s-new/_common/spack.tools.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
spack:
concretizer:
reuse: false
unify: when_possible

specs:
- ccache
- cmake
- environment-modules
- gmake
- libtree
- ninja
- patchelf
61 changes: 61 additions & 0 deletions Dockerfiles/e4s-new/_common/utilities.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash -e

GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'

utilities_are_available() {
return 0
}

cmd() {
echo -e "${GREEN}+ $@ ${NC}"
eval $@
}

multi_cmd() {
local line
while IFS= read -r line || [[ -n "$line" ]]; do
if [[ -z "${line//[[:space:]]/}" ]]; then
continue
fi
echo -e "${GREEN}+ $line ${NC}"
eval $line
done < <(printf "%s" "$1")
}

is_set() {
! [[ -z "${!1+x}" ]];
}

is_empty() {
[[ -z "${!1}" ]];
}

is_true() {
if [[ $1 == "true" ]]; then
return 0
fi
return 1
}

_err() {
echo -e "${RED}$@${NC}"
}

require_env() {
msgs=()
for vv in "$@" ; do
if ! is_set $vv ; then
msgs+=("error: required environment variable is not set: $vv")
fi
done

for msg in "${msgs[@]}" ; do
_err $msg
done

if [[ ${#msgs[@]} -gt 0 ]]; then
exit 1
fi
}
Loading
Loading