1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-04 01:24:09 +02:00

forward OCC_LOG

This commit is contained in:
Robin Appelman 2023-06-15 17:54:11 +02:00
commit fe5562a9b5
6 changed files with 90 additions and 31 deletions

View file

@ -436,36 +436,39 @@ impl Cloud {
Ok(()) Ok(())
} }
pub async fn exec<S: Into<String>>( pub async fn exec<S: Into<String>, Env: Into<String>>(
&self, &self,
docker: &Docker, docker: &Docker,
cmd: Vec<S>, cmd: Vec<S>,
tty: bool, tty: bool,
env: Vec<Env>,
) -> Result<ExitCode> { ) -> Result<ExitCode> {
if tty { if tty {
exec_tty(docker, &self.id, "haze", cmd, vec![]).await exec_tty(docker, &self.id, "haze", cmd, env).await
} else { } else {
exec(docker, &self.id, "haze", cmd, vec![], Some(stdout())).await exec(docker, &self.id, "haze", cmd, env, Some(stdout())).await
} }
} }
pub async fn occ<'a, S: Into<String> + From<&'a str>>( pub async fn occ<'a, S: Into<String> + From<&'a str>, Env: Into<String>>(
&self, &self,
docker: &Docker, docker: &Docker,
mut cmd: Vec<S>, mut cmd: Vec<S>,
output: Option<&mut Vec<u8>>, output: Option<&mut Vec<u8>>,
env: Vec<Env>,
) -> Result<ExitCode> { ) -> Result<ExitCode> {
cmd.insert(0, "occ".into()); cmd.insert(0, "occ".into());
self.exec_with_output(docker, cmd, output).await self.exec_with_output(docker, cmd, output, env).await
} }
pub async fn exec_with_output<S: Into<String>>( pub async fn exec_with_output<S: Into<String>, Env: Into<String>>(
&self, &self,
docker: &Docker, docker: &Docker,
cmd: Vec<S>, cmd: Vec<S>,
output: Option<impl Write>, output: Option<impl Write>,
env: Vec<Env>,
) -> Result<ExitCode> { ) -> Result<ExitCode> {
exec(docker, &self.id, "haze", cmd, vec![], output).await exec(docker, &self.id, "haze", cmd, env, output).await
} }
pub async fn list( pub async fn list(
@ -607,6 +610,7 @@ impl Cloud {
"--force".to_string(), "--force".to_string(),
], ],
false, false,
Vec::<String>::default(),
) )
.await?; .await?;
Ok(()) Ok(())

View file

@ -252,9 +252,17 @@ impl Database {
_ => format!("{}-db", cloud_id), _ => format!("{}-db", cloud_id),
}; };
if tty { if tty {
exec_tty(docker, &container, "root", cmd, vec![]).await exec_tty(docker, &container, "root", cmd, Vec::<String>::default()).await
} else { } else {
exec(docker, &container, "root", cmd, vec![], Some(stdout())).await exec(
docker,
&container,
"root",
cmd,
Vec::<String>::default(),
Some(stdout()),
)
.await
} }
} }
@ -266,7 +274,7 @@ impl Database {
cloud_id, cloud_id,
"haze", "haze",
vec!["sqlite3", "/var/www/html/data/haze.db"], vec!["sqlite3", "/var/www/html/data/haze.db"],
vec![], Vec::<String>::default(),
) )
.await .await
} }
@ -282,7 +290,7 @@ impl Database {
"-phaze", "-phaze",
"haze", "haze",
], ],
vec![], Vec::<String>::default(),
) )
.await .await
} }
@ -302,7 +310,7 @@ impl Database {
format!("{}-db", cloud_id), format!("{}-db", cloud_id),
"root", "root",
vec!["sqlplus", "system/haze"], vec!["sqlplus", "system/haze"],
vec![], Vec::<String>::default(),
) )
.await .await
} }
@ -355,7 +363,7 @@ impl Database {
format!("{}-db", cloud_id), format!("{}-db", cloud_id),
"root", "root",
vec!["mysql", "-u", "haze", "-phaze", "-e", "SELECT 1"], vec!["mysql", "-u", "haze", "-phaze", "-e", "SELECT 1"],
vec![], Vec::<String>::default(),
Some(&mut output), Some(&mut output),
) )
.await?; .await?;
@ -368,7 +376,7 @@ impl Database {
format!("{}-db", cloud_id), format!("{}-db", cloud_id),
"root", "root",
vec!["pg_isready", "-U", "haze", "-q"], vec!["pg_isready", "-U", "haze", "-q"],
vec![], Vec::<String>::default(),
Option::<Stdout>::None, Option::<Stdout>::None,
) )
.await?; .await?;
@ -378,7 +386,7 @@ impl Database {
format!("{}-db", cloud_id), format!("{}-db", cloud_id),
"root", "root",
vec!["psql", "-U", "haze", "-qtA", "-c", ""], vec!["psql", "-U", "haze", "-qtA", "-c", ""],
vec![], Vec::<String>::default(),
Option::<Stdout>::None, Option::<Stdout>::None,
) )
.await?; .await?;
@ -394,7 +402,7 @@ impl Database {
format!("{}-db", cloud_id), format!("{}-db", cloud_id),
"root", "root",
vec!["sh", "-c", r#"echo "show user" | sqlplus -S system/haze"#], vec!["sh", "-c", r#"echo "show user" | sqlplus -S system/haze"#],
vec![], Vec::<String>::default(),
Some(&mut output), Some(&mut output),
) )
.await?; .await?;

View file

@ -11,12 +11,12 @@ use tokio::io::AsyncWriteExt;
use tokio::task::spawn; use tokio::task::spawn;
use tokio::time::sleep; use tokio::time::sleep;
pub async fn exec_tty<S1: AsRef<str>, S2: Into<String>>( pub async fn exec_tty<S1: AsRef<str>, S2: Into<String>, Env: Into<String>>(
docker: &Docker, docker: &Docker,
container: S1, container: S1,
user: &str, user: &str,
cmd: Vec<S2>, cmd: Vec<S2>,
env: Vec<&str>, env: Vec<Env>,
) -> Result<ExitCode> { ) -> Result<ExitCode> {
let stdout = stdout(); let stdout = stdout();
@ -26,7 +26,7 @@ pub async fn exec_tty<S1: AsRef<str>, S2: Into<String>>(
let tty_size = terminal_size().into_diagnostic()?; let tty_size = terminal_size().into_diagnostic()?;
let cmd = cmd.into_iter().map(S2::into).collect(); let cmd = cmd.into_iter().map(S2::into).collect();
let env = env.into_iter().map(String::from).collect(); let env = env.into_iter().map(Env::into).collect();
let config = CreateExecOptions { let config = CreateExecOptions {
cmd: Some(cmd), cmd: Some(cmd),
user: Some(user.to_string()), user: Some(user.to_string()),
@ -97,16 +97,16 @@ pub async fn exec_tty<S1: AsRef<str>, S2: Into<String>>(
.into()) .into())
} }
pub async fn exec<S1: AsRef<str>, S2: Into<String>>( pub async fn exec<S1: AsRef<str>, S2: Into<String>, Env: Into<String>>(
docker: &Docker, docker: &Docker,
container: S1, container: S1,
user: &str, user: &str,
cmd: Vec<S2>, cmd: Vec<S2>,
env: Vec<&str>, env: Vec<Env>,
mut std_out: Option<impl Write>, mut std_out: Option<impl Write>,
) -> Result<ExitCode> { ) -> Result<ExitCode> {
let cmd = cmd.into_iter().map(S2::into).collect(); let cmd = cmd.into_iter().map(S2::into).collect();
let env = env.into_iter().map(String::from).collect(); let env = env.into_iter().map(Env::into).collect();
let config = CreateExecOptions { let config = CreateExecOptions {
cmd: Some(cmd), cmd: Some(cmd),
user: Some(user.to_string()), user: Some(user.to_string()),

View file

@ -12,6 +12,7 @@ use crate::service::Service;
use crate::service::ServiceTrait; use crate::service::ServiceTrait;
use bollard::Docker; use bollard::Docker;
use miette::{IntoDiagnostic, Report, Result, WrapErr}; use miette::{IntoDiagnostic, Report, Result, WrapErr};
use std::env::vars;
use std::io::stdout; use std::io::stdout;
use std::os::unix::process::CommandExt; use std::os::unix::process::CommandExt;
use std::process::Command; use std::process::Command;
@ -29,6 +30,15 @@ mod php;
mod proxy; mod proxy;
mod service; mod service;
static FORWARD_ENV: &[&str] = &["OCC_LOG"];
fn get_forward_env() -> Vec<String> {
vars()
.filter(|(var, _)| FORWARD_ENV.contains(&var.as_str()))
.map(|(var, value)| format!("{var}={value}"))
.collect()
}
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
miette::set_panic_hook(); miette::set_panic_hook();
@ -106,6 +116,7 @@ async fn main() -> Result<()> {
command command
}, },
atty::is(atty::Stream::Stdout), atty::is(atty::Stream::Stdout),
get_forward_env(),
) )
.await?; .await?;
} }
@ -133,7 +144,12 @@ async fn main() -> Result<()> {
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?; let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
command.insert(0, "occ".to_string()); command.insert(0, "occ".to_string());
cloud cloud
.exec(&docker, command, atty::is(atty::Stream::Stdout)) .exec(
&docker,
command,
atty::is(atty::Stream::Stdout),
get_forward_env(),
)
.await?; .await?;
} }
HazeArgs::Db { filter, root } => { HazeArgs::Db { filter, root } => {
@ -161,6 +177,7 @@ async fn main() -> Result<()> {
&config.auto_setup.password, &config.auto_setup.password,
], ],
false, false,
Vec::<String>::default(),
) )
.await .await
{ {
@ -180,7 +197,7 @@ async fn main() -> Result<()> {
cloud.enable_app(&docker, app).await?; cloud.enable_app(&docker, app).await?;
} }
args.insert(0, "tests".to_string()); args.insert(0, "tests".to_string());
cloud.exec(&docker, args, false).await?; cloud.exec(&docker, args, false, get_forward_env()).await?;
cloud.destroy(&docker).await?; cloud.destroy(&docker).await?;
} }
HazeArgs::Integration { options, mut args } => { HazeArgs::Integration { options, mut args } => {
@ -197,6 +214,7 @@ async fn main() -> Result<()> {
&config.auto_setup.password, &config.auto_setup.password,
], ],
false, false,
Vec::<String>::default(),
) )
.await .await
{ {
@ -204,7 +222,7 @@ async fn main() -> Result<()> {
return Err(e); return Err(e);
} }
args.insert(0, "integration".to_string()); args.insert(0, "integration".to_string());
cloud.exec(&docker, args, false).await?; cloud.exec(&docker, args, false, get_forward_env()).await?;
cloud.destroy(&docker).await?; cloud.destroy(&docker).await?;
} }
HazeArgs::Fmt { path } => { HazeArgs::Fmt { path } => {
@ -214,7 +232,12 @@ async fn main() -> Result<()> {
cloud.wait_for_start(&docker).await?; cloud.wait_for_start(&docker).await?;
println!("Installing composer"); println!("Installing composer");
if let Err(e) = cloud if let Err(e) = cloud
.exec_with_output(&docker, vec!["composer", "install"], Some(&mut out_buffer)) .exec_with_output(
&docker,
vec!["composer", "install"],
Some(&mut out_buffer),
Vec::<String>::default(),
)
.await .await
.and_then(|c| c.to_result()) .and_then(|c| c.to_result())
{ {
@ -229,6 +252,7 @@ async fn main() -> Result<()> {
&docker, &docker,
vec!["composer", "run", "cs:fix", path.as_str()], vec!["composer", "run", "cs:fix", path.as_str()],
false, false,
Vec::<String>::default(),
) )
.await .await
{ {
@ -241,6 +265,7 @@ async fn main() -> Result<()> {
&docker, &docker,
vec!["git", "clean", "-fd", "lib/composer"], vec!["git", "clean", "-fd", "lib/composer"],
Some(&mut out_buffer), Some(&mut out_buffer),
Vec::<String>::default(),
) )
.await .await
.and_then(|c| c.to_result()) .and_then(|c| c.to_result())
@ -254,6 +279,7 @@ async fn main() -> Result<()> {
&docker, &docker,
vec!["git", "checkout", "lib/composer"], vec!["git", "checkout", "lib/composer"],
Some(&mut out_buffer), Some(&mut out_buffer),
Vec::<String>::default(),
) )
.await .await
.and_then(|c| c.to_result()) .and_then(|c| c.to_result())
@ -275,6 +301,7 @@ async fn main() -> Result<()> {
command command
}, },
true, true,
get_forward_env(),
) )
.await?; .await?;
cloud.destroy(&docker).await?; cloud.destroy(&docker).await?;
@ -355,6 +382,7 @@ async fn setup(docker: &Docker, options: CloudOptions, config: &HazeConfig) -> R
&config.auto_setup.password, &config.auto_setup.password,
], ],
false, false,
Vec::<String>::default(),
) )
.await?; .await?;
cloud cloud
@ -367,6 +395,7 @@ async fn setup(docker: &Docker, options: CloudOptions, config: &HazeConfig) -> R
&cloud.address, &cloud.address,
], ],
None, None,
Vec::<String>::default(),
) )
.await?; .await?;
cloud cloud
@ -374,6 +403,7 @@ async fn setup(docker: &Docker, options: CloudOptions, config: &HazeConfig) -> R
docker, docker,
vec!["config:system:set", "overwritehost", "--value", host], vec!["config:system:set", "overwritehost", "--value", host],
None, None,
Vec::<String>::default(),
) )
.await?; .await?;
if cloud.address.contains("https://") { if cloud.address.contains("https://") {
@ -382,6 +412,7 @@ async fn setup(docker: &Docker, options: CloudOptions, config: &HazeConfig) -> R
docker, docker,
vec!["config:system:set", "overwriteprotocol", "--value", "https"], vec!["config:system:set", "overwriteprotocol", "--value", "https"],
None, None,
Vec::<String>::default(),
) )
.await?; .await?;
} }
@ -399,6 +430,7 @@ async fn setup(docker: &Docker, options: CloudOptions, config: &HazeConfig) -> R
domain, domain,
], ],
None, None,
Vec::<String>::default(),
) )
.await?; .await?;
} }
@ -406,20 +438,35 @@ async fn setup(docker: &Docker, options: CloudOptions, config: &HazeConfig) -> R
for service in &cloud.services { for service in &cloud.services {
for app in service.apps() { for app in service.apps() {
cloud cloud
.exec(docker, vec!["occ", "app:enable", *app, "--force"], false) .exec(
docker,
vec!["occ", "app:enable", *app, "--force"],
false,
Vec::<String>::default(),
)
.await?; .await?;
} }
} }
for service in &cloud.services { for service in &cloud.services {
for cmd in service.post_setup(docker, &cloud.id, config).await? { for cmd in service.post_setup(docker, &cloud.id, config).await? {
cloud cloud
.exec(docker, shell_words::split(&cmd).into_diagnostic()?, false) .exec(
docker,
shell_words::split(&cmd).into_diagnostic()?,
false,
Vec::<String>::default(),
)
.await?; .await?;
} }
} }
for cmd in &config.auto_setup.post_setup { for cmd in &config.auto_setup.post_setup {
cloud cloud
.exec(docker, shell_words::split(cmd).into_diagnostic()?, false) .exec(
docker,
shell_words::split(cmd).into_diagnostic()?,
false,
Vec::<String>::default(),
)
.await?; .await?;
} }
} }

View file

@ -77,7 +77,7 @@ impl ServiceTrait for Kaspersky {
self.container_name(cloud_id), self.container_name(cloud_id),
"root", "root",
vec!["curl", "localhost/licenseinfo"], vec!["curl", "localhost/licenseinfo"],
vec![], Vec::<String>::default(),
Option::<Stdout>::None, Option::<Stdout>::None,
) )
.await?; .await?;

View file

@ -126,7 +126,7 @@ impl ServiceTrait for ObjectStore {
format!("{}-object", cloud_id), format!("{}-object", cloud_id),
"root", "root",
vec!["curl", "localhost:9000/minio/health/ready"], vec!["curl", "localhost:9000/minio/health/ready"],
vec![], Vec::<String>::default(),
Some(&mut output), Some(&mut output),
) )
.await?; .await?;