systemprompt_cli/shared/
docker.rs1use anyhow::{anyhow, Result};
2use std::io::Write;
3use std::path::Path;
4use std::process::Command;
5
6use super::process::run_command_in_dir;
7
8pub fn build_docker_image(context_dir: &Path, dockerfile: &Path, image: &str) -> Result<()> {
9 run_command_in_dir(
10 "docker",
11 &[
12 "build",
13 "--no-cache",
14 "-f",
15 &dockerfile.to_string_lossy(),
16 "-t",
17 image,
18 ".",
19 ],
20 &context_dir.to_path_buf(),
21 )
22}
23
24pub fn docker_login(registry: &str, username: &str, token: &str) -> Result<()> {
25 let mut command = Command::new("docker");
26 command.args(["login", registry, "-u", username, "--password-stdin"]);
27 command.stdin(std::process::Stdio::piped());
28
29 let mut child = command.spawn()?;
30 if let Some(mut stdin) = child.stdin.take() {
31 stdin.write_all(token.as_bytes())?;
32 }
33
34 let status = child.wait()?;
35 if !status.success() {
36 return Err(anyhow!("Docker login failed"));
37 }
38
39 Ok(())
40}
41
42pub fn docker_push(image: &str) -> Result<()> {
43 let status = Command::new("docker").args(["push", image]).status()?;
44
45 if !status.success() {
46 return Err(anyhow!("Docker push failed for image: {}", image));
47 }
48
49 Ok(())
50}