From 2778f31c93a62fed1dd001c8cf732644a6532740 Mon Sep 17 00:00:00 2001 From: Louis Chmn Date: Thu, 17 Sep 2026 12:52:36 +0200 Subject: [PATCH] feat(lookup): Support use of local repo for the lookup-server Signed-off-by: Louis Chmn --- README.md | 3 ++ src/args.rs | 1 + src/config.rs | 4 ++ src/service/lookup_server.rs | 87 ++++++++++++++++++++++++++++++++++-- 4 files changed, 92 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a822603..e0eb344 100644 --- a/README.md +++ b/README.md @@ -306,6 +306,8 @@ haze start --name gs-master lookup The Nextcloud instance started with this command is already properly configured as master node. +If you want to work on the lookup_server, you can set the `lookup_server_source` config in `haze.toml`. This will mount your local checkout of the lookup server into the container. + You can then start slave instance with the following command: ```bash @@ -489,6 +491,7 @@ sources_root = "/path/to/sources" # path of the nextcloud sources. required app_directories = ["/path/to/sources/more_app"] # paths to additional app directories. work_dir = "/path/to/temp/dir" # path to temporary directory. optional, defaults to "/tmp/haze" worktree_dir = "/path/to/worktrees" # where to create the worktrees of detached instances. optional, defaults to "/worktrees" +lookup_server_source = "/path/to/lookup-server" # optional, mount a local lookup-server checkout instead of the code bundled in the image [auto_setup] # optional enabled = false # whether or not to automatically install nextcloud on `haze start`. enabled by default diff --git a/src/args.rs b/src/args.rs index 181db11..7b2fc7d 100644 --- a/src/args.rs +++ b/src/args.rs @@ -553,6 +553,7 @@ fn test_arg_parse() { app_directories: Default::default(), work_dir: Default::default(), worktree_dir: Default::default(), + lookup_server_source: None, auto_setup: Default::default(), volume: vec![], blackfire: None, diff --git a/src/config.rs b/src/config.rs index 392b453..f54536c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,6 +17,7 @@ pub struct HazeConfig { pub app_directories: Vec, pub work_dir: Utf8PathBuf, pub worktree_dir: Utf8PathBuf, + pub lookup_server_source: Option, pub auto_setup: HazeAutoSetupConfig, pub volume: Vec, pub blackfire: Option, @@ -32,6 +33,8 @@ pub struct RawHazeConfig { #[serde(default)] pub worktree_dir: Option, #[serde(default)] + pub lookup_server_source: Option, + #[serde(default)] pub app_directories: Vec, #[serde(default)] pub auto_setup: HazeAutoSetupConfig, @@ -73,6 +76,7 @@ impl From for HazeConfig { .worktree_dir .map(normalize_path) .unwrap_or_else(|| work_dir.join("worktrees")), + lookup_server_source: raw.lookup_server_source.map(normalize_path), work_dir, auto_setup: raw.auto_setup, volume: raw.volume, diff --git a/src/service/lookup_server.rs b/src/service/lookup_server.rs index 8e6099f..d5bd950 100644 --- a/src/service/lookup_server.rs +++ b/src/service/lookup_server.rs @@ -5,17 +5,18 @@ use crate::exec::exec; use crate::image::pull_image; use crate::network::ensure_network_exists; use crate::service::ServiceTrait; +use crate::service::authentik::write_file; 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 miette::{IntoDiagnostic, Report}; use serde_json::Value; use std::collections::HashMap; use std::io::Stdout; -pub(super) const GSS_JWT_KEY: &str = "random-key"; +pub(super) const GSS_JWT_KEY: &str = "random-key-that-is-loong-enough"; #[derive(Debug, Clone, Eq, PartialEq)] pub struct LookupServer; @@ -31,7 +32,7 @@ impl ServiceTrait for LookupServer { docker: &Docker, cloud_id: &str, network: &str, - _config: &HazeConfig, + config: &HazeConfig, _options: &CloudOptions, ) -> Result> { let image = "ghcr.io/juliusknorr/nextcloud-dev-lookupserver:latest"; @@ -41,6 +42,22 @@ impl ServiceTrait for LookupServer { // attached to the shared network in addition to the instance network ensure_network_exists(docker, "haze").await?; + let config_dir = config.work_dir.join(cloud_id).join("lookup"); + write_file(&config_dir, "config.php", &lookup_config())?; + let mut binds = vec![format!( + "{config_dir}/config.php:/var/www/html/config/config.php:ro" + )]; + + if let Some(source) = &config.lookup_server_source { + let server_dir = source.join("server"); + if !server_dir.is_dir() { + return Err(Report::msg(format!( + "{server_dir} not found, `lookup_server_source` should point to a lookup-server checkout" + ))); + } + binds.push(format!("{server_dir}:/var/www/html")); + } + let options = Some(CreateContainerOptions { name: self.container_name(cloud_id), ..CreateContainerOptions::default() @@ -49,6 +66,7 @@ impl ServiceTrait for LookupServer { image: Some(image.into()), host_config: Some(HostConfig { network_mode: Some(network.to_string()), + binds: Some(binds), ..Default::default() }), labels: Some(hashmap! { @@ -142,3 +160,66 @@ impl ServiceTrait for LookupServer { }) } } + +// Lookup-server config. +fn lookup_config() -> String { + format!( + r#" [ + 'host' => 'localhost', + 'db' => 'lookup', + 'user' => 'lookup', + 'pass' => 'lookup', + ], + + 'ERROR_VERBOSE' => true, + + 'LOG' => [ + 'ENABLED' => true, + 'LEVEL' => 0, + 'FILE' => '/tmp/lookup.log', + 'FILE_MODE' => 0640, + 'DATE_FORMAT' => 'Y-m-d H:i:s', + 'DATE_TIMEZONE' => 'UTC', + 'HIDE_BACKTRACE' => false, + ], + + 'REPLICATION_LOG' => '/tmp/lookup_replication.log', + + 'MAX_SEARCH_PAGE' => 10, + + 'MAX_REQUESTS' => 10000, + + 'REPLICATION_AUTH' => 'foobar', + + 'SLAVEREPLICATION_AUTH' => 'slavefoobar', + + 'REPLICATION_HOSTS' => [ + ], + + 'IP_BLACKLIST' => [ + ], + + 'SPAM_BLACKLIST' => [ + ], + + 'EMAIL_SENDER' => 'admin@nextcloud.dev', + + 'PUBLIC_URL' => 'http://lookup', + + 'GLOBAL_SCALE' => true, + + 'AUTH_KEY' => '{GSS_JWT_KEY}', + + 'TWITTER' => [ + 'CONSUMER_KEY' => '', + 'CONSUMER_SECRET' => '', + 'ACCESS_TOKEN' => '', + 'ACCESS_TOKEN_SECRET' => '', + ] +]; +"# + ) +}