1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 09:04:12 +02:00
This commit is contained in:
Robin Appelman 2021-03-12 22:17:12 +01:00
commit 3939d6423e
2 changed files with 29 additions and 3 deletions

View file

@ -3,6 +3,7 @@ use bollard::container::{
Config, CreateContainerOptions, ListContainersOptions, LogsOptions, NetworkingConfig,
RemoveContainerOptions,
};
use bollard::exec::{CreateExecOptions, StartExecResults};
use bollard::models::{ContainerState, EndpointSettings, HostConfig};
use bollard::network::CreateNetworkOptions;
use bollard::Docker;
@ -418,8 +419,8 @@ impl Cloud {
config.work_dir, id
),
format!(
"{}/{}/skeleton/welcome.txt:/var/www/html/core/skeleton/welcome.txt:ro",
config.sources_root, id
"{}/skeleton/welcome.txt:/var/www/html/core/skeleton/welcome.txt:ro",
config.sources_root
),
format!(
"{}/{}/integration/vendor:/var/www/html/build/integration/vendor",
@ -546,6 +547,27 @@ impl Cloud {
}
Ok(logs)
}
pub async fn exec(&self, docker: &mut Docker, cmd: Vec<String>) -> Result<()> {
let config = CreateExecOptions {
cmd: Some(cmd),
user: Some("haze".to_string()),
attach_stdout: Some(true),
attach_stderr: Some(true),
..Default::default()
};
let message = docker.create_exec(&self.id, config).await?;
let mut exec = docker.start_exec(&message.id, None);
while let Some(res) = exec.next().await {
match res? {
StartExecResults::Attached { log } => {
print!("{}", log);
}
_ => {}
}
}
Ok(())
}
}
async fn setup_workdir(base: &Utf8Path, id: &str) -> Result<Utf8PathBuf> {

View file

@ -62,12 +62,16 @@ async fn main() -> Result<()> {
println!("http://{}", cloud.ip.unwrap());
}
HazeCommand::Logs => {
let cloud = get_by_filter(&mut docker, args.options.first().cloned(), &config).await?;
let cloud = get_by_filter(&mut docker, None, &config).await?;
let logs = cloud.logs(&mut docker).await?;
for log in logs {
print!("{}", log);
}
}
HazeCommand::Exec => {
let cloud = get_by_filter(&mut docker, None, &config).await?;
cloud.exec(&mut docker, args.options).await?;
}
_ => todo!(),
};