mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
add notify_push service
This commit is contained in:
parent
3cac4e4679
commit
93c20bc530
10 changed files with 224 additions and 45 deletions
|
|
@ -1,3 +1,4 @@
|
|||
use crate::config::HazeConfig;
|
||||
use crate::image::pull_image;
|
||||
use crate::service::ServiceTrait;
|
||||
use crate::Result;
|
||||
|
|
@ -20,7 +21,13 @@ impl ServiceTrait for LDAP {
|
|||
&["LDAP=1"]
|
||||
}
|
||||
|
||||
async fn spawn(&self, docker: &Docker, cloud_id: &str, network: &str) -> Result<String> {
|
||||
async fn spawn(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
network: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<String> {
|
||||
let image = "icewind1991/haze-ldap";
|
||||
pull_image(docker, image).await?;
|
||||
let options = Some(CreateContainerOptions {
|
||||
|
|
@ -57,17 +64,9 @@ impl ServiceTrait for LDAP {
|
|||
format!("{}-ldap", cloud_id)
|
||||
}
|
||||
|
||||
async fn start_message(&self, _docker: &Docker, _cloud_id: &str) -> Result<Option<String>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn apps(&self) -> &'static [&'static str] {
|
||||
&["user_ldap"]
|
||||
}
|
||||
|
||||
async fn post_setup(&self, _docker: &Docker, _cloud_id: &str) -> Result<Vec<String>> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
|
|
@ -83,7 +82,13 @@ impl ServiceTrait for LDAPAdmin {
|
|||
&[]
|
||||
}
|
||||
|
||||
async fn spawn(&self, docker: &Docker, cloud_id: &str, network: &str) -> Result<String> {
|
||||
async fn spawn(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
network: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<String> {
|
||||
let image = "osixia/phpldapadmin";
|
||||
pull_image(docker, image).await?;
|
||||
let options = Some(CreateContainerOptions {
|
||||
|
|
@ -149,12 +154,4 @@ impl ServiceTrait for LDAPAdmin {
|
|||
ip
|
||||
)))
|
||||
}
|
||||
|
||||
async fn post_setup(&self, _docker: &Docker, _cloud_id: &str) -> Result<Vec<String>> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
fn apps(&self) -> &'static [&'static str] {
|
||||
&[]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use crate::config::HazeConfig;
|
||||
use crate::exec::exec;
|
||||
use crate::image::pull_image;
|
||||
use crate::service::ServiceTrait;
|
||||
|
|
@ -40,7 +41,13 @@ impl ServiceTrait for ObjectStore {
|
|||
}
|
||||
}
|
||||
|
||||
async fn spawn(&self, docker: &Docker, cloud_id: &str, network: &str) -> Result<String> {
|
||||
async fn spawn(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
network: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<String> {
|
||||
pull_image(docker, self.image()).await?;
|
||||
let options = Some(CreateContainerOptions {
|
||||
name: format!("{}-object", cloud_id),
|
||||
|
|
@ -90,15 +97,7 @@ impl ServiceTrait for ObjectStore {
|
|||
format!("{}-object", cloud_id)
|
||||
}
|
||||
|
||||
async fn start_message(&self, _docker: &Docker, _cloud_id: &str) -> Result<Option<String>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn apps(&self) -> &'static [&'static str] {
|
||||
&["files_external"]
|
||||
}
|
||||
|
||||
async fn post_setup(&self, _docker: &Docker, _cloud_id: &str) -> Result<Vec<String>> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use crate::config::HazeConfig;
|
||||
use crate::image::pull_image;
|
||||
use crate::service::ServiceTrait;
|
||||
use crate::Result;
|
||||
|
|
@ -20,7 +21,13 @@ impl ServiceTrait for OnlyOffice {
|
|||
&[]
|
||||
}
|
||||
|
||||
async fn spawn(&self, docker: &Docker, cloud_id: &str, network: &str) -> Result<String> {
|
||||
async fn spawn(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
network: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<String> {
|
||||
let image = "onlyoffice/documentserver";
|
||||
pull_image(docker, image).await?;
|
||||
let options = Some(CreateContainerOptions {
|
||||
|
|
@ -55,10 +62,6 @@ impl ServiceTrait for OnlyOffice {
|
|||
format!("{}-onlyoffice", cloud_id)
|
||||
}
|
||||
|
||||
async fn start_message(&self, _docker: &Docker, _cloud_id: &str) -> Result<Option<String>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn apps(&self) -> &'static [&'static str] {
|
||||
&["onlyoffice"]
|
||||
}
|
||||
|
|
|
|||
147
src/service/push.rs
Normal file
147
src/service/push.rs
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
use crate::config::HazeConfig;
|
||||
use crate::image::pull_image;
|
||||
use crate::service::ServiceTrait;
|
||||
use crate::Result;
|
||||
use bollard::container::{Config, CreateContainerOptions, NetworkingConfig};
|
||||
use bollard::models::{ContainerState, EndpointSettings, HostConfig};
|
||||
use bollard::Docker;
|
||||
use color_eyre::eyre::WrapErr;
|
||||
use color_eyre::Report;
|
||||
use maplit::hashmap;
|
||||
use std::time::Duration;
|
||||
use tokio::time::{sleep, timeout};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct NotifyPush;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ServiceTrait for NotifyPush {
|
||||
fn name(&self) -> &str {
|
||||
"push"
|
||||
}
|
||||
|
||||
fn env(&self) -> &[&str] {
|
||||
&[]
|
||||
}
|
||||
|
||||
async fn spawn(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
network: &str,
|
||||
config: &HazeConfig,
|
||||
) -> Result<String> {
|
||||
let image = "icewind1991/notify_push";
|
||||
pull_image(docker, image).await?;
|
||||
let options = Some(CreateContainerOptions {
|
||||
name: self.container_name(cloud_id),
|
||||
});
|
||||
let config = Config {
|
||||
image: Some(image),
|
||||
host_config: Some(HostConfig {
|
||||
network_mode: Some(network.to_string()),
|
||||
binds: Some(vec![
|
||||
format!("{}/config:/config:ro", config.work_dir.join(cloud_id)),
|
||||
format!("{}/data:/var/www/html/data", config.work_dir.join(cloud_id)),
|
||||
]),
|
||||
..Default::default()
|
||||
}),
|
||||
env: Some(vec![
|
||||
"NEXTCLOUD_URL=http://cloud/",
|
||||
"LOG=debug",
|
||||
"REDIS_URL=redis://cloud/",
|
||||
]),
|
||||
labels: Some(hashmap! {
|
||||
"haze-type" => self.name(),
|
||||
"haze-cloud-id" => cloud_id
|
||||
}),
|
||||
networking_config: Some(NetworkingConfig {
|
||||
endpoints_config: hashmap! {
|
||||
network => EndpointSettings {
|
||||
aliases: Some(vec![self.name().to_string()]),
|
||||
..Default::default()
|
||||
}
|
||||
},
|
||||
}),
|
||||
cmd: Some(vec!["/notify_push", "/config/config.php"]),
|
||||
..Default::default()
|
||||
};
|
||||
let id = docker.create_container(options, config).await?.id;
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
fn container_name(&self, cloud_id: &str) -> String {
|
||||
format!("{}-push", cloud_id)
|
||||
}
|
||||
|
||||
fn apps(&self) -> &'static [&'static str] {
|
||||
&["notify_push"]
|
||||
}
|
||||
|
||||
async fn is_healthy(&self, _docker: &Docker, _cloud_id: &str) -> Result<bool> {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
async fn post_setup(&self, docker: &Docker, cloud_id: &str) -> Result<Vec<String>> {
|
||||
docker
|
||||
.start_container::<String>(&self.container_name(cloud_id), None)
|
||||
.await?;
|
||||
self.wait_for_push(docker, cloud_id).await?;
|
||||
|
||||
sleep(Duration::from_millis(100)).await;
|
||||
|
||||
let info = docker
|
||||
.inspect_container(&self.container_name(cloud_id), None)
|
||||
.await?;
|
||||
let ip = if matches!(
|
||||
info.state,
|
||||
Some(ContainerState {
|
||||
running: Some(true),
|
||||
..
|
||||
})
|
||||
) {
|
||||
info.network_settings
|
||||
.unwrap()
|
||||
.networks
|
||||
.unwrap()
|
||||
.values()
|
||||
.next()
|
||||
.unwrap()
|
||||
.ip_address
|
||||
.clone()
|
||||
.unwrap()
|
||||
} else {
|
||||
return Err(Report::msg("notify_push not started"));
|
||||
};
|
||||
Ok(vec![
|
||||
format!("occ config:system:set trusted_proxies 1 --value {}", ip),
|
||||
format!("occ notify_push:setup http://{}:7867", ip),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
impl NotifyPush {
|
||||
async fn is_push_running(&self, docker: &Docker, cloud_id: &str) -> Result<bool> {
|
||||
let info = docker
|
||||
.inspect_container(&self.container_name(cloud_id), None)
|
||||
.await?;
|
||||
Ok(matches!(
|
||||
info.state,
|
||||
Some(ContainerState {
|
||||
running: Some(true),
|
||||
..
|
||||
})
|
||||
))
|
||||
}
|
||||
|
||||
async fn wait_for_push(&self, docker: &Docker, cloud_id: &str) -> Result<()> {
|
||||
timeout(Duration::from_secs(30), async {
|
||||
while !self.is_push_running(docker, cloud_id).await? {
|
||||
sleep(Duration::from_millis(100)).await
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.await
|
||||
.wrap_err("Timeout after 30 seconds")?
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue