Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
63d04a9393
|
|||
|
f92227a679
|
|||
|
27a1ec6d2c
|
|||
|
1b1f9a31ed
|
|||
|
e5eddb39f7
|
|||
|
2000204250
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -4,7 +4,7 @@ version = 4
|
||||
|
||||
[[package]]
|
||||
name = "ahab"
|
||||
version = "0.3.2"
|
||||
version = "0.4.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name = "ahab"
|
||||
description = "docker cli wrapper"
|
||||
readme = "README.md"
|
||||
version = "0.3.2"
|
||||
version = "0.4.2"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
authors = ["Matej Janežič <janezic.mj@gmail.com>"]
|
||||
|
||||
@@ -21,5 +21,5 @@ Completion files are generated **during build process** in `target/*/build/*/out
|
||||
Currently `ahab` respects three 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 `appserver`
|
||||
- `AHAB_POSTGRES_CONTAINER`: control which compose service is used for sending postgres commands - defaults to `postgresdb`
|
||||
- `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`
|
||||
|
||||
10
build.rs
10
build.rs
@@ -5,15 +5,17 @@ use std::{env, io::Error};
|
||||
include!("src/cli/mod.rs");
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
let outdir = match env::var_os("OUT_DIR") {
|
||||
None => return Ok(()),
|
||||
Some(outdir) => outdir,
|
||||
let outdir = env::var_os("SHELL_COMPLETIONS_DIR")
|
||||
.or_else(|| env::var_os("OUT_DIR"));
|
||||
|
||||
let Some(outdir) = outdir else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let mut cmd = ahab::Ahab::command();
|
||||
|
||||
for shell in Shell::value_variants() {
|
||||
let path = generate_to(*shell, &mut cmd, "ahab", &outdir)?;
|
||||
let path = generate_to(*shell, &mut cmd, env!("CARGO_PKG_NAME"), &outdir)?;
|
||||
|
||||
println!("cargo:warning=completion file is generated: {path:?}");
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ pub enum DockerCompose {
|
||||
rest: Vec<String>,
|
||||
},
|
||||
|
||||
/// Print services
|
||||
/// Print services
|
||||
Ps,
|
||||
|
||||
/// Stop, build and start containers.
|
||||
|
||||
@@ -34,8 +34,7 @@ fn main() -> Result<()> {
|
||||
cli::Django::Test => scripts::django::test(),
|
||||
},
|
||||
cli::Commands::Postgres { command } => {
|
||||
let db_container =
|
||||
std::env::var("AHAB_POSTGRES_CONTAINER").unwrap_or("postgresdb".to_string());
|
||||
let db_container = std::env::var("AHAB_POSTGRES_CONTAINER").unwrap_or("db".to_string());
|
||||
match command {
|
||||
cli::Postgres::Import { path } => scripts::postgres::import(&db_container, &path),
|
||||
cli::Postgres::Dump { path } => scripts::postgres::dump(&db_container, &path),
|
||||
|
||||
@@ -55,7 +55,7 @@ pub fn make_command(app: &PathBuf, name: &str) -> Result<()> {
|
||||
}
|
||||
|
||||
pub fn manage(rest: &[String]) -> Result<()> {
|
||||
let container = env::var("AHAB_DJANGO_CONTAINER").unwrap_or("appserver".to_string());
|
||||
let container = env::var("AHAB_DJANGO_CONTAINER").unwrap_or("django".to_string());
|
||||
let joined = rest.join(" ");
|
||||
let command = format!("run --rm {container} python manage.py {joined}");
|
||||
CommandBuilder::docker_compose().args(&command).exec()
|
||||
|
||||
@@ -12,7 +12,7 @@ pub fn down() -> Result<()> {
|
||||
}
|
||||
|
||||
pub fn exec(rest: &[String]) -> Result<()> {
|
||||
let container = std::env::var("AHAB_DJANGO_CONTAINER").unwrap_or("appserver".to_string());
|
||||
let container = std::env::var("AHAB_DJANGO_CONTAINER").unwrap_or("django".to_string());
|
||||
CommandBuilder::docker_compose()
|
||||
.args("exec")
|
||||
.args(&container)
|
||||
|
||||
@@ -48,7 +48,7 @@ pub fn import(container: &str, file: &Path) -> Result<()> {
|
||||
|
||||
eprintln!("restoring database");
|
||||
let commands = [
|
||||
format!("cp {dump_file} {db_container}:/tmp/dbdump"),
|
||||
format!("cp -L {dump_file} {db_container}:/tmp/dbdump"),
|
||||
format!("exec {db_container} dropdb -U db db"),
|
||||
format!("exec {db_container} createdb -U db -E utf8 -T template0 db"),
|
||||
format!("exec {db_container} pg_restore -U db --dbname=db /tmp/dbdump"),
|
||||
|
||||
Reference in New Issue
Block a user