diff --git a/changelog.d/+local-host-probe.feature.md b/changelog.d/+local-host-probe.feature.md new file mode 100644 index 00000000..d2c61cf2 --- /dev/null +++ b/changelog.d/+local-host-probe.feature.md @@ -0,0 +1 @@ +`check --probe-tools` on a `local` site warns when this host has no `eb` on PATH or no module tool that EasyBuild can use (Lmod through LMOD_CMD or `lmod`, or the tool EASYBUILD_MODULES_TOOL names). diff --git a/changelog.d/+workstation-tutorial.doc.md b/changelog.d/+workstation-tutorial.doc.md new file mode 100644 index 00000000..69fec167 --- /dev/null +++ b/changelog.d/+workstation-tutorial.doc.md @@ -0,0 +1 @@ +New tutorial, Build with EasyBuild on your own machine: the workstation template, `check --probe-tools`, and a module built with real EasyBuild and loaded. diff --git a/docs/orgmode/index.org b/docs/orgmode/index.org index 72783cf0..e35809dc 100644 --- a/docs/orgmode/index.org +++ b/docs/orgmode/index.org @@ -11,6 +11,7 @@ Nothing about a site lives in eb-pipeline: the site file holds it, and the envir New here? [[file:tutorials/first-build-list.org][Run your first build list]] installs eb-pipeline on one Linux machine, runs a build list against a stand-in for EasyBuild, and ends with a result file, a log for each line, and a line that fails without stopping the run. +[[file:tutorials/workstation-build.org][Build with EasyBuild on your own machine]] installs EasyBuild beside EESSI's Lmod, checks the machine with =check --probe-tools=, and builds and loads a module, with no cluster and no Slurm. | You want to | Read | |-----------------------------------+--------------------------------------------| diff --git a/docs/orgmode/reference/cli.org b/docs/orgmode/reference/cli.org index 3aa069cc..cc5e4fc9 100644 --- a/docs/orgmode/reference/cli.org +++ b/docs/orgmode/reference/cli.org @@ -157,7 +157,7 @@ An option with a variable in the table takes its value from that variable when t |-----------------------------+-------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | =--site FILE= | =EB_PIPELINE_SITE= | The site file. Required unless =--check-from-commit= is set. | | =--lists-dir DIR= | =EB_PIPELINE_LISTS_DIR= | A directory that must contain every file that the =build_lists= of a target names. A missing file is an error of the site file. | -| =--probe-tools= | | Start =BIN --version= for each sibling tool that an enabled phase calls, and fail when one cannot start, prints no version, or prints one below the =min_version= of its =[site.tools]= table. | +| =--probe-tools= | | Start =BIN --version= for each sibling tool that an enabled phase calls, and fail when one cannot start, prints no version, or prints one below the =min_version= of its =[site.tools]= table. On a =local= site with no module wrapper, also warn when this host has no =eb= on =PATH= or no module tool EasyBuild can use. | | =--list FILE= | =EB_PIPELINE_LIST= | The build list or easystack passed to =--stack-checks= or =--check-from-commit=. | | =--target NAME= | =EB_PIPELINE_TARGET= | Use only this target's =cpu_target= and expanded source paths. Requires =--stack-checks= when given as an option; =EB_PIPELINE_TARGET= alone is ignored without it. Without it, target-dependent values from every target are used. | | =--stack-checks LIST= | | Comma-separated =files=, =arch=, =cuda-cc=, =generation=, =provided=, =known-failures= or =buildenv=. Each names an =eb-stack stack= subprocess. Requires =--list= and =--site=. | diff --git a/docs/orgmode/reference/templates.org b/docs/orgmode/reference/templates.org index b1c3b692..d0ee325c 100644 --- a/docs/orgmode/reference/templates.org +++ b/docs/orgmode/reference/templates.org @@ -52,7 +52,7 @@ ERROR [main] -: cannot create small-cluster.toml: File exists (os error 17) One machine with no scheduler, such as a workstation, a lab server or a continuous integration runner. =kind = "local"= starts every command of a run on this host as a plain process, so no command goes through =srun=. No module is loaded before a build: =eb= comes from =PATH=, for example from =pip install easybuild=. -EasyBuild still needs a module tool to write and find modules: source EESSI's init, which provides Lmod, or install Lmod, and set =EASYBUILD_MODULES_TOOL=Lmod=. +EasyBuild still needs a module tool to write and find modules: source EESSI's init, which provides Lmod, or install Lmod, and set =EASYBUILD_MODULES_TOOL=Lmod=. =eb-pipeline check --site site.toml --probe-tools= says when this host has neither =eb= nor the module tool. Each line runs as its own =eb= command with the line's options only, so a line whose dependencies are not installed yet needs =--robot= on the line. #+INCLUDE: "../../../templates/workstation.toml" src toml diff --git a/docs/orgmode/tutorials/index.org b/docs/orgmode/tutorials/index.org index e75206aa..085a87fb 100644 --- a/docs/orgmode/tutorials/index.org +++ b/docs/orgmode/tutorials/index.org @@ -12,4 +12,5 @@ It explains only what the next step needs; [[file:../explanation/index.org][Expl :maxdepth: 1 first-build-list + workstation-build #+end_export diff --git a/docs/orgmode/tutorials/workstation-build.org b/docs/orgmode/tutorials/workstation-build.org new file mode 100644 index 00000000..4188c398 --- /dev/null +++ b/docs/orgmode/tutorials/workstation-build.org @@ -0,0 +1,187 @@ +#+TITLE: Build with EasyBuild on your own machine +#+OPTIONS: toc:nil todo:nil num:nil author:nil title:nil +#+STARTUP: content + +* Build with EasyBuild on your own machine + +By the end of this tutorial eb-pipeline will have driven EasyBuild on one Linux machine to install a package and write its module. +You will then load that module. +There is no cluster and no Slurm: the site file's =local= scheduler starts every phase on this machine. +The package is a bundle with no components, so the build takes seconds and downloads nothing; a real easyconfig goes through the same steps. + +** What you will need + +- A Linux machine with Python 3.9 or newer and =python3 -m venv=. +- EESSI mounted at =/cvmfs/software.eessi.io=, for its Lmod. EasyBuild needs a module tool to write and find modules; an Lmod you installed yourself works the same way. +- eb-pipeline on your =PATH=, as [[file:../howto/install.org][Install eb-pipeline]] describes. + +** Make a directory to work in + +Every step from here on runs in one directory, which the commands call =$WORK=: + +#+begin_src bash +export WORK=$HOME/eb-workstation +mkdir -p "$WORK" +cd "$WORK" +#+end_src + +** Give EasyBuild a module tool + +Source EESSI's init, which puts Lmod on your =PATH= and sets =LMOD_CMD=, and tell EasyBuild to use Lmod: + +#+begin_src bash +source /cvmfs/software.eessi.io/versions/2023.06/init/lmod/bash +export EASYBUILD_MODULES_TOOL=Lmod +#+end_src + +#+begin_example +Module for EESSI/2023.06 loaded successfully +EESSI has selected x86_64/amd/zen4 as the compatible CPU target for EESSI/2023.06 +#+end_example + +The CPU target in the second line is your machine's. +Do this before the next step: EESSI's init puts a Python of its own on =PATH=, and EasyBuild must find the Python it is installed in first. + +** Install EasyBuild + +Install EasyBuild into a virtual environment and put it first on your =PATH=: + +#+begin_src bash +python3 -m venv "$WORK/venv" +"$WORK/venv/bin/pip" install --quiet easybuild==5.4.2 +export PATH="$WORK/venv/bin:$PATH" +eb --version +#+end_src + +#+begin_example +This is EasyBuild 5.4.2 (framework: 5.4.2, easyblocks: 5.4.2) on host yourhost. +#+end_example + +** Write a site file + +=init= writes a site file from a template; =workstation= is the one for a single machine with no scheduler: + +#+begin_src bash +eb-pipeline init --template workstation --out site.toml +sed -i "s|/srv/eb|$WORK|g" site.toml +#+end_src + +#+begin_example +INFO [init] -: wrote template workstation to site.toml +#+end_example + +Every path in the template sits under =/srv/eb=; =sed= moves them under =$WORK=, so EasyBuild builds in =$WORK/scratch= and installs in =$WORK/software=. + +Check the file, and with =--probe-tools= check this machine too: + +#+begin_src bash +eb-pipeline check --site site.toml --probe-tools +#+end_src + +#+begin_example +INFO [check] workstation: site file is valid +#+end_example + +On a =local= site, =--probe-tools= looks for =eb=, runs =eb --version=, and looks for the module tool, and prints a =WARN= line for each one it cannot find or start. +With the two steps above in the other order it prints: + +#+begin_example +WARN [check] workstation: `eb --version` fails on this host: ERROR: No compatible 'python' command found via $PATH (EasyBuild requires Python 3.6+); set EB_PYTHON to the Python that has EasyBuild installed, or put its directory first on PATH +#+end_example + +** Write an easyconfig and a build list + +The easyconfig is a bundle with no components, built with the =SYSTEM= toolchain, so EasyBuild needs no compiler and no source: + +#+begin_src bash +mkdir -p easyconfigs +cat > easyconfigs/Hello-1.0.eb <<'EOF' +easyblock = 'Bundle' + +name = 'Hello' +version = '1.0' + +homepage = 'https://easybuild.io' +description = "A bundle with no components: EasyBuild installs nothing and writes its module." + +toolchain = SYSTEM + +moduleclass = 'tools' +EOF +printf '%s\n' "$WORK/easyconfigs/Hello-1.0.eb" > software.list +#+end_src + +The build list names one easyconfig per line; a path works as well as a name EasyBuild finds on its robot path. + +** See what a run would start + +#+begin_src bash +eb-pipeline run --site site.toml --list software.list --target cpu --build-type production --dry-run +#+end_src + +#+begin_example +# [licences] not configured +# [shard] not configured +# [sources] not configured +# [admission] not configured +[build] eb $WORK/easyconfigs/Hello-1.0.eb +# [checks] not configured +# [caches] not configured +# [logs] not configured +INFO [run] cpu: dry run: nothing executed +#+end_example + +The =build= phase starts =eb= directly, with no =srun= in front of it, because the scheduler is =local=. + +** Build it + +#+begin_src bash +eb-pipeline run --site site.toml --list software.list --target cpu --build-type production --result result.json +echo $? +#+end_src + +#+begin_example +INFO [licences] cpu: not configured +INFO [shard] cpu: not configured +INFO [sources] cpu: not configured +INFO [admission] cpu: not configured +INFO [checks] cpu: not configured +INFO [caches] cpu: not configured +INFO [logs] cpu: not configured +INFO [build] cpu: Hello-1.0: start +INFO [build] cpu: Hello-1.0: ok +INFO [summary] cpu: summary.json and summary.html written in $WORK/logs/20261126_015425 +0 +#+end_example + +=result.json= records the line as built, with the log EasyBuild wrote: + +#+begin_src bash +grep -E '"log"|"status": "(success|failed)"' result.json +#+end_src + +#+begin_example + "log": "$WORK/logs/20261126_015425/cpu/Hello-1.0.stdout.log", + "status": "success", +#+end_example + +** Load the module + +EasyBuild wrote the module under =$WORK/software/modules/all=: + +#+begin_src bash +module use "$WORK/software/modules/all" +module load Hello/1.0 +echo "$EBROOTHELLO" +#+end_src + +#+begin_example +$WORK/software/software/Hello/1.0 +#+end_example + +** What you did + +You installed EasyBuild beside EESSI's Lmod and wrote a site file for one machine. +=check --probe-tools= checked that machine, and =run= built a module you then loaded. +To build software of your own, put its easyconfigs in the build list: lines that EasyBuild resolves from its robot path, with any =eb= options after the name, as in [[file:first-build-list.org][Run your first build list]]. +[[file:../reference/templates.org][The site file templates]] lists the other templates, and [[file:../howto/write-a-site-file.org][Write a site file]] goes through every table. diff --git a/share/completions/_eb-pipeline b/share/completions/_eb-pipeline index ecf1c3ea..3cd10db4 100644 --- a/share/completions/_eb-pipeline +++ b/share/completions/_eb-pipeline @@ -46,7 +46,7 @@ buildenv\:"\`stack buildenv\` on a plain build list, failing while a toolchain o '--easybuild-version=[EasyBuild release \`X.Y.Z\`. Overrides \`eb-X.Y.Z\` in the list file name]:EASYBUILD_VERSION:_default' \ '--gap-out=[Write eb-stack'\''s gap report files into this directory]:GAP_OUT:_files' \ '--generation=[Toolchain generation passed to \`eb-stack stack gap\`]:GENERATION:_default' \ -'--probe-tools[Run each needed tool'\''s \`--version\` and enforce min_version]' \ +'--probe-tools[Run each needed tool'\''s \`--version\` and enforce min_version. On a \`local\` site, also warn when this host lacks \`eb\` or the module tool EasyBuild uses]' \ '--check-from-commit[Ask \`eb-stack stack from-commit\` whether pins are already in the EasyBuild release tag]' \ '--shadow[Also write \`stack shadow\` JavaScript Object Notation (JSON) output to \`DIR/shadow.json\`]' \ '-h[Print help (see more with '\''--help'\'')]' \ diff --git a/share/completions/eb-pipeline.fish b/share/completions/eb-pipeline.fish index b6f33181..c2bb0cd4 100644 --- a/share/completions/eb-pipeline.fish +++ b/share/completions/eb-pipeline.fish @@ -57,7 +57,7 @@ complete -c eb-pipeline -n "__fish_eb_pipeline_using_subcommand check" -l easybl complete -c eb-pipeline -n "__fish_eb_pipeline_using_subcommand check" -l easybuild-version -d 'EasyBuild release `X.Y.Z`. Overrides `eb-X.Y.Z` in the list file name' -r complete -c eb-pipeline -n "__fish_eb_pipeline_using_subcommand check" -l gap-out -d 'Write eb-stack\'s gap report files into this directory' -r -F complete -c eb-pipeline -n "__fish_eb_pipeline_using_subcommand check" -l generation -d 'Toolchain generation passed to `eb-stack stack gap`' -r -complete -c eb-pipeline -n "__fish_eb_pipeline_using_subcommand check" -l probe-tools -d 'Run each needed tool\'s `--version` and enforce min_version' +complete -c eb-pipeline -n "__fish_eb_pipeline_using_subcommand check" -l probe-tools -d 'Run each needed tool\'s `--version` and enforce min_version. On a `local` site, also warn when this host lacks `eb` or the module tool EasyBuild uses' complete -c eb-pipeline -n "__fish_eb_pipeline_using_subcommand check" -l check-from-commit -d 'Ask `eb-stack stack from-commit` whether pins are already in the EasyBuild release tag' complete -c eb-pipeline -n "__fish_eb_pipeline_using_subcommand check" -l shadow -d 'Also write `stack shadow` JavaScript Object Notation (JSON) output to `DIR/shadow.json`' complete -c eb-pipeline -n "__fish_eb_pipeline_using_subcommand check" -s h -l help -d 'Print help (see more with \'--help\')' diff --git a/src/host.rs b/src/host.rs new file mode 100644 index 00000000..11d41f30 --- /dev/null +++ b/src/host.rs @@ -0,0 +1,204 @@ +//! What a `local` site needs on the host that runs it. +//! +//! A `local` scheduler runs every phase on the host that runs eb-pipeline, +//! so `check --probe-tools` can look at that host before a build fails on +//! it. EasyBuild needs `eb` and a module tool; the module tool is the one +//! EASYBUILD_MODULES_TOOL names, Lmod when it is unset, and EasyBuild finds +//! it through the variable or the program below. + +use crate::schema::Site; + +/// Module tools EasyBuild knows, with the variable that holds the +/// command's path and the program looked up on PATH without it. +const MODULE_TOOLS: [(&str, &str, &str); 3] = [ + ("Lmod", "LMOD_CMD", "lmod"), + ("EnvironmentModules", "MODULES_CMD", "modulecmd.tcl"), + ("EnvironmentModulesC", "", "modulecmd"), +]; + +/// Problems a `local` site would hit on this host, one sentence each. +/// Empty for another scheduler kind, and when the site's module wrapper +/// (`modules.shell_init` or `modules.init`) sets up the environment, since +/// what that provides is only known after it runs. +pub fn local_problems( + site: &Site, + env: &dyn Fn(&str) -> Option, + on_path: &dyn Fn(&str) -> bool, +) -> Vec { + let m = &site.modules; + if site.scheduler.kind != "local" || m.shell_init.is_some() || !m.init.is_empty() { + return Vec::new(); + } + let mut out = Vec::new(); + if !on_path("eb") { + out.push( + "`eb` is not on PATH, and the local scheduler runs it on this host; install EasyBuild (`pip install easybuild`) or load it through modules.init".to_string(), + ); + } + let set = env("EASYBUILD_MODULES_TOOL").filter(|v| !v.is_empty()); + let name = set.as_deref().unwrap_or("Lmod"); + if let Some((tool, var, prog)) = MODULE_TOOLS.iter().find(|(t, _, _)| *t == name) { + let by_var = !var.is_empty() && env(var).is_some_and(|v| !v.is_empty()); + if !by_var && !on_path(prog) { + let how = if var.is_empty() { + format!("`{prog}` on PATH") + } else { + format!("{var} or `{prog}` on PATH") + }; + let why = if set.is_some() { + "EASYBUILD_MODULES_TOOL names" + } else { + "EASYBUILD_MODULES_TOOL is unset, so EasyBuild uses" + }; + out.push(format!( + "{why} {tool} and this host has no {how}; set modules.shell_init to the module tool's init (EESSI's init/lmod/bash provides Lmod), or install one and set EASYBUILD_MODULES_TOOL" + )); + } + } + out +} + +/// The problem `eb --version` shows on this host for a `local` site, if +/// any. `eb` is a launcher that picks the first Python on PATH it accepts, +/// so an `eb` that is on PATH can still fail to start, as when an init +/// script puts a Python without EasyBuild ahead of the one that has it. +/// None for another scheduler kind, with a module wrapper, or with no `eb` +/// on PATH, which [`local_problems`] reports. +pub fn eb_problem(site: &Site) -> Option { + let m = &site.modules; + if site.scheduler.kind != "local" + || m.shell_init.is_some() + || !m.init.is_empty() + || !on_path("eb") + { + return None; + } + let out = std::process::Command::new("eb") + .arg("--version") + .stdin(std::process::Stdio::null()) + .output(); + let text = match out { + Ok(o) if o.status.success() => return None, + Ok(o) => { + let all = format!( + "{}{}", + String::from_utf8_lossy(&o.stdout), + String::from_utf8_lossy(&o.stderr) + ); + all.lines() + .find(|l| !l.trim().is_empty()) + .unwrap_or("no output") + .trim() + .to_string() + } + Err(e) => e.to_string(), + }; + Some(eb_hint(&text)) +} + +/// The WARN text for an `eb --version` that failed with `first`. +fn eb_hint(first: &str) -> String { + let hint = if first.contains("No compatible 'python'") { + "; set EB_PYTHON to the Python that has EasyBuild installed, or put its directory first on PATH" + } else { + "" + }; + format!("`eb --version` fails on this host: {first}{hint}") +} + +/// Whether `prog` names an executable file in a PATH entry. +pub fn on_path(prog: &str) -> bool { + use std::os::unix::fs::PermissionsExt; + let Some(path) = std::env::var_os("PATH") else { + return false; + }; + std::env::split_paths(&path).any(|d| { + std::fs::metadata(d.join(prog)) + .is_ok_and(|m| m.is_file() && m.permissions().mode() & 0o111 != 0) + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + fn site(kind: &str, init: &[&str], shell_init: Option<&str>) -> Site { + let modules = match shell_init { + Some(f) => format!("init = {init:?}\nshell_init = \"{f}\""), + None => format!("init = {init:?}"), + }; + let text = format!( + "schema_version = 1\nkind = \"site\"\n[site]\nname = \"w\"\n[scheduler]\nkind = \"{kind}\"\n\ + [[targets]]\nname = \"cpu\"\nbuild_lists = [\"software.list\"]\ndefault = true\n\ + [filesystems]\nscratch = \"/srv/s\"\ntmp = \"/srv/s/tmp\"\nbuild_path = \"/srv/s/b\"\n\ + install_root = \"/srv/sw\"\nlog_root = \"/srv/logs\"\n[modules]\n{modules}\n" + ); + toml::from_str(&text).expect("test site parses") + } + + fn env<'a>(pairs: &'a [(&'a str, &'a str)]) -> impl Fn(&str) -> Option + 'a { + move |k| { + pairs + .iter() + .find(|(n, _)| *n == k) + .map(|(_, v)| v.to_string()) + } + } + + #[test] + fn bare_host_names_eb_and_lmod() { + let p = local_problems(&site("local", &[], None), &env(&[]), &|_| false); + assert_eq!(p.len(), 2, "{p:?}"); + assert!(p[0].contains("`eb` is not on PATH"), "{p:?}"); + assert!(p[1].contains("EASYBUILD_MODULES_TOOL is unset"), "{p:?}"); + assert!(p[1].contains("LMOD_CMD or `lmod` on PATH"), "{p:?}"); + } + + #[test] + fn lmod_cmd_or_program_satisfies_lmod() { + let s = site("local", &[], None); + assert!(local_problems(&s, &env(&[("LMOD_CMD", "/x/lmod")]), &|p| p == "eb").is_empty()); + assert!(local_problems(&s, &env(&[]), &|p| p == "eb" || p == "lmod").is_empty()); + } + + #[test] + fn named_tool_is_the_one_checked() { + let s = site("local", &[], None); + let e = [("EASYBUILD_MODULES_TOOL", "EnvironmentModulesC")]; + let p = local_problems(&s, &env(&e), &|p| p == "eb" || p == "lmod"); + assert_eq!(p.len(), 1, "{p:?}"); + assert!(p[0].contains("names EnvironmentModulesC"), "{p:?}"); + assert!(local_problems(&s, &env(&e), &|p| p == "eb" || p == "modulecmd").is_empty()); + } + + #[test] + fn unknown_tool_is_left_to_easybuild() { + let s = site("local", &[], None); + let e = [("EASYBUILD_MODULES_TOOL", "SomethingNew")]; + assert!(local_problems(&s, &env(&e), &|p| p == "eb").is_empty()); + } + + #[test] + fn python_launcher_failure_names_eb_python() { + let w = eb_hint("ERROR: No compatible 'python' command found via $PATH (EasyBuild requires Python 3.6+)"); + assert!( + w.starts_with("`eb --version` fails on this host: ERROR"), + "{w}" + ); + assert!(w.contains("EB_PYTHON"), "{w}"); + assert!(!eb_hint("Traceback").contains("EB_PYTHON")); + } + + #[test] + fn wrapper_or_slurm_skips_the_host() { + let none = |_: &str| false; + assert!(local_problems(&site("slurm", &[], None), &env(&[]), &none).is_empty()); + assert!(local_problems(&site("local", &["EasyBuild"], None), &env(&[]), &none).is_empty()); + let s = site( + "local", + &[], + Some("/cvmfs/software.eessi.io/versions/2023.06/init/lmod/bash"), + ); + assert!(local_problems(&s, &env(&[]), &none).is_empty()); + } +} diff --git a/src/lib.rs b/src/lib.rs index 4cb8b43d..621b06ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,7 @@ pub mod eessi; pub mod exit; pub mod from_commit; pub mod gap; +pub mod host; pub mod lint; pub mod metrics; pub mod notify; diff --git a/src/main.rs b/src/main.rs index e758fbc1..5da6e4cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,7 +99,9 @@ enum Cmd { /// Directory that must hold every build list a target names. #[arg(long, env = "EB_PIPELINE_LISTS_DIR")] lists_dir: Option, - /// Run each needed tool's `--version` and enforce min_version. + /// Run each needed tool's `--version` and enforce min_version. On a + /// `local` site, also warn when this host lacks `eb` or the module + /// tool EasyBuild uses. #[arg(long)] probe_tools: bool, /// Build list or easystack to pass to requested eb-stack checks. @@ -524,6 +526,16 @@ fn cmd_check( } } if probe { + for p in eb_pipeline::host::local_problems( + s, + &|k| std::env::var(k).ok(), + &eb_pipeline::host::on_path, + ) { + log("WARN", "check", &s.site.name, &p); + } + if let Some(p) = eb_pipeline::host::eb_problem(s) { + log("WARN", "check", &s.site.name, &p); + } tools::check_versions(s, true)?; } if !stack_checks.is_empty() {