mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
config
This commit is contained in:
parent
67c2b59639
commit
56c574374e
5 changed files with 150 additions and 12 deletions
25
Cargo.lock
generated
25
Cargo.lock
generated
|
|
@ -120,6 +120,9 @@ name = "camino"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cd065703998b183ed0b348a22555691373a9345a1431141e5778b48bb17e4703"
|
checksum = "cd065703998b183ed0b348a22555691373a9345a1431141e5778b48bb17e4703"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
|
|
@ -218,6 +221,16 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "directories-next"
|
||||||
|
version = "1.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8a28ccebc1239c5c57f0c55986e2ac03f49af0d0ca3dff29bfcad39d60a8be56"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"dirs-sys-next",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dirs-next"
|
name = "dirs-next"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
|
|
@ -380,13 +393,16 @@ dependencies = [
|
||||||
"bollard",
|
"bollard",
|
||||||
"camino",
|
"camino",
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
|
"directories-next",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"maplit",
|
"maplit",
|
||||||
"min-id",
|
"min-id",
|
||||||
"opener",
|
"opener",
|
||||||
"parse-display",
|
"parse-display",
|
||||||
|
"serde",
|
||||||
"termion",
|
"termion",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -1117,6 +1133,15 @@ dependencies = [
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "toml"
|
||||||
|
version = "0.5.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower-service"
|
name = "tower-service"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,12 @@ bollard = { version = "0.10", git = "https://github.com/icewind1991/bollard", br
|
||||||
color-eyre = "0.5"
|
color-eyre = "0.5"
|
||||||
min-id = "0.1"
|
min-id = "0.1"
|
||||||
maplit = "1"
|
maplit = "1"
|
||||||
camino = "1"
|
camino = { version = "1", features = ["serde1"] }
|
||||||
tokio = { version = "1" , features = ["fs", "macros"] }
|
tokio = { version = "1" , features = ["fs", "macros"] }
|
||||||
parse-display = "0.4"
|
parse-display = "0.4"
|
||||||
futures-util = "0.3"
|
futures-util = "0.3"
|
||||||
termion = "1"
|
termion = "1"
|
||||||
opener = "0.4"
|
opener = "0.4"
|
||||||
|
toml = "0.5"
|
||||||
|
directories-next = "1"
|
||||||
|
serde = "1"
|
||||||
88
README.md
Normal file
88
README.md
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
# Haze
|
||||||
|
|
||||||
|
Hazy with a chance of clouds.
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
### Requirements
|
||||||
|
|
||||||
|
- Docker
|
||||||
|
|
||||||
|
### Config
|
||||||
|
|
||||||
|
Create a file `~/.config/haze/haze.toml` with the following options:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
sources_root = "/path/to/nextcloud/sources"
|
||||||
|
work_dir = "/path/to/temp/folder" # optional, defaults to /tmp/haze
|
||||||
|
```
|
||||||
|
|
||||||
|
## Managing instances
|
||||||
|
|
||||||
|
#### Start an instance
|
||||||
|
|
||||||
|
```bash
|
||||||
|
haze start [database]
|
||||||
|
```
|
||||||
|
|
||||||
|
Where database is one of `sqlite`, `mysql`, `mariadb` or `pgsql` with an option version (e.g. `pgsql:12`), defaults to `sqlite`.
|
||||||
|
|
||||||
|
### List running instances
|
||||||
|
|
||||||
|
```bash
|
||||||
|
haze
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
```bash
|
||||||
|
haze list
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Remove all running instances
|
||||||
|
|
||||||
|
```bash
|
||||||
|
haze clean
|
||||||
|
```
|
||||||
|
|
||||||
|
## Controlling running instances
|
||||||
|
|
||||||
|
The following commands run against the most recently started instance and allow optionally providing a `match` to select a specific instance by it's name.
|
||||||
|
|
||||||
|
#### Open an instance
|
||||||
|
|
||||||
|
```bash
|
||||||
|
haze [match] open
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Open the database of an instance
|
||||||
|
|
||||||
|
```bash
|
||||||
|
haze [match] db
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Execute a command on an instance
|
||||||
|
|
||||||
|
```bash
|
||||||
|
haze [match] exec [cmd]
|
||||||
|
```
|
||||||
|
|
||||||
|
If no `cmd` is specified it will launch `bash`
|
||||||
|
|
||||||
|
#### Execute an occ command on an instance
|
||||||
|
|
||||||
|
```bash
|
||||||
|
haze [match] occ [cmd]
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Show the logs of an instance
|
||||||
|
|
||||||
|
```bash
|
||||||
|
haze [match] logs
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Stop an instance
|
||||||
|
|
||||||
|
```bash
|
||||||
|
haze [match] stop
|
||||||
|
```
|
||||||
|
|
@ -1,6 +1,31 @@
|
||||||
use camino::Utf8PathBuf;
|
use camino::Utf8PathBuf;
|
||||||
|
use color_eyre::{eyre::WrapErr, Report, Result};
|
||||||
|
use directories_next::ProjectDirs;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::fs::read;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct HazeConfig {
|
pub struct HazeConfig {
|
||||||
pub sources_root: Utf8PathBuf,
|
pub sources_root: Utf8PathBuf,
|
||||||
|
#[serde(default = "default_work_dir")]
|
||||||
pub work_dir: Utf8PathBuf,
|
pub work_dir: Utf8PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_work_dir() -> Utf8PathBuf {
|
||||||
|
"/tmp/haze".into()
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HazeConfig {
|
||||||
|
pub fn load() -> Result<Self> {
|
||||||
|
let dirs = ProjectDirs::from("nl", "icewind", "haze").unwrap();
|
||||||
|
let file = dirs.config_dir().join("haze.toml");
|
||||||
|
if !file.exists() {
|
||||||
|
return Err(Report::msg(format!(
|
||||||
|
"Config file not setup: {}",
|
||||||
|
file.to_string_lossy()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
let content = read(&file).wrap_err("Failed to read config file")?;
|
||||||
|
toml::from_slice(&content).wrap_err("Failed to parse config file")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
17
src/main.rs
17
src/main.rs
|
|
@ -16,10 +16,7 @@ mod tty;
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let mut docker =
|
let mut docker =
|
||||||
Docker::connect_with_local_defaults().wrap_err("Failed to connect to docker")?;
|
Docker::connect_with_local_defaults().wrap_err("Failed to connect to docker")?;
|
||||||
let config = HazeConfig {
|
let config = HazeConfig::load().wrap_err("Failed to load config")?;
|
||||||
sources_root: "/srv/http/owncloud".into(),
|
|
||||||
work_dir: "/tmp/haze".into(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let args = HazeArgs::parse(std::env::args())?;
|
let args = HazeArgs::parse(std::env::args())?;
|
||||||
|
|
||||||
|
|
@ -66,18 +63,18 @@ async fn main() -> Result<()> {
|
||||||
println!("http://{}", cloud.ip.unwrap());
|
println!("http://{}", cloud.ip.unwrap());
|
||||||
}
|
}
|
||||||
HazeCommand::Stop => {
|
HazeCommand::Stop => {
|
||||||
let cloud = get_by_filter(&mut docker, None, &config).await?;
|
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||||
cloud.destroy(&mut docker).await?;
|
cloud.destroy(&mut docker).await?;
|
||||||
}
|
}
|
||||||
HazeCommand::Logs => {
|
HazeCommand::Logs => {
|
||||||
let cloud = get_by_filter(&mut docker, None, &config).await?;
|
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||||
let logs = cloud.logs(&mut docker).await?;
|
let logs = cloud.logs(&mut docker).await?;
|
||||||
for log in logs {
|
for log in logs {
|
||||||
print!("{}", log);
|
print!("{}", log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HazeCommand::Exec => {
|
HazeCommand::Exec => {
|
||||||
let cloud = get_by_filter(&mut docker, None, &config).await?;
|
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||||
cloud
|
cloud
|
||||||
.exec(
|
.exec(
|
||||||
&mut docker,
|
&mut docker,
|
||||||
|
|
@ -90,17 +87,17 @@ async fn main() -> Result<()> {
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
HazeCommand::Occ => {
|
HazeCommand::Occ => {
|
||||||
let cloud = get_by_filter(&mut docker, None, &config).await?;
|
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||||
let mut options = args.options;
|
let mut options = args.options;
|
||||||
options.insert(0, "occ".to_string());
|
options.insert(0, "occ".to_string());
|
||||||
cloud.exec(&mut docker, options).await?;
|
cloud.exec(&mut docker, options).await?;
|
||||||
}
|
}
|
||||||
HazeCommand::Db => {
|
HazeCommand::Db => {
|
||||||
let cloud = get_by_filter(&mut docker, None, &config).await?;
|
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||||
cloud.db.exec(&mut docker, &cloud.id).await?;
|
cloud.db.exec(&mut docker, &cloud.id).await?;
|
||||||
}
|
}
|
||||||
HazeCommand::Open => {
|
HazeCommand::Open => {
|
||||||
let cloud = get_by_filter(&mut docker, None, &config).await?;
|
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||||
match cloud.ip {
|
match cloud.ip {
|
||||||
Some(ip) => opener::open(format!("http://{}", ip))?,
|
Some(ip) => opener::open(format!("http://{}", ip))?,
|
||||||
None => eprintln!("{} is not running", cloud.id),
|
None => eprintln!("{} is not running", cloud.id),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue