mirror of
https://codeberg.org/icewind/haze.git
synced 2026-10-01 16:54:08 +02:00
feat(lookup): Support use of local repo for the lookup-server
Signed-off-by: Louis Chmn <louis@chmn.me>
This commit is contained in:
parent
d48a192f3f
commit
2778f31c93
4 changed files with 92 additions and 3 deletions
|
|
@ -306,6 +306,8 @@ haze start --name gs-master lookup
|
||||||
The Nextcloud instance started with this command is already properly configured
|
The Nextcloud instance started with this command is already properly configured
|
||||||
as master node.
|
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:
|
You can then start slave instance with the following command:
|
||||||
|
|
||||||
```bash
|
```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.
|
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"
|
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 "<work_dir>/worktrees"
|
worktree_dir = "/path/to/worktrees" # where to create the worktrees of detached instances. optional, defaults to "<work_dir>/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
|
[auto_setup] # optional
|
||||||
enabled = false # whether or not to automatically install nextcloud on `haze start`. enabled by default
|
enabled = false # whether or not to automatically install nextcloud on `haze start`. enabled by default
|
||||||
|
|
|
||||||
|
|
@ -553,6 +553,7 @@ fn test_arg_parse() {
|
||||||
app_directories: Default::default(),
|
app_directories: Default::default(),
|
||||||
work_dir: Default::default(),
|
work_dir: Default::default(),
|
||||||
worktree_dir: Default::default(),
|
worktree_dir: Default::default(),
|
||||||
|
lookup_server_source: None,
|
||||||
auto_setup: Default::default(),
|
auto_setup: Default::default(),
|
||||||
volume: vec![],
|
volume: vec![],
|
||||||
blackfire: None,
|
blackfire: None,
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ pub struct HazeConfig {
|
||||||
pub app_directories: Vec<Utf8PathBuf>,
|
pub app_directories: Vec<Utf8PathBuf>,
|
||||||
pub work_dir: Utf8PathBuf,
|
pub work_dir: Utf8PathBuf,
|
||||||
pub worktree_dir: Utf8PathBuf,
|
pub worktree_dir: Utf8PathBuf,
|
||||||
|
pub lookup_server_source: Option<Utf8PathBuf>,
|
||||||
pub auto_setup: HazeAutoSetupConfig,
|
pub auto_setup: HazeAutoSetupConfig,
|
||||||
pub volume: Vec<HazeVolumeConfig>,
|
pub volume: Vec<HazeVolumeConfig>,
|
||||||
pub blackfire: Option<HazeBlackfireConfig>,
|
pub blackfire: Option<HazeBlackfireConfig>,
|
||||||
|
|
@ -32,6 +33,8 @@ pub struct RawHazeConfig {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub worktree_dir: Option<Utf8PathBuf>,
|
pub worktree_dir: Option<Utf8PathBuf>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
pub lookup_server_source: Option<Utf8PathBuf>,
|
||||||
|
#[serde(default)]
|
||||||
pub app_directories: Vec<Utf8PathBuf>,
|
pub app_directories: Vec<Utf8PathBuf>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub auto_setup: HazeAutoSetupConfig,
|
pub auto_setup: HazeAutoSetupConfig,
|
||||||
|
|
@ -73,6 +76,7 @@ impl From<RawHazeConfig> for HazeConfig {
|
||||||
.worktree_dir
|
.worktree_dir
|
||||||
.map(normalize_path)
|
.map(normalize_path)
|
||||||
.unwrap_or_else(|| work_dir.join("worktrees")),
|
.unwrap_or_else(|| work_dir.join("worktrees")),
|
||||||
|
lookup_server_source: raw.lookup_server_source.map(normalize_path),
|
||||||
work_dir,
|
work_dir,
|
||||||
auto_setup: raw.auto_setup,
|
auto_setup: raw.auto_setup,
|
||||||
volume: raw.volume,
|
volume: raw.volume,
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,18 @@ use crate::exec::exec;
|
||||||
use crate::image::pull_image;
|
use crate::image::pull_image;
|
||||||
use crate::network::ensure_network_exists;
|
use crate::network::ensure_network_exists;
|
||||||
use crate::service::ServiceTrait;
|
use crate::service::ServiceTrait;
|
||||||
|
use crate::service::authentik::write_file;
|
||||||
use bollard::Docker;
|
use bollard::Docker;
|
||||||
use bollard::config::{NetworkConnectRequest, NetworkingConfig};
|
use bollard::config::{NetworkConnectRequest, NetworkingConfig};
|
||||||
use bollard::models::{ContainerCreateBody, EndpointSettings, HostConfig};
|
use bollard::models::{ContainerCreateBody, EndpointSettings, HostConfig};
|
||||||
use bollard::query_parameters::CreateContainerOptions;
|
use bollard::query_parameters::CreateContainerOptions;
|
||||||
use maplit::hashmap;
|
use maplit::hashmap;
|
||||||
use miette::IntoDiagnostic;
|
use miette::{IntoDiagnostic, Report};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::Stdout;
|
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)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct LookupServer;
|
pub struct LookupServer;
|
||||||
|
|
@ -31,7 +32,7 @@ impl ServiceTrait for LookupServer {
|
||||||
docker: &Docker,
|
docker: &Docker,
|
||||||
cloud_id: &str,
|
cloud_id: &str,
|
||||||
network: &str,
|
network: &str,
|
||||||
_config: &HazeConfig,
|
config: &HazeConfig,
|
||||||
_options: &CloudOptions,
|
_options: &CloudOptions,
|
||||||
) -> Result<Vec<String>> {
|
) -> Result<Vec<String>> {
|
||||||
let image = "ghcr.io/juliusknorr/nextcloud-dev-lookupserver:latest";
|
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
|
// attached to the shared network in addition to the instance network
|
||||||
ensure_network_exists(docker, "haze").await?;
|
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 {
|
let options = Some(CreateContainerOptions {
|
||||||
name: self.container_name(cloud_id),
|
name: self.container_name(cloud_id),
|
||||||
..CreateContainerOptions::default()
|
..CreateContainerOptions::default()
|
||||||
|
|
@ -49,6 +66,7 @@ impl ServiceTrait for LookupServer {
|
||||||
image: Some(image.into()),
|
image: Some(image.into()),
|
||||||
host_config: Some(HostConfig {
|
host_config: Some(HostConfig {
|
||||||
network_mode: Some(network.to_string()),
|
network_mode: Some(network.to_string()),
|
||||||
|
binds: Some(binds),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
labels: Some(hashmap! {
|
labels: Some(hashmap! {
|
||||||
|
|
@ -142,3 +160,66 @@ impl ServiceTrait for LookupServer {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lookup-server config.
|
||||||
|
fn lookup_config() -> String {
|
||||||
|
format!(
|
||||||
|
r#"<?php
|
||||||
|
|
||||||
|
$CONFIG = [
|
||||||
|
'DB' => [
|
||||||
|
'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' => '',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
"#
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue