stax/src/deploy.rs

46 lines
1.2 KiB
Rust

use argh::FromArgs;
use libstax::{compose, deno::ScriptRunner};
use std::path::PathBuf;
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "deploy")]
/// Dry run (print stacks to stdout)
pub(crate) struct Arguments {
/// script to run
#[argh(positional)]
script_path: String,
/// path to Typescript interpreter (Deno)
#[argh(option, default = "PathBuf::from(\"deno\")")]
interpreter_path: PathBuf,
/// path to docker binary
#[argh(option, default = "PathBuf::from(\"docker\")")]
docker_cli_path: PathBuf,
}
pub(crate) async fn deploy(args: Arguments) {
let runner = ScriptRunner::new(args.interpreter_path);
runner
.check_script(&args.script_path)
.await
.expect("Failed to check script");
let stacks = runner
.run_and_parse(&args.script_path)
.await
.expect("Failed to run script");
let compose = compose::ComposeRunner::new(args.docker_cli_path);
for (name, contents) in stacks {
println!("<> Deploying {} <>", name);
compose
.deploy_stack(&name, &contents)
.await
.expect("Failed to deploy stack");
}
}