Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
176 lines
5.8 KiB
Rust
176 lines
5.8 KiB
Rust
//! Static checks of the packaging recipes (no container engine needed): the OCI recipe keeps the model and
|
|
//! secrets out of the image, runs non-root with a health check, and the install script is valid POSIX sh.
|
|
use std::path::{Path, PathBuf};
|
|
|
|
fn repo() -> PathBuf {
|
|
Path::new(env!("CARGO_MANIFEST_DIR")).join("../..")
|
|
}
|
|
|
|
fn read(relative: &str) -> String {
|
|
std::fs::read_to_string(repo().join(relative)).unwrap_or_else(|e| panic!("{relative}: {e}"))
|
|
}
|
|
|
|
/// The instruction lines of a Containerfile (comments and blank lines removed, continuations joined).
|
|
fn instructions(text: &str) -> Vec<String> {
|
|
let mut out = Vec::new();
|
|
let mut current = String::new();
|
|
for line in text.lines() {
|
|
let line = line.trim_end();
|
|
if line.trim_start().starts_with('#') || line.trim().is_empty() {
|
|
continue;
|
|
}
|
|
if let Some(stripped) = line.strip_suffix('\\') {
|
|
current.push_str(stripped.trim_start());
|
|
current.push(' ');
|
|
} else {
|
|
current.push_str(line.trim_start());
|
|
out.push(std::mem::take(&mut current));
|
|
}
|
|
}
|
|
out
|
|
}
|
|
|
|
#[test]
|
|
fn the_oci_recipe_is_non_root_checked_and_model_free() {
|
|
let text = read("deploy/Containerfile.rust-runtime");
|
|
let lines = instructions(&text);
|
|
let find = |prefix: &str| {
|
|
lines
|
|
.iter()
|
|
.filter(|l| l.starts_with(prefix))
|
|
.cloned()
|
|
.collect::<Vec<_>>()
|
|
};
|
|
// Non-root, and the last USER wins.
|
|
assert_eq!(
|
|
find("USER ").last().map(String::as_str),
|
|
Some("USER 10001:10001")
|
|
);
|
|
// A health check that does not need a GPU probe.
|
|
let health = find("HEALTHCHECK").join(" ");
|
|
assert!(
|
|
health.contains("/opt/leleka/bin/leleka") && health.contains("status"),
|
|
"{health}"
|
|
);
|
|
// The model volume is external: declared, never copied.
|
|
assert!(find("VOLUME").join(" ").contains("/models"));
|
|
for copy in find("COPY").iter().chain(find("ADD").iter()) {
|
|
let lower = copy.to_ascii_lowercase();
|
|
for forbidden in [
|
|
".gguf",
|
|
".kar",
|
|
"mtp-rt",
|
|
"api-key",
|
|
"runtime.env",
|
|
"token",
|
|
"secret",
|
|
] {
|
|
assert!(
|
|
!lower.contains(forbidden),
|
|
"{copy} would bake {forbidden} into the image"
|
|
);
|
|
}
|
|
}
|
|
// Only the binaries, the cuBLAS libraries and the manifests are copied in.
|
|
let copies: Vec<String> = find("COPY");
|
|
assert!(copies.iter().any(|c| c.contains("bin/ /opt/leleka/bin/")));
|
|
assert!(copies.iter().any(|c| c.contains("--from=cublas")));
|
|
// The cuBLAS download is checksum-pinned.
|
|
assert!(
|
|
find("ADD")
|
|
.iter()
|
|
.any(|a| a.contains("--checksum=sha256:${CUBLAS_SHA256}"))
|
|
);
|
|
assert!(text.contains("546addc4a9d82b8f23aa9ba9274b6bc0429a63008a31c759884ac24880796057"));
|
|
// No secret-looking environment, no ssh keys, no package-manager network step in the runtime stage.
|
|
for env in find("ENV") {
|
|
assert!(
|
|
!env.to_ascii_uppercase().contains("TOKEN")
|
|
&& !env.to_ascii_uppercase().contains("KEY="),
|
|
"{env}"
|
|
);
|
|
}
|
|
assert_eq!(
|
|
find("ENTRYPOINT"),
|
|
vec![r#"ENTRYPOINT ["/opt/leleka/bin/leleka"]"#.to_string()]
|
|
);
|
|
assert!(find("CMD").join(" ").contains("--foreground"));
|
|
}
|
|
|
|
#[test]
|
|
fn the_cublas_pin_matches_the_tool_and_the_documentation() {
|
|
let recipe = read("deploy/Containerfile.rust-runtime");
|
|
let plan = read("crates/deploy/src/plan.rs");
|
|
for pinned in [
|
|
"546addc4a9d82b8f23aa9ba9274b6bc0429a63008a31c759884ac24880796057",
|
|
"libcublas-linux-x86_64-12.9.1.4-archive.tar.xz",
|
|
] {
|
|
assert!(
|
|
recipe.contains(pinned) && plan.contains(pinned),
|
|
"{pinned} differs between the recipe and plan.rs"
|
|
);
|
|
assert!(read("docs/rust-runtime-run.md").contains(pinned));
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn the_pinned_archive_digest_of_the_stamps_is_the_one_the_engine_pins() {
|
|
let engine = read("crates/leleka-runtime/src/model_binding/qwen4exp_kar_ple.rs");
|
|
assert!(
|
|
engine.contains(leleka_deploy::profile::ARCHIVE_SHA256_HEX),
|
|
"the archive digest the supervisor stamps differs from the engine's pin"
|
|
);
|
|
assert_eq!(leleka_deploy::profile::archive_sha256().len(), 32);
|
|
}
|
|
|
|
#[test]
|
|
fn the_shard_pins_of_the_preverification_are_the_engines() {
|
|
let backend = read("crates/leleka-runtime/src/backend.rs");
|
|
for digest in leleka_deploy::profile::SHARD_SHA256_HEX {
|
|
assert!(
|
|
backend.contains(&format!("sha256:{digest}")),
|
|
"{digest} is not pinned in backend.rs"
|
|
);
|
|
}
|
|
}
|
|
|
|
#[cfg(unix)]
|
|
#[test]
|
|
fn install_script_is_valid_sh_and_verifies_before_it_runs() {
|
|
let script = repo().join("deploy/rust-runtime/install.sh");
|
|
let status = std::process::Command::new("sh")
|
|
.arg("-n")
|
|
.arg(&script)
|
|
.status()
|
|
.unwrap();
|
|
assert!(status.success());
|
|
let text = read("deploy/rust-runtime/install.sh");
|
|
let verify = text
|
|
.find("sha256sum --quiet -c SHA256SUMS")
|
|
.expect("verifies the release");
|
|
let run = text
|
|
.find("exec ./bin/leleka up")
|
|
.expect("hands over to leleka up");
|
|
assert!(
|
|
verify < run,
|
|
"the checksum check must come before the hand-over"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn systemd_unit_templates_do_not_carry_secrets() {
|
|
for template in [
|
|
"leleka-daemon.service",
|
|
"leleka-inference.service",
|
|
"runtime.env.example",
|
|
] {
|
|
let text = read(&format!("deploy/rust-runtime/{template}"));
|
|
assert!(
|
|
!text
|
|
.lines()
|
|
.any(|l| l.trim_start().starts_with("Environment=") && l.contains("TOKEN")),
|
|
"{template}"
|
|
);
|
|
}
|
|
}
|