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.
|
||||
Shell,
|
||||
|
||||
|
||||
/// Run Django's manage.py test.
|
||||
Test,
|
||||
}
|
||||
|
|
|
@ -5,12 +5,21 @@ use clap::Subcommand;
|
|||
/// Wraper for docker compose; autodiscover compose file and source .env file.
|
||||
#[derive(Subcommand, Debug)]
|
||||
pub enum DockerCompose {
|
||||
/// Start bash session inside container
|
||||
Bash,
|
||||
|
||||
/// Build containers.
|
||||
Build,
|
||||
|
||||
/// Down containers.
|
||||
Down,
|
||||
|
||||
/// Exec command inside container.
|
||||
Exec {
|
||||
#[arg(value_enum)]
|
||||
rest: Vec<String>,
|
||||
},
|
||||
|
||||
/// Stop, build and start containers.
|
||||
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)]
|
||||
pub struct CommandBuilder {
|
||||
args: Vec<String>,
|
||||
|
|
|
@ -26,8 +26,10 @@ fn main() -> Result<()> {
|
|||
cli::Docker::StopAll => scripts::docker::stop_all(),
|
||||
},
|
||||
cli::Commands::Compose { command } => match command {
|
||||
cli::DockerCompose::Bash => scripts::docker_compose::bash(),
|
||||
cli::DockerCompose::Build => scripts::docker_compose::build(),
|
||||
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::Restart => scripts::docker_compose::restart(),
|
||||
cli::DockerCompose::Start => scripts::docker_compose::start(None),
|
||||
|
|
|
@ -11,6 +11,13 @@ 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()
|
||||
}
|
||||
|
||||
/// Start containers via `docker compose start`. Optionally pass containers to be started.
|
||||
/// ```
|
||||
/// start(None);
|
||||
|
@ -31,6 +38,10 @@ pub fn up() -> Result<()> {
|
|||
}
|
||||
|
||||
// shortcuts
|
||||
pub fn bash() -> Result<()> {
|
||||
exec(&["bash".to_string()])
|
||||
}
|
||||
|
||||
pub fn rebuild() -> Result<()> {
|
||||
stop()?;
|
||||
build()?;
|
||||
|
|
Loading…
Reference in New Issue