1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-10-01 08:44:09 +02:00

feat(start): Add --detach flag

This will create a dedicated worktree for the instance.

App listed to be enabled will also benefit from their own worktrees.

The worktree is cleanup when the instance is destroyed.
This commit is contained in:
Louis Chmn 2026-08-13 19:32:23 +02:00
commit 0e702f7b87
9 changed files with 339 additions and 27 deletions

View file

@ -5,7 +5,7 @@ use crate::cloud::{Cloud, CloudOptions};
use crate::config::HazeConfig;
use crate::database::DatabaseFamily;
use crate::exec::{container_logs, exec, exec_tty};
use crate::git::{checkout_all, pull_all};
use crate::git::{checkout_all, prune_worktrees, pull_all};
use crate::help::help;
use crate::image::update_image;
use crate::network::clear_networks;
@ -79,7 +79,7 @@ async fn main() -> Result<ExitCode> {
}
for cloud in remove {
if let Err(e) = cloud.destroy(&docker).await {
if let Err(e) = cloud.destroy(&docker, &config).await {
eprintln!("Error while removing cloud: {:#}", e);
}
}
@ -91,6 +91,11 @@ async fn main() -> Result<ExitCode> {
if let Some(id) = cache_dir.file_name().to_str() {
if !retain.iter().any(|cloud| cloud.id == id) {
let path = cache_dir.path();
// By default, the worktrees live within the work dir, we do not want to delete it here.
if path == config.worktree_dir {
continue;
}
if path.is_dir() {
remove_dir_all(&path).into_diagnostic().wrap_err_with(|| {
format!("Failed to cleanup stray cache dir: {}", path.display())
@ -103,6 +108,8 @@ async fn main() -> Result<ExitCode> {
}
}
}
prune_worktrees(&config)?;
}
HazeArgs::List { filter } => {
let list = Cloud::list(&docker, filter, &config).await?;
@ -119,13 +126,19 @@ async fn main() -> Result<ExitCode> {
Some(version) => format!(", v{version}"),
None => String::new(),
};
let detached = if cloud.options.detach {
", detached"
} else {
""
};
println!(
"Cloud {}{}, {}, {}{}, running on {}",
"Cloud {}{}, {}, {}{}{}, running on {}",
cloud.id,
pin,
cloud.php().name(),
services,
version,
detached,
cloud.address,
);
}
@ -135,7 +148,7 @@ async fn main() -> Result<ExitCode> {
}
HazeArgs::Stop { filter } => {
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
cloud.destroy(&docker).await?;
cloud.destroy(&docker, &config).await?;
}
HazeArgs::Logs {
filter,
@ -290,7 +303,7 @@ async fn main() -> Result<ExitCode> {
)
.await
{
cloud.destroy(&docker).await?;
cloud.destroy(&docker, &config).await?;
return Err(e);
}
if let Some(app) = args
@ -307,7 +320,7 @@ async fn main() -> Result<ExitCode> {
}
args.insert(0, "tests".to_string());
let result = cloud.exec(&docker, args, false, get_forward_env()).await?;
cloud.destroy(&docker).await?;
cloud.destroy(&docker, &config).await?;
return Ok(result.into());
}
HazeArgs::Integration { options, mut args } => {
@ -315,7 +328,7 @@ async fn main() -> Result<ExitCode> {
args.insert(0, "integration".to_string());
cloud.exec(&docker, args, false, get_forward_env()).await?;
cloud.destroy(&docker).await?;
cloud.destroy(&docker, &config).await?;
}
HazeArgs::Fmt { path } => {
let cloud = Cloud::create(&docker, CloudOptions::new(&config), &config).await?;
@ -334,7 +347,7 @@ async fn main() -> Result<ExitCode> {
.and_then(|c| c.to_result())
{
eprintln!("{}", String::from_utf8_lossy(&out_buffer));
cloud.destroy(&docker).await?;
cloud.destroy(&docker, &config).await?;
return Err(e);
}
out_buffer.clear();
@ -348,7 +361,7 @@ async fn main() -> Result<ExitCode> {
)
.await
{
cloud.destroy(&docker).await?;
cloud.destroy(&docker, &config).await?;
return Err(e);
}
println!("Cleanup");
@ -363,7 +376,7 @@ async fn main() -> Result<ExitCode> {
.and_then(|c| c.to_result())
{
eprintln!("{}", String::from_utf8_lossy(&out_buffer));
cloud.destroy(&docker).await?;
cloud.destroy(&docker, &config).await?;
return Err(e);
}
if let Err(e) = cloud
@ -377,10 +390,10 @@ async fn main() -> Result<ExitCode> {
.and_then(|c| c.to_result())
{
eprintln!("{}", String::from_utf8_lossy(&out_buffer));
cloud.destroy(&docker).await?;
cloud.destroy(&docker, &config).await?;
return Err(e);
}
cloud.destroy(&docker).await?;
cloud.destroy(&docker, &config).await?;
}
HazeArgs::Shell { command, options } => {
let cloud = setup(&docker, options, &config).await?;
@ -396,7 +409,7 @@ async fn main() -> Result<ExitCode> {
get_forward_env(),
)
.await?;
cloud.destroy(&docker).await?;
cloud.destroy(&docker, &config).await?;
}
HazeArgs::Pin { filter } => {
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;