Skip to content

Commit

Permalink
Merge pull request #82 from NERSC/lastephey/update-default-args
Browse files Browse the repository at this point in the history
update default build args, make pull use them
  • Loading branch information
lastephey authored Aug 7, 2023
2 parents 4dab7e1 + 74d77cd commit 81b6295
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 38 deletions.
5 changes: 2 additions & 3 deletions podman_hpc/podman_hpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ def rmsqi(siteconf, image):
@click.pass_context
@click.argument("podman_args", nargs=-1, type=click.UNPROCESSED)
@click.argument("image")
def pull(ctx, siteconf, image, podman_args):
def pull(ctx, siteconf, image, podman_args, **site_opts):
"""Pulls an image to a local repository and makes a squashed copy."""
cmd = [siteconf.podman_bin, "pull"]
cmd.extend(podman_args)
cmd.extend(siteconf.default_pull_args)
cmd.extend(siteconf.get_cmd_extensions("pull", site_opts))
cmd.append(image)
proc = Popen(cmd)
proc.communicate()
Expand All @@ -179,7 +179,6 @@ def pull(ctx, siteconf, image, podman_args):
sys.stderr.write("Pull failed.\n")
sys.exit(proc.returncode)


# podman-hpc shared-run subcommand #########################################
@podhpc.command(
context_settings=dict(
Expand Down
69 changes: 34 additions & 35 deletions podman_hpc/siteconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ class SiteConfig:
_valid_params = ["podman_bin", "mount_program", "modules_dir",
"shared_run_exec_args", "shared_run_command",
"graph_root", "run_root",
"default_args", "default_run_args",
"additional_stores", "hooks_dir",
"localid_var", "tasks_per_node_var", "ntasks_pattern",
"config_home", "mksquashfs_bin",
"wait_timeout", "wait_poll_interval"]
"wait_timeout", "wait_poll_interval",
"use_default_args",
]
_valid_templates = ["shared_run_args_template",
"graph_root_template",
"run_root_template",
"default_args_template",
"default_run_args_template",
"additional_stores_template",
"config_home_template"
]
Expand All @@ -46,20 +45,17 @@ class SiteConfig:
config_home = f"{_xdg_base}/config"
run_root = _xdg_base
additional_stores = []
default_args = []
hooks_dir = f"{sys.prefix}/share/containers/oci/hooks.d"
graph_root = f"{_xdg_base}/storage"
squash_dir = os.environ.get(
"SQUASH_DIR", f'{os.environ.get("SCRATCH", "/tmp")}/storage'
)
modules_dir = "/etc/podman_hpc/modules.d"
shared_run_exec_args = ["-e", "SLURM_*", "-e", "PALS_*", "-e", "PMI_*"]
default_run_args = []
default_pull_args = []
default_build_args = []
use_default_args = True
shared_run_command = ["sleep", "infinity"]
podman_bin = "podman"
mount_program = "fuse-overlayfs-warp"
mount_program = "fuse-overlayfs-wrap"
runtime = "runc"
localid_var = "SLURM_LOCALID"
tasks_per_node_var = "SLURM_STEP_TASKS_PER_NODE"
Expand Down Expand Up @@ -95,47 +91,46 @@ def __init__(self, squash_dir=None, log_level=None):
self._check_and_set(param)

self.read_site_modules()
# TODO: Allow this to be over-rideable
if len(self.default_args) == 0:

if isinstance(self.wait_poll_interval, str):
self.wait_poll_interval = \
float(self.wait_poll_interval)
if isinstance(self.wait_timeout, str):
self.wait_timeout = float(self.wait_timeout)

if self.use_default_args is True:
self.default_args = [
"--root", self.graph_root,
"--runroot", self.run_root,
"--storage-opt",
f"additionalimagestore={self.additionalimagestore()}",
"--storage-opt",
f"mount_program={self.mount_program}",
"--storage-opt",
"ignore_chown_errors=true",
"--cgroup-manager", "cgroupfs",
]
if len(self.default_run_args) == 0:
self.default_run_args = [
"--storage-opt",
"ignore_chown_errors=true",
"--storage-opt",
f"additionalimagestore={self.additionalimagestore()}",
"--hooks-dir", self.hooks_dir,
"-e", f"{_MOD_ENV}={self.modules_dir}",
"--env", f"{_MOD_ENV}={self.modules_dir}",
"--annotation", f"{_HOOKS_ANNO}=true",
"--security-opt", "seccomp=unconfined",
]
if isinstance(self.wait_poll_interval, str):
self.wait_poll_interval = \
float(self.wait_poll_interval)
if isinstance(self.wait_timeout, str):
self.wait_timeout = float(self.wait_timeout)
if len(self.default_pull_args) == 0:
self.default_pull_args = [
"--root", self.graph_root,
"--runroot", self.run_root,
"--cgroup-manager", "cgroupfs",
]
if len(self.default_build_args) == 0:
self.default_build_args = [
"--root", self.graph_root,
"--runroot", self.run_root,
"--storage-opt",
f"mount_program={self.mount_program}",
"--hooks-dir", self.hooks_dir,
"--env", f"{_MOD_ENV}={self.modules_dir}",
"--annotation", f"{_HOOKS_ANNO}=true",
]
self.default_pull_args = [
"--storage-opt",
"ignore_chown_errors=true",
"--cgroup-manager", "cgroupfs",
]
]
else:
self.default_args = []
self.default_run_args = []
self.default_build_args = []
self.default_pull_args = []

self.log_level = log_level

def dump_config(self):
Expand Down Expand Up @@ -349,6 +344,10 @@ def get_cmd_extensions(self, subcommand, args):
cmds.extend(self.default_run_args)
elif subcommand == "build":
cmds.extend(self.default_build_args)
elif subcommand == "pull":
cmds.extend(self.default_pull_args)
else:
pass
for mod, mconf in self.sitemods.get(subcommand, {}).items():
if 'cli_arg' not in mconf:
continue
Expand Down

0 comments on commit 81b6295

Please sign in to comment.