Skip to content

Commit

Permalink
templates/common/util_functions:
Browse files Browse the repository at this point in the history
* increased minimum memory threshold for ram disk
* moved apt_add_repo and friends to common/install_functions

templates/dask/util_functions:
* validating conda tarball before caching to gcs

templates/generate-action.pl:
* improved usage documentation a little

templates/gpu/install_functions
* using /opt/conda/miniconda3/bin/python3 instead of /usr/bin/ for
  venv pre-install
  • Loading branch information
cjac committed Jan 9, 2025
1 parent 88f9f7f commit 119f1b1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 60 deletions.
56 changes: 1 addition & 55 deletions templates/common/util_functions
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function is_ramdisk() {
function mount_ramdisk(){
local free_mem
free_mem="$(awk '/^MemFree/ {print $2}' /proc/meminfo)"
if [[ ${free_mem} -lt 10500000 ]]; then return 0 ; fi
if [[ ${free_mem} -lt 20500000 ]]; then return 0 ; fi

# Write to a ramdisk instead of churning the persistent disk

Expand Down Expand Up @@ -350,60 +350,6 @@ function check_os() {
fi
}

#
# Generate repo file under /etc/apt/sources.list.d/
#
function apt_add_repo() {
local -r repo_name="$1"
local -r repo_data="$3" # "http(s)://host/path/uri argument0 .. argumentN"
local -r include_src="${4:-yes}"
local -r kr_path="${5:-/usr/share/keyrings/${repo_name}.gpg}"
local -r repo_path="${6:-/etc/apt/sources.list.d/${repo_name}.list}"

echo "deb [signed-by=${kr_path}] ${repo_data}" > "${repo_path}"
if [[ "${include_src}" == "yes" ]] ; then
echo "deb-src [signed-by=${kr_path}] ${repo_data}" >> "${repo_path}"
fi

apt-get update -qq
}

#
# Generate repo file under /etc/yum.repos.d/
#
function dnf_add_repo() {
local -r repo_name="$1"
local -r repo_url="$3" # "http(s)://host/path/filename.repo"
local -r kr_path="${5:-/etc/pki/rpm-gpg/${repo_name}.gpg}"
local -r repo_path="${6:-/etc/yum.repos.d/${repo_name}.repo}"

curl -s -L "${repo_url}" \
| dd of="${repo_path}" status=progress
# | perl -p -e "s{^gpgkey=.*$}{gpgkey=file://${kr_path}}" \
}

#
# Keyrings default to
# /usr/share/keyrings/${repo_name}.gpg (debian/ubuntu) or
# /etc/pki/rpm-gpg/${repo_name}.gpg (rocky/RHEL)
#
function os_add_repo() {
local -r repo_name="$1"
local -r signing_key_url="$2"
local -r repo_data="$3" # "http(s)://host/path/uri argument0 .. argumentN"
local kr_path
if is_debuntu ; then kr_path="${5:-/usr/share/keyrings/${repo_name}.gpg}"
else kr_path="${5:-/etc/pki/rpm-gpg/${repo_name}.gpg}" ; fi

mkdir -p "$(dirname "${kr_path}")"

curl -fsS --retry-connrefused --retry 10 --retry-max-time 30 "${signing_key_url}" \
| gpg --import --no-default-keyring --keyring "${kr_path}"

if is_debuntu ; then apt_add_repo "${repo_name}" "${signing_key_url}" "${repo_data}" "${4:-yes}" "${kr_path}" "${6:-}"
else dnf_add_repo "${repo_name}" "${signing_key_url}" "${repo_data}" "${4:-yes}" "${kr_path}" "${6:-}" ; fi
}

function configure_dkms_certs() {
if test -v PSN && [[ -z "${PSN}" ]]; then
echo "No signing secret provided. skipping";
Expand Down
4 changes: 2 additions & 2 deletions templates/dask/util_functions
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ function install_conda_packages() {
if [[ "$retval" == "0" ]] ; then
is_installed="1"
pushd "${DASK_CONDA_ENV}"
time (
tar czf "${local_tarball}" .
time ( set -e
tar czf "${local_tarball}" . && tar tzf "${local_tarball}"
gcloud storage cp "${local_tarball}" "${gcs_tarball}"
rm "${local_tarball}"
)
Expand Down
14 changes: 13 additions & 1 deletion templates/generate-action.pl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@
my $action = $ARGV[0];
my $v = { template_path => "${action}.in" };

sub usage{ die "Usage: $0 <action>" }
sub usage{
# TODO: use File::Find to list the available actions for the user
my $message = <<EOF;
This script evaluates a template to generate an initialization action.
The output is printed to STDOUT.
Action templates reside under templates/$action and end in .sh.in
The <action> argument is the destination action name, not the source.
EOF
print STDERR $message;
die "Usage:$/$0 <action>"
}

usage unless( $action && -f "$ENV{PWD}/templates/$v->{template_path}" );

Expand Down
4 changes: 2 additions & 2 deletions templates/gpu/install_functions
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ function download_gpu_monitoring_agent(){

function install_gpu_monitoring_agent_dependency(){
cd /opt/google/compute-gpu-monitoring/linux
/usr/bin/python3 -m venv venv
/opt/conda/miniconda3/bin/python3 -m venv venv
(
source venv/bin/activate
pip install wheel
Expand Down Expand Up @@ -829,7 +829,7 @@ function install_gpu_agent() {
| sed -e 's/-u --format=/--format=/' \
| dd status=none of="${install_dir}/report_gpu_metrics.py"
local venv="${install_dir}/venv"
/usr/bin/python3 -m venv "${venv}"
/opt/conda/miniconda3/bin/python3 -m venv "${venv}"
(
source "${venv}/bin/activate"
python3 -m pip install --upgrade pip
Expand Down

0 comments on commit 119f1b1

Please sign in to comment.