Compare commits
7 Commits
f7737ea00d
...
v0.4.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
e5eddb39f7
|
|||
|
2000204250
|
|||
|
7912e9a516
|
|||
|
568d126fc2
|
|||
|
3ce4cbfad7
|
|||
|
36fcc84881
|
|||
|
c8b3a817f0
|
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -1,10 +1,10 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ahab"
|
name = "ahab"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
name = "ahab"
|
name = "ahab"
|
||||||
description = "docker cli wrapper"
|
description = "docker cli wrapper"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Matej Janežič <janezic.mj@gmail.com>"]
|
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.
|
Currently `ahab` respects three environment variables.
|
||||||
|
|
||||||
- `COMPOSE_FILE`: control which docker-compose file is used - defaults to `docker/local/docker-compose.yaml`
|
- `COMPOSE_FILE`: control which docker-compose file is used - defaults to `docker/local/docker-compose.yaml`
|
||||||
- `AHAB_POSTGRES_CONATINER`: 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_CONATINER`: 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 `db`
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub enum DockerCompose {
|
|||||||
rest: Vec<String>,
|
rest: Vec<String>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Print services
|
/// Print services
|
||||||
Ps,
|
Ps,
|
||||||
|
|
||||||
/// Stop, build and start containers.
|
/// Stop, build and start containers.
|
||||||
|
|||||||
@@ -7,9 +7,6 @@ fn main() -> Result<()> {
|
|||||||
// always load dotenv on start
|
// always load dotenv on start
|
||||||
dotenvy::dotenv().ok();
|
dotenvy::dotenv().ok();
|
||||||
|
|
||||||
// TODO: (matej) some prints about project
|
|
||||||
// eg: DJANGO_SETTINGS_MODULE for django projects, used docker-compose, etc.
|
|
||||||
|
|
||||||
let args = cli::Ahab::parse();
|
let args = cli::Ahab::parse();
|
||||||
|
|
||||||
match args.command {
|
match args.command {
|
||||||
@@ -37,8 +34,7 @@ fn main() -> Result<()> {
|
|||||||
cli::Django::Test => scripts::django::test(),
|
cli::Django::Test => scripts::django::test(),
|
||||||
},
|
},
|
||||||
cli::Commands::Postgres { command } => {
|
cli::Commands::Postgres { command } => {
|
||||||
let db_container =
|
let db_container = std::env::var("AHAB_POSTGRES_CONTAINER").unwrap_or("db".to_string());
|
||||||
std::env::var("AHAB_POSTGRES_CONTAINER").unwrap_or("postgresdb".to_string());
|
|
||||||
match command {
|
match command {
|
||||||
cli::Postgres::Import { path } => scripts::postgres::import(&db_container, &path),
|
cli::Postgres::Import { path } => scripts::postgres::import(&db_container, &path),
|
||||||
cli::Postgres::Dump { path } => scripts::postgres::dump(&db_container, &path),
|
cli::Postgres::Dump { path } => scripts::postgres::dump(&db_container, &path),
|
||||||
|
|||||||
@@ -8,13 +8,6 @@ use anyhow::{anyhow, Result};
|
|||||||
use crate::command_builder::CommandBuilder;
|
use crate::command_builder::CommandBuilder;
|
||||||
use crate::{create_file, safe_create_file};
|
use crate::{create_file, safe_create_file};
|
||||||
|
|
||||||
fn get_django_settings_module() -> Result<String> {
|
|
||||||
let dsm = env::var("DJANGO_SETTINGS_MODULE")?;
|
|
||||||
eprintln!("USING: {dsm}");
|
|
||||||
|
|
||||||
Ok(dsm)
|
|
||||||
}
|
|
||||||
|
|
||||||
const DEBUG_TEMPLATE: &str = r#"from django.core.management.base import BaseCommand
|
const DEBUG_TEMPLATE: &str = r#"from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
@@ -62,10 +55,9 @@ pub fn make_command(app: &PathBuf, name: &str) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn manage(rest: &[String]) -> Result<()> {
|
pub fn manage(rest: &[String]) -> Result<()> {
|
||||||
let dsm = get_django_settings_module()?;
|
let container = env::var("AHAB_DJANGO_CONTAINER").unwrap_or("django".to_string());
|
||||||
let container = env::var("AHAB_DJANGO_CONTAINER").unwrap_or("appserver".to_string());
|
|
||||||
let joined = rest.join(" ");
|
let joined = rest.join(" ");
|
||||||
let command = format!("run --rm {container} python manage.py {joined} --settings={dsm}");
|
let command = format!("run --rm {container} python manage.py {joined}");
|
||||||
CommandBuilder::docker_compose().args(&command).exec()
|
CommandBuilder::docker_compose().args(&command).exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ pub fn down() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn exec(rest: &[String]) -> 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()
|
CommandBuilder::docker_compose()
|
||||||
.args("exec")
|
.args("exec")
|
||||||
.args(&container)
|
.args(&container)
|
||||||
@@ -26,6 +26,7 @@ pub fn ps() -> Result<()> {
|
|||||||
|
|
||||||
/// Start containers via `docker compose start`. Optionally pass containers to be started.
|
/// Start containers via `docker compose start`. Optionally pass containers to be started.
|
||||||
/// ```
|
/// ```
|
||||||
|
/// # use ahab::scripts::docker_compose::start;
|
||||||
/// start(None);
|
/// start(None);
|
||||||
/// ```
|
/// ```
|
||||||
/// is roughly the same as
|
/// is roughly the same as
|
||||||
|
|||||||
Reference in New Issue
Block a user