use std::path::PathBuf;
pub const ARTIFACT_CATEGORIES: &[&str] = &["core", "agents", "benchmarks", "models", "gateways"];
pub const COMBINATION_BAKE_FILE: &str = "core/combination.docker-bake.hcl";
pub const ROOT_BAKE_FILE: &str = "docker-bake.hcl";
pub fn artifact_bake_files() -> Vec<PathBuf> {
let mut files: Vec<PathBuf> = vec![ROOT_BAKE_FILE.into(), COMBINATION_BAKE_FILE.into()];
for category in ARTIFACT_CATEGORIES {
let Ok(entries) = std::fs::read_dir(category) else {
continue;
};
for entry in entries.flatten() {
let p = entry.path().join("docker-bake.hcl");
if p.exists() {
files.push(p);
}
}
}
files
}
pub fn base_args(targets: &[&str], overrides: &[&str], builder: Option<&str>) -> Vec<String> {
let mut args: Vec<String> = vec!["buildx".into(), "bake".into()];
for f in artifact_bake_files() {
args.push("-f".into());
args.push(f.to_string_lossy().into_owned());
}
match builder {
Some(name) => {
args.push("--builder".into());
args.push(name.to_string());
args.push("--push".into());
}
None => args.push("--load".into()),
}
for o in overrides {
args.push("--set".into());
args.push((*o).to_string());
}
for t in targets {
args.push((*t).to_string());
}
args
}
pub fn artifact_dirs_with_dockerfile() -> Vec<PathBuf> {
let mut out = Vec::new();
for category in ARTIFACT_CATEGORIES {
let Ok(entries) = std::fs::read_dir(category) else {
continue;
};
for e in entries.flatten() {
let p = e.path();
if p.is_dir() && p.join("Dockerfile").exists() {
out.push(p);
}
}
}
out.sort();
out
}