Build's podman calls always talk to the systemd user bus (crun needs it for cgroups
Browse files at this commitccf421a9d8856d8d2b1b65072c7ba43c1ba8311dParent: 962f0fa- fix
- Build's podman calls always talk to the systemd user bus (crun needs it for cgroups
- a foreign DBUS_SESSION_BUS_ADDRESS made container start fail), and a failed command reports its last stderr line instead of the first (pull progress hid the real error)
1 changed file +27 -9
- crates/client/src/release.rs +27 -9
crates/client/src/release.rsmodified+27 -9
| @@ -218,7 +218,7 @@ fn preflight(source: &Path) -> Result<bool, String> { | |||
| 218 | } | 218 | } |
| 219 | 219 | ||
| 220 | fn container_running(container: &str) -> bool { | 220 | fn container_running(container: &str) -> bool { |
| 221 | - Command::new("podman") | 221 | + podman() |
| 222 | .args(["inspect", "-f", "{{.State.Running}}", container]) | 222 | .args(["inspect", "-f", "{{.State.Running}}", container]) |
| 223 | .output() | 223 | .output() |
| 224 | .is_ok_and(|out| String::from_utf8_lossy(&out.stdout).trim() == "true") | 224 | .is_ok_and(|out| String::from_utf8_lossy(&out.stdout).trim() == "true") |
| @@ -308,7 +308,7 @@ fn host_rust() -> Result<String, String> { | |||
| 308 | } | 308 | } |
| 309 | 309 | ||
| 310 | fn in_linux(script: &str) -> Command { | 310 | fn in_linux(script: &str) -> Command { |
| 311 | - let mut cmd = Command::new("podman"); | 311 | + let mut cmd = podman(); |
| 312 | cmd.args(["exec", "-w", "/build"]) | 312 | cmd.args(["exec", "-w", "/build"]) |
| 313 | .args(["-e", "PATH=/root/.cargo/bin:/usr/local/bin:/usr/bin:/bin"]) | 313 | .args(["-e", "PATH=/root/.cargo/bin:/usr/local/bin:/usr/bin:/bin"]) |
| 314 | .args(["-e", "DEBIAN_FRONTEND=noninteractive"]) | 314 | .args(["-e", "DEBIAN_FRONTEND=noninteractive"]) |
| @@ -329,7 +329,7 @@ fn start_linux(job: Job, source: &Path, cx: &Cx) -> Result<(), String> { | |||
| 329 | cx.send(Event::Line(job, "creating container".into())); | 329 | cx.send(Event::Line(job, "creating container".into())); |
| 330 | let mount = |dir: &str, at: &str| format!("{}:{at}:Z", cache.join(dir).display()); | 330 | let mount = |dir: &str, at: &str| format!("{}:{at}:Z", cache.join(dir).display()); |
| 331 | check( | 331 | check( |
| 332 | - Command::new("podman") | 332 | + podman() |
| 333 | .args(["run", "-d", "--name", LINUX]) | 333 | .args(["run", "-d", "--name", LINUX]) |
| 334 | .args(["-v", &mount("cargo", "/root/.cargo")]) | 334 | .args(["-v", &mount("cargo", "/root/.cargo")]) |
| 335 | .args(["-v", &mount("rustup", "/root/.rustup")]) | 335 | .args(["-v", &mount("rustup", "/root/.rustup")]) |
| @@ -337,10 +337,10 @@ fn start_linux(job: Job, source: &Path, cx: &Cx) -> Result<(), String> { | |||
| 337 | .args([LINUX_IMAGE, "sleep", "infinity"]), | 337 | .args([LINUX_IMAGE, "sleep", "infinity"]), |
| 338 | )?; | 338 | )?; |
| 339 | } else { | 339 | } else { |
| 340 | - check(Command::new("podman").args(["start", LINUX]))?; | 340 | + check(podman().args(["start", LINUX]))?; |
| 341 | } | 341 | } |
| 342 | check( | 342 | check( |
| 343 | - Command::new("podman") | 343 | + podman() |
| 344 | .arg("cp") | 344 | .arg("cp") |
| 345 | .arg(source.join(ARCHIVE)) | 345 | .arg(source.join(ARCHIVE)) |
| 346 | .arg(format!("{LINUX}:/build/src.tgz")), | 346 | .arg(format!("{LINUX}:/build/src.tgz")), |
| @@ -433,7 +433,7 @@ fn create_windows(job: Job, key: &Path, cx: &Cx) -> Result<(), String> { | |||
| 433 | let mount = |sub: &str| format!("{}:/{sub}:Z", dir.join(sub).display()); | 433 | let mount = |sub: &str| format!("{}:/{sub}:Z", dir.join(sub).display()); |
| 434 | cx.send(Event::Line(job, "creating Windows VM".into())); | 434 | cx.send(Event::Line(job, "creating Windows VM".into())); |
| 435 | check( | 435 | check( |
| 436 | - Command::new("podman") | 436 | + podman() |
| 437 | .args(["run", "-d", "--name", VM]) | 437 | .args(["run", "-d", "--name", VM]) |
| 438 | .args([ | 438 | .args([ |
| 439 | "-e", | 439 | "-e", |
| @@ -479,7 +479,7 @@ fn start_windows(job: Job, source: &Path, key: &Path, cx: &Cx) -> Result<(), Str | |||
| 479 | if !podman_ok(&["container", "exists", VM]) { | 479 | if !podman_ok(&["container", "exists", VM]) { |
| 480 | create_windows(job, key, cx)?; | 480 | create_windows(job, key, cx)?; |
| 481 | } else if !container_running(VM) { | 481 | } else if !container_running(VM) { |
| 482 | - check(Command::new("podman").args(["start", VM]))?; | 482 | + check(podman().args(["start", VM]))?; |
| 483 | } | 483 | } |
| 484 | wait_ssh(job, key, cx)?; | 484 | wait_ssh(job, key, cx)?; |
| 485 | while !ssh_ok_with( | 485 | while !ssh_ok_with( |
| @@ -611,8 +611,19 @@ fn ssh_ok_with(key: &Path, command: &str) -> bool { | |||
| 611 | .is_ok_and(|s| s.success()) | 611 | .is_ok_and(|s| s.success()) |
| 612 | } | 612 | } |
| 613 | 613 | ||
| 614 | +fn podman() -> Command { | ||
| 615 | + let mut cmd = Command::new("podman"); | ||
| 616 | + if let Some(runtime) = std::env::var_os("XDG_RUNTIME_DIR") { | ||
| 617 | + let mut bus = std::ffi::OsString::from("unix:path="); | ||
| 618 | + bus.push(runtime); | ||
| 619 | + bus.push("/bus"); | ||
| 620 | + cmd.env("DBUS_SESSION_BUS_ADDRESS", bus); | ||
| 621 | + } | ||
| 622 | + cmd | ||
| 623 | +} | ||
| 624 | + | ||
| 614 | fn podman_ok(args: &[&str]) -> bool { | 625 | fn podman_ok(args: &[&str]) -> bool { |
| 615 | - Command::new("podman") | 626 | + podman() |
| 616 | .args(args) | 627 | .args(args) |
| 617 | .stdout(Stdio::null()) | 628 | .stdout(Stdio::null()) |
| 618 | .stderr(Stdio::null()) | 629 | .stderr(Stdio::null()) |
| @@ -625,7 +636,14 @@ fn check(cmd: &mut Command) -> Result<(), String> { | |||
| 625 | if out.status.success() { | 636 | if out.status.success() { |
| 626 | Ok(()) | 637 | Ok(()) |
| 627 | } else { | 638 | } else { |
| 628 | - Err(String::from_utf8_lossy(&out.stderr).trim().to_string()) | 639 | + let stderr = String::from_utf8_lossy(&out.stderr); |
| 640 | + Err(stderr | ||
| 641 | + .lines() | ||
| 642 | + .rev() | ||
| 643 | + .find(|line| !line.trim().is_empty()) | ||
| 644 | + .unwrap_or_default() | ||
| 645 | + .trim() | ||
| 646 | + .to_string()) | ||
| 629 | } | 647 | } |
| 630 | } | 648 | } |
| 631 | 649 | ||