1use std::process::{Command, ExitStatus, Output, Stdio};
4
5pub fn has_docker() -> bool {
7 Command::new("docker")
8 .arg("info")
9 .stdout(Stdio::null())
10 .stderr(Stdio::null())
11 .status()
12 .is_ok_and(|s| s.success())
13}
14
15#[allow(dead_code)]
17pub fn image_exists(name: &str) -> bool {
18 Command::new("docker")
19 .args(["image", "inspect", name])
20 .stdout(Stdio::null())
21 .stderr(Stdio::null())
22 .status()
23 .is_ok_and(|s| s.success())
24}
25
26#[allow(dead_code)]
30pub fn compose_run(compose_dir: &str, args: &[&str]) -> Result<ExitStatus, String> {
31 Command::new("docker")
32 .arg("compose")
33 .args(args)
34 .current_dir(compose_dir)
35 .stdout(Stdio::inherit())
36 .stderr(Stdio::inherit())
37 .status()
38 .map_err(|e| format!("failed to run docker compose: {}", e))
39}
40
41#[allow(dead_code)]
43pub fn compose_output(compose_dir: &str, args: &[&str]) -> Result<Output, String> {
44 Command::new("docker")
45 .arg("compose")
46 .args(args)
47 .current_dir(compose_dir)
48 .output()
49 .map_err(|e| format!("failed to run docker compose: {}", e))
50}
51
52pub fn docker_output(args: &[&str]) -> Result<Output, String> {
54 Command::new("docker")
55 .args(args)
56 .output()
57 .map_err(|e| format!("failed to run docker: {}", e))
58}
59
60pub fn docker_run(args: &[&str]) -> Result<ExitStatus, String> {
62 Command::new("docker")
63 .args(args)
64 .stdout(Stdio::inherit())
65 .stderr(Stdio::inherit())
66 .status()
67 .map_err(|e| format!("failed to run docker: {}", e))
68}