mirror of
https://codeberg.org/icewind/haze.git
synced 2026-10-01 08:44:09 +02:00
feat(services): Add a service for the lookup server
Signed-off-by: Louis Chmn <louis@chmn.me>
This commit is contained in:
parent
7121474198
commit
46ea577dbd
3 changed files with 213 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ mod dav;
|
|||
mod imaginary;
|
||||
mod kaspersky;
|
||||
mod ldap;
|
||||
mod lookup_server;
|
||||
mod mail;
|
||||
mod objectstore;
|
||||
mod oc;
|
||||
|
|
@ -25,6 +26,7 @@ use crate::service::dav::Dav;
|
|||
use crate::service::imaginary::Imaginary;
|
||||
use crate::service::kaspersky::{Kaspersky, KasperskyIcap};
|
||||
pub use crate::service::ldap::{Ldap, LdapAdmin};
|
||||
pub use crate::service::lookup_server::LookupServer;
|
||||
use crate::service::mail::Mail;
|
||||
pub use crate::service::objectstore::ObjectStore;
|
||||
use crate::service::oc::Oc;
|
||||
|
|
@ -332,6 +334,9 @@ pub enum ServiceType {
|
|||
Oidc,
|
||||
/// Configure Authentik as a SCIM server for Nextcloud
|
||||
Scim,
|
||||
/// Global scale lookup server
|
||||
#[strum(serialize = "lookup")]
|
||||
LookupServer,
|
||||
}
|
||||
|
||||
#[enum_dispatch]
|
||||
|
|
@ -369,6 +374,7 @@ pub enum Service {
|
|||
AuthentikSaml(AuthentikSaml),
|
||||
AuthentikOidc(AuthentikOidc),
|
||||
AuthentikScim(AuthentikScim),
|
||||
LookupServer(LookupServer),
|
||||
Preset(PresetService),
|
||||
}
|
||||
|
||||
|
|
@ -428,6 +434,7 @@ impl Service {
|
|||
Service::Authentik(Authentik),
|
||||
Service::AuthentikScim(AuthentikScim),
|
||||
]),
|
||||
ServiceType::LookupServer => Some(vec![Service::LookupServer(LookupServer)]),
|
||||
}
|
||||
} else {
|
||||
presets
|
||||
|
|
|
|||
142
src/service/lookup_server.rs
Normal file
142
src/service/lookup_server.rs
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
use crate::Result;
|
||||
use crate::cloud::CloudOptions;
|
||||
use crate::config::HazeConfig;
|
||||
use crate::exec::exec;
|
||||
use crate::image::pull_image;
|
||||
use crate::network::ensure_network_exists;
|
||||
use crate::service::ServiceTrait;
|
||||
use bollard::Docker;
|
||||
use bollard::config::{NetworkConnectRequest, NetworkingConfig};
|
||||
use bollard::models::{ContainerCreateBody, EndpointSettings, HostConfig};
|
||||
use bollard::query_parameters::CreateContainerOptions;
|
||||
use maplit::hashmap;
|
||||
use miette::IntoDiagnostic;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
use std::io::Stdout;
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct LookupServer;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ServiceTrait for LookupServer {
|
||||
fn name(&self) -> &str {
|
||||
"lookup"
|
||||
}
|
||||
|
||||
async fn spawn(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
network: &str,
|
||||
_config: &HazeConfig,
|
||||
_options: &CloudOptions,
|
||||
) -> Result<Vec<String>> {
|
||||
let image = "ghcr.io/juliusknorr/nextcloud-dev-lookupserver:latest";
|
||||
pull_image(docker, image).await?;
|
||||
|
||||
// The lookup server needs to be reachable from other instances, so it's
|
||||
// attached to the shared network in addition to the instance network
|
||||
ensure_network_exists(docker, "haze").await?;
|
||||
|
||||
let options = Some(CreateContainerOptions {
|
||||
name: self.container_name(cloud_id),
|
||||
..CreateContainerOptions::default()
|
||||
});
|
||||
let container_config = ContainerCreateBody {
|
||||
image: Some(image.into()),
|
||||
host_config: Some(HostConfig {
|
||||
network_mode: Some(network.to_string()),
|
||||
..Default::default()
|
||||
}),
|
||||
labels: Some(hashmap! {
|
||||
"haze-type".into() => self.name().into(),
|
||||
"haze-cloud-id".into() => cloud_id.into(),
|
||||
}),
|
||||
networking_config: Some(NetworkingConfig {
|
||||
endpoints_config: Some(hashmap! {
|
||||
network.into() => EndpointSettings {
|
||||
aliases: Some(vec![self.name().to_string()]),
|
||||
..Default::default()
|
||||
}
|
||||
}),
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
let id = docker
|
||||
.create_container(options, container_config)
|
||||
.await
|
||||
.into_diagnostic()?
|
||||
.id;
|
||||
docker.start_container(&id, None).await.into_diagnostic()?;
|
||||
|
||||
if let Err(e) = docker
|
||||
.connect_network(
|
||||
"haze",
|
||||
NetworkConnectRequest {
|
||||
container: id.clone(),
|
||||
endpoint_config: Some(EndpointSettings {
|
||||
aliases: self.container_name(cloud_id).map(|name| vec![name]),
|
||||
..Default::default()
|
||||
}),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.into_diagnostic()
|
||||
{
|
||||
docker.remove_container(&id, None).await.ok();
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
Ok(vec![id.into()])
|
||||
}
|
||||
|
||||
fn container_name(&self, cloud_id: &str) -> Option<String> {
|
||||
Some(format!("{}-lookup", cloud_id))
|
||||
}
|
||||
|
||||
fn apps(&self) -> &'static [&'static str] {
|
||||
&["globalsiteselector"]
|
||||
}
|
||||
|
||||
async fn is_healthy(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
_options: &CloudOptions,
|
||||
) -> Result<bool> {
|
||||
if !self.is_running(docker, cloud_id).await? {
|
||||
return Ok(false);
|
||||
}
|
||||
let exit = exec(
|
||||
docker,
|
||||
self.container_name(cloud_id).unwrap(),
|
||||
"root",
|
||||
vec![
|
||||
"bash",
|
||||
"-c",
|
||||
r#"php -r 'exit(str_contains(@file_get_contents("http://127.0.0.1/index.php/status") ?: "", "version") ? 0 : 1);'"#,
|
||||
],
|
||||
Vec::<String>::default(),
|
||||
Option::<Stdout>::None,
|
||||
)
|
||||
.await?;
|
||||
Ok(exit.to_result().is_ok())
|
||||
}
|
||||
|
||||
fn config(
|
||||
&self,
|
||||
_docker: &Docker,
|
||||
_cloud_id: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<HashMap<String, Value>> {
|
||||
Ok(hashmap! {
|
||||
"lookup_server".into() => Value::String("http://lookup".into()),
|
||||
"gs.enabled".into() => Value::Bool(true),
|
||||
"gss.mode".into() => Value::String("master".into()),
|
||||
"gss.master.accounts".into() => Value::Array(vec![Value::String("admin".into())]),
|
||||
"gss.master.csp-allow".into() => Value::Array(vec![Value::String("*".into())]),
|
||||
"gss.jwt.key".into() => Value::String("random-key".into()),
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue