mirror of
https://codeberg.org/icewind/haze.git
synced 2026-10-01 16:54:08 +02:00
allow exec'ing service containers
This commit is contained in:
parent
fc6cde4161
commit
d138740bbd
7 changed files with 74 additions and 16 deletions
55
src/main.rs
55
src/main.rs
|
|
@ -148,6 +148,9 @@ async fn main() -> Result<ExitCode> {
|
|||
root,
|
||||
} => {
|
||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||
let env = get_forward_env();
|
||||
let tty = atty::is(atty::Stream::Stdout);
|
||||
|
||||
match service {
|
||||
None => {
|
||||
let command = if command.is_empty() {
|
||||
|
|
@ -155,8 +158,7 @@ async fn main() -> Result<ExitCode> {
|
|||
} else {
|
||||
command
|
||||
};
|
||||
let env = get_forward_env();
|
||||
let tty = atty::is(atty::Stream::Stdout);
|
||||
|
||||
let user = if root { "root" } else { "haze" };
|
||||
if tty {
|
||||
exec_tty(&docker, &cloud.id, user, command, env).await?;
|
||||
|
|
@ -165,19 +167,42 @@ async fn main() -> Result<ExitCode> {
|
|||
}
|
||||
}
|
||||
Some(ExecService::Db) => {
|
||||
cloud
|
||||
.db()
|
||||
.exec_sh(
|
||||
&docker,
|
||||
&cloud.id,
|
||||
if command.is_empty() {
|
||||
vec!["bash".to_string()]
|
||||
} else {
|
||||
command
|
||||
},
|
||||
atty::is(atty::Stream::Stdout),
|
||||
)
|
||||
.await?;
|
||||
let command = if command.is_empty() {
|
||||
vec!["bash".to_string()]
|
||||
} else {
|
||||
command
|
||||
};
|
||||
|
||||
cloud.db().exec_sh(&docker, &cloud.id, command, tty).await?;
|
||||
}
|
||||
Some(ExecService::Service(service)) => {
|
||||
let Some(container) = service.container_name(&cloud.id) else {
|
||||
eprintln!(
|
||||
"Service {} can't be exec'ed as it has no associated container",
|
||||
service.name()
|
||||
);
|
||||
return Ok(ExitCode::FAILURE);
|
||||
};
|
||||
if service.exec_shell() == "" && command.is_empty() {
|
||||
eprintln!(
|
||||
"Service {} can't be exec'ed as it has no shell",
|
||||
service.name()
|
||||
);
|
||||
return Ok(ExitCode::FAILURE);
|
||||
}
|
||||
|
||||
let command = if command.is_empty() {
|
||||
vec![service.exec_shell().to_string()]
|
||||
} else {
|
||||
command
|
||||
};
|
||||
|
||||
let user = if root { "root" } else { service.exec_user() };
|
||||
if tty {
|
||||
exec_tty(&docker, &container, user, command, env).await?;
|
||||
} else {
|
||||
exec(&docker, &container, user, command, env, Some(stdout())).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue