feat: finish docker compose cli
Implemented basic wanted functionality for docker compose subcommands. We currently assume that docker-compose.yaml file is located in local/docker/ folder.
This commit is contained in:
@@ -5,6 +5,9 @@ use anyhow::Result;
|
||||
use clap::Parser;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// always load dotenv on start
|
||||
dotenvy::dotenv().ok();
|
||||
|
||||
let args = cli::Ahab::parse();
|
||||
|
||||
match args.command {
|
||||
|
@@ -1,21 +1,34 @@
|
||||
use super::DockerCommand;
|
||||
|
||||
// simple commands
|
||||
pub fn build() {
|
||||
todo!()
|
||||
DockerCommand::docker_compose().args("build").spawn_wait();
|
||||
}
|
||||
|
||||
pub fn down() {
|
||||
todo!()
|
||||
}
|
||||
pub fn rebuild() {
|
||||
todo!()
|
||||
}
|
||||
pub fn restart() {
|
||||
todo!()
|
||||
DockerCommand::docker_compose().args("down").spawn_wait();
|
||||
}
|
||||
|
||||
pub fn start() {
|
||||
todo!()
|
||||
DockerCommand::docker_compose().args("start").spawn_wait();
|
||||
}
|
||||
|
||||
pub fn stop() {
|
||||
todo!()
|
||||
DockerCommand::docker_compose().args("stop").spawn_wait();
|
||||
}
|
||||
|
||||
pub fn up() {
|
||||
todo!()
|
||||
DockerCommand::docker_compose().args("up -d").spawn_wait();
|
||||
}
|
||||
|
||||
// shortcuts
|
||||
pub fn rebuild() {
|
||||
stop();
|
||||
build();
|
||||
start();
|
||||
}
|
||||
|
||||
pub fn restart() {
|
||||
stop();
|
||||
start();
|
||||
}
|
||||
|
@@ -2,3 +2,44 @@ pub mod django;
|
||||
pub mod docker;
|
||||
pub mod docker_compose;
|
||||
pub mod postgres;
|
||||
|
||||
use std::{ffi::OsStr, process::Command};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
struct DockerCommand {
|
||||
command: Command,
|
||||
}
|
||||
|
||||
impl DockerCommand {
|
||||
fn new<T>(program: T) -> Self
|
||||
where
|
||||
T: AsRef<OsStr>,
|
||||
{
|
||||
DockerCommand {
|
||||
command: Command::new(program),
|
||||
}
|
||||
}
|
||||
|
||||
fn docker() -> Self {
|
||||
Self::new("docker")
|
||||
}
|
||||
|
||||
fn docker_compose() -> Self {
|
||||
Self::new("docker").args("compose -f docker/local/docker-compose.yaml")
|
||||
}
|
||||
|
||||
fn args(mut self, args: &str) -> Self {
|
||||
self.command.args(args.split_whitespace());
|
||||
self
|
||||
}
|
||||
|
||||
fn spawn_wait(mut self) -> Result<()> {
|
||||
self.command
|
||||
.spawn()
|
||||
.context("failed spawning command")?
|
||||
.wait()
|
||||
.context("failed while waiting")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user