mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
more office wip, only wss proxy missing it seems
This commit is contained in:
parent
7910b9d034
commit
2a7f4de2b7
11 changed files with 186 additions and 110 deletions
|
|
@ -19,7 +19,8 @@ use crate::service::smb::Smb;
|
|||
use bollard::models::ContainerState;
|
||||
use bollard::Docker;
|
||||
use enum_dispatch::enum_dispatch;
|
||||
use miette::{IntoDiagnostic, Result, WrapErr};
|
||||
use miette::{IntoDiagnostic, Report, Result, WrapErr};
|
||||
use std::net::IpAddr;
|
||||
use std::time::Duration;
|
||||
use tokio::time::{sleep, timeout};
|
||||
|
||||
|
|
@ -64,9 +65,78 @@ pub trait ServiceTrait {
|
|||
&[]
|
||||
}
|
||||
|
||||
async fn post_setup(&self, _docker: &Docker, _cloud_id: &str) -> Result<Vec<String>> {
|
||||
async fn post_setup(
|
||||
&self,
|
||||
_docker: &Docker,
|
||||
_cloud_id: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<Vec<String>> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
async fn is_running(&self, docker: &Docker, cloud_id: &str) -> Result<bool> {
|
||||
let info = docker
|
||||
.inspect_container(&self.container_name(cloud_id), None)
|
||||
.await
|
||||
.into_diagnostic()?;
|
||||
Ok(matches!(
|
||||
info.state,
|
||||
Some(ContainerState {
|
||||
running: Some(true),
|
||||
..
|
||||
})
|
||||
))
|
||||
}
|
||||
|
||||
async fn wait_for_running(&self, docker: &Docker, cloud_id: &str) -> Result<()> {
|
||||
timeout(Duration::from_secs(30), async {
|
||||
while !self.is_running(docker, cloud_id).await? {
|
||||
sleep(Duration::from_millis(100)).await
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.await
|
||||
.into_diagnostic()
|
||||
.wrap_err("Timeout after 30 seconds")?
|
||||
}
|
||||
|
||||
async fn get_ip(&self, docker: &Docker, cloud_id: &str) -> Result<IpAddr> {
|
||||
docker
|
||||
.start_container::<String>(&self.container_name(cloud_id), None)
|
||||
.await
|
||||
.into_diagnostic()?;
|
||||
self.wait_for_running(docker, cloud_id).await?;
|
||||
|
||||
sleep(Duration::from_millis(100)).await;
|
||||
|
||||
let info = docker
|
||||
.inspect_container(&self.container_name(cloud_id), None)
|
||||
.await
|
||||
.into_diagnostic()?;
|
||||
if matches!(
|
||||
info.state,
|
||||
Some(ContainerState {
|
||||
running: Some(true),
|
||||
..
|
||||
})
|
||||
) {
|
||||
info.network_settings
|
||||
.unwrap()
|
||||
.networks
|
||||
.unwrap()
|
||||
.values()
|
||||
.next()
|
||||
.unwrap()
|
||||
.ip_address
|
||||
.clone()
|
||||
.unwrap()
|
||||
.parse()
|
||||
.into_diagnostic()
|
||||
.wrap_err("Invalid ip address")
|
||||
} else {
|
||||
Err(Report::msg("service not started"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[enum_dispatch]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue