feat: let docker compose find its own file
This commit is contained in:
12
README.md
12
README.md
@@ -38,6 +38,17 @@ SHELL_COMPLETIONS_DIR_FISH=~/.config/fish/completions \
|
|||||||
|
|
||||||
`SHELL_COMPLETIONS_DIR` writes every shell into one directory instead.
|
`SHELL_COMPLETIONS_DIR` writes every shell into one directory instead.
|
||||||
|
|
||||||
|
## the compose file
|
||||||
|
|
||||||
|
`ahab` does not pass `-f`. docker compose finds the file itself, so set
|
||||||
|
docker's own `COMPOSE_FILE` when it is not in the working directory, including
|
||||||
|
its `base.yaml:override.yaml` form. A project's `.env` is a good place for it,
|
||||||
|
since docker reads that too:
|
||||||
|
|
||||||
|
```
|
||||||
|
COMPOSE_FILE=docker/docker-compose.yaml
|
||||||
|
```
|
||||||
|
|
||||||
## compose
|
## compose
|
||||||
|
|
||||||
Wrappers around the matching `docker compose` call, plus `exec` and `bash`
|
Wrappers around the matching `docker compose` call, plus `exec` and `bash`
|
||||||
@@ -89,7 +100,6 @@ from the git `origin` remote.
|
|||||||
|
|
||||||
Currently `ahab` respects the following environment variables.
|
Currently `ahab` respects the following environment variables.
|
||||||
|
|
||||||
- `COMPOSE_FILE`: control which docker-compose file is used - defaults to `docker/local/docker-compose.yaml`
|
|
||||||
- `AHAB_DJANGO_CONTAINER`: control which compose service is used for sending django commands - defaults to `django`
|
- `AHAB_DJANGO_CONTAINER`: control which compose service is used for sending django commands - defaults to `django`
|
||||||
- `AHAB_POSTGRES_CONTAINER`: control which compose service is used for sending postgres commands - defaults to `db`
|
- `AHAB_POSTGRES_CONTAINER`: control which compose service is used for sending postgres commands - defaults to `db`
|
||||||
- `AHAB_LINK_ROOT`: root of the out-of-repo store `ahab link` moves paths into - defaults to `${XDG_DATA_HOME:-$HOME/.local/share}/ahab`
|
- `AHAB_LINK_ROOT`: root of the out-of-repo store `ahab link` moves paths into - defaults to `${XDG_DATA_HOME:-$HOME/.local/share}/ahab`
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use std::{
|
use std::{
|
||||||
env,
|
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
process::{Child, Command, Stdio},
|
process::{Child, Command, Stdio},
|
||||||
};
|
};
|
||||||
@@ -27,11 +26,6 @@ impl From<&[String]> for Args {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_compose_file() -> Result<String> {
|
|
||||||
let cf = env::var("COMPOSE_FILE")?;
|
|
||||||
Ok(cf)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct CommandBuilder {
|
pub struct CommandBuilder {
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
@@ -49,9 +43,7 @@ impl CommandBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn docker_compose() -> Self {
|
pub fn docker_compose() -> Self {
|
||||||
let cf =
|
Self::default().args("docker compose")
|
||||||
get_compose_file().unwrap_or_else(|_| "docker/local/docker-compose.yaml".to_string());
|
|
||||||
Self::default().args("docker compose -f").args(&cf)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn args<T>(mut self, args: T) -> Self
|
pub fn args<T>(mut self, args: T) -> Self
|
||||||
|
|||||||
@@ -24,13 +24,6 @@ pub fn ps() -> Result<()> {
|
|||||||
CommandBuilder::docker_compose().args("ps").exec()
|
CommandBuilder::docker_compose().args("ps").exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start containers via `docker compose start`. Optionally pass containers to be started.
|
|
||||||
/// ```
|
|
||||||
/// # use ahab::scripts::docker_compose::start;
|
|
||||||
/// 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<()> {
|
pub fn start(containers: Option<&str>) -> Result<()> {
|
||||||
let args = format!("start {}", containers.unwrap_or(""));
|
let args = format!("start {}", containers.unwrap_or(""));
|
||||||
CommandBuilder::docker_compose().args(&args).exec()
|
CommandBuilder::docker_compose().args(&args).exec()
|
||||||
|
|||||||
Reference in New Issue
Block a user