feat: add compose exec and compose bash commands
Exec is new command scoped under compose. It allows sending commands directly into appserver container. I will make this customizable/controllable in the future.
This commit is contained in:
parent
7bf76d3ff2
commit
b45cfd3e0a
|
@ -31,7 +31,7 @@ pub enum Django {
|
||||||
|
|
||||||
/// Run Django's manage.py shell.
|
/// Run Django's manage.py shell.
|
||||||
Shell,
|
Shell,
|
||||||
|
|
||||||
/// Run Django's manage.py test.
|
/// Run Django's manage.py test.
|
||||||
Test,
|
Test,
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,21 @@ use clap::Subcommand;
|
||||||
/// Wraper for docker compose; autodiscover compose file and source .env file.
|
/// Wraper for docker compose; autodiscover compose file and source .env file.
|
||||||
#[derive(Subcommand, Debug)]
|
#[derive(Subcommand, Debug)]
|
||||||
pub enum DockerCompose {
|
pub enum DockerCompose {
|
||||||
|
/// Start bash session inside container
|
||||||
|
Bash,
|
||||||
|
|
||||||
/// Build containers.
|
/// Build containers.
|
||||||
Build,
|
Build,
|
||||||
|
|
||||||
/// Down containers.
|
/// Down containers.
|
||||||
Down,
|
Down,
|
||||||
|
|
||||||
|
/// Exec command inside container.
|
||||||
|
Exec {
|
||||||
|
#[arg(value_enum)]
|
||||||
|
rest: Vec<String>,
|
||||||
|
},
|
||||||
|
|
||||||
/// Stop, build and start containers.
|
/// Stop, build and start containers.
|
||||||
Rebuild,
|
Rebuild,
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,12 @@ impl From<&String> for Args {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<&[String]> for Args {
|
||||||
|
fn from(value: &[String]) -> Self {
|
||||||
|
Self(Vec::from_iter(value.iter().map(|x| x.to_string())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct CommandBuilder {
|
pub struct CommandBuilder {
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
|
|
|
@ -26,8 +26,10 @@ fn main() -> Result<()> {
|
||||||
cli::Docker::StopAll => scripts::docker::stop_all(),
|
cli::Docker::StopAll => scripts::docker::stop_all(),
|
||||||
},
|
},
|
||||||
cli::Commands::Compose { command } => match command {
|
cli::Commands::Compose { command } => match command {
|
||||||
|
cli::DockerCompose::Bash => scripts::docker_compose::bash(),
|
||||||
cli::DockerCompose::Build => scripts::docker_compose::build(),
|
cli::DockerCompose::Build => scripts::docker_compose::build(),
|
||||||
cli::DockerCompose::Down => scripts::docker_compose::down(),
|
cli::DockerCompose::Down => scripts::docker_compose::down(),
|
||||||
|
cli::DockerCompose::Exec { rest } => scripts::docker_compose::exec(&rest),
|
||||||
cli::DockerCompose::Rebuild => scripts::docker_compose::rebuild(),
|
cli::DockerCompose::Rebuild => scripts::docker_compose::rebuild(),
|
||||||
cli::DockerCompose::Restart => scripts::docker_compose::restart(),
|
cli::DockerCompose::Restart => scripts::docker_compose::restart(),
|
||||||
cli::DockerCompose::Start => scripts::docker_compose::start(None),
|
cli::DockerCompose::Start => scripts::docker_compose::start(None),
|
||||||
|
|
|
@ -11,6 +11,13 @@ pub fn down() -> Result<()> {
|
||||||
CommandBuilder::docker_compose().args("down").exec()
|
CommandBuilder::docker_compose().args("down").exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn exec(rest: &[String]) -> Result<()> {
|
||||||
|
CommandBuilder::docker_compose()
|
||||||
|
.args("exec appserver")
|
||||||
|
.args(rest)
|
||||||
|
.exec()
|
||||||
|
}
|
||||||
|
|
||||||
/// Start containers via `docker compose start`. Optionally pass containers to be started.
|
/// Start containers via `docker compose start`. Optionally pass containers to be started.
|
||||||
/// ```
|
/// ```
|
||||||
/// start(None);
|
/// start(None);
|
||||||
|
@ -31,6 +38,10 @@ pub fn up() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// shortcuts
|
// shortcuts
|
||||||
|
pub fn bash() -> Result<()> {
|
||||||
|
exec(&["bash".to_string()])
|
||||||
|
}
|
||||||
|
|
||||||
pub fn rebuild() -> Result<()> {
|
pub fn rebuild() -> Result<()> {
|
||||||
stop()?;
|
stop()?;
|
||||||
build()?;
|
build()?;
|
||||||
|
|
Loading…
Reference in New Issue