MCPcopy Create free account
hub / github.com/codename-co/stack / run_stack

Function run_stack

packages/app/src-tauri/src/cli.rs:486–708  ·  view source on GitHub ↗

Runs a software stack from a stack bundle based on its flavor. # Arguments `name` - The name of the software stack. `path` - A reference to the path of the extracted bundle directory. `flavor` - The flavor of the software stack. `callback` - A function to receive progress updates.

(name: &str, path: &Path, flavor: Flavor, callback: impl Fn(String))

Source from the content-addressed store, hash-verified

484/// * `flavor` - The flavor of the software stack.
485/// * `callback` - A function to receive progress updates.
486fn run_stack(name: &str, path: &Path, flavor: Flavor, callback: impl Fn(String)) {
487 info!("Running flavor: {:?} in path: {:?}", flavor, path);
488
489 // Collect environment variables
490 let env_vars = get_docker_env_vars();
491
492 match flavor {
493 Flavor::DockerCompose => {
494 let mut cmd = Command::new("docker");
495 cmd.args([
496 "compose",
497 "--project-name",
498 &name,
499 "up",
500 "-d",
501 "--wait",
502 "--remove-orphans",
503 ])
504 .current_dir(path)
505 .envs(env_vars)
506 .stdout(std::process::Stdio::piped())
507 .stderr(std::process::Stdio::piped());
508 debug!("> {:?}", cmd);
509 callback(format!("Running command: {:?}", cmd));
510
511 match cmd.spawn() {
512 Ok(mut child) => {
513 let stdout = child.stdout.take().unwrap();
514 let stderr = child.stderr.take().unwrap();
515
516 // Stream stdout
517 let stdout_reader = std::io::BufReader::new(stdout);
518 for line in stdout_reader.lines() {
519 if let Ok(line) = line {
520 debug!("out: {}", line);
521 callback(format!("| {}", line));
522 }
523 }
524
525 // Stream stderr
526 let stderr_reader = std::io::BufReader::new(stderr);
527 for line in stderr_reader.lines() {
528 if let Ok(line) = line {
529 error!("err: {}", line);
530 callback(format!("| {}", line));
531 }
532 }
533
534 // Wait for completion
535 match child.wait() {
536 Ok(status) => {
537 if !status.success() {
538 error!("Docker compose failed with status: {}", status);
539 callback(format!("Docker compose failed with status: {}", status));
540 } else {
541 debug!("Docker compose completed successfully");
542 callback("Docker compose completed successfully".to_string());
543 }

Callers 2

runFunction · 0.85
run_with_callbackFunction · 0.85

Calls 1

get_docker_env_varsFunction · 0.85

Tested by

no test coverage detected