ahab/src/scripts/docker_compose.rs

59 lines
1.3 KiB
Rust

use anyhow::Result;
use crate::command_builder::CommandBuilder;
// simple commands
pub fn build() -> Result<()> {
CommandBuilder::docker_compose().args("build").exec()
}
pub fn down() -> Result<()> {
CommandBuilder::docker_compose().args("down").exec()
}
pub fn exec(rest: &[String]) -> Result<()> {
CommandBuilder::docker_compose()
.args("exec appserver")
.args(rest)
.exec()
}
pub fn ps() -> Result<()> {
CommandBuilder::docker_compose().args("ps").exec()
}
/// Start containers via `docker compose start`. Optionally pass containers to be started.
/// ```
/// start(None);
/// ```
/// is roughly the same as
/// `docker compose --env-file ./.env -f docker/local/docker-compose.yaml up start`
pub fn start(containers: Option<&str>) -> Result<()> {
let args = format!("start {}", containers.unwrap_or(""));
CommandBuilder::docker_compose().args(&args).exec()
}
pub fn stop() -> Result<()> {
CommandBuilder::docker_compose().args("stop").exec()
}
pub fn up() -> Result<()> {
CommandBuilder::docker_compose().args("up -d").exec()
}
// shortcuts
pub fn bash() -> Result<()> {
exec(&["bash".to_string()])
}
pub fn rebuild() -> Result<()> {
stop()?;
build()?;
up()
}
pub fn restart() -> Result<()> {
stop()?;
up()
}