
Attach a Validated Apptainer or rcapsule Container to a SLURM Job Spec
Source: R/container_hook.R
use_rcapsule_container.RdProvides a zero-hard-dependency handoff between reproducible container
builders (such as rcapsule manifests/specs, build_apptainer_def()
recipes, or pre-built .sif / .def file paths) and slurm_job_spec().
Strictly validates all container paths and --bind mounts against traversal
and shell/option injection, records provenance metadata (digest,
r_version, def_path, source), and injects SLURMPILOT_CONTAINER_DIGEST
into the job environment when a cryptographic digest is supplied.
Usage
use_rcapsule_container(
spec = NULL,
container,
binds = character(),
check_exists = FALSE
)Arguments
- spec
Optional
slurmpilot_job_specobject to update. WhenNULL, returns a standalone validated"slurmpilot_container_spec"object.- container
Container descriptor: either (a) a character path to an Apptainer
.sifimage or.defrecipe, (b) aslurmpilot_apptainer_defobject frombuild_apptainer_def(), or (c) a duck-typedrcapsulespec or manifest list containing fields such asapptainer_sif/sif_path/image,apptainer_def/def_path/recipe_path,content_digest/capsule_hash/env_hash,r_version,binds, or nestedtargets$apptainer/manifest.- binds
Optional character vector of extra Apptainer
--bindmounts (e.g."/data:/data:ro").- check_exists
Logical; if
TRUE, asserts that any resolved local.sifor.defpath exists on disk. DefaultFALSE(cluster paths often exist only on the remote HPC filesystem).
Value
Updated slurmpilot_job_spec (when spec is supplied) or a
"slurmpilot_container_spec" object (when spec is NULL).
Examples
spec <- slurm_job_spec(
fun = function(x) x + 1,
args_list = list(1, 2),
resources = resource_spec(2L)
)
capsule <- list(
sif_path = "/scratch/containers/analysis.sif",
def_path = "/scratch/containers/analysis.def",
content_digest = "a1b2c3d4e5f6",
r_version = "4.4.1",
binds = c("/scratch/data:/data:ro")
)
spec2 <- use_rcapsule_container(spec, capsule)
spec2$container_sif
#> [1] "/scratch/containers/analysis.sif"