From 6c8bc8fe2d6d3e6ae2b4969b4d7b711ed53dbae1 Mon Sep 17 00:00:00 2001 From: Oleksander Piskun Date: Mon, 26 Jan 2026 14:52:39 +0200 Subject: [PATCH] feat(HaRP): automatically register HaRP when it is installed Signed-off-by: Oleksander Piskun --- lib/DeployActions/AIODockerActions.php | 70 ++++++++++++++++++++++++ lib/Migration/DataInitializationStep.php | 24 ++++++-- 2 files changed, 90 insertions(+), 4 deletions(-) diff --git a/lib/DeployActions/AIODockerActions.php b/lib/DeployActions/AIODockerActions.php index 37833a89..372d2c08 100644 --- a/lib/DeployActions/AIODockerActions.php +++ b/lib/DeployActions/AIODockerActions.php @@ -20,6 +20,8 @@ class AIODockerActions { public const AIO_DAEMON_CONFIG_NAME = 'docker_aio'; public const AIO_DOCKER_SOCKET_PROXY_HOST = 'nextcloud-aio-docker-socket-proxy:2375'; + public const AIO_HARP_DAEMON_CONFIG_NAME = 'harp_aio'; + public const AIO_HARP_HOST = 'nextcloud-aio-harp:8780'; public function __construct( private readonly IAppConfig $appConfig, @@ -71,4 +73,72 @@ public function registerAIODaemonConfig(): ?DaemonConfig { } return $daemonConfig; } + + /** + * Check if HaRP is enabled in AIO + */ + public function isHarpEnabled(): bool { + $harpEnabled = getenv('HARP_ENABLED'); + return $harpEnabled === 'yes' || $harpEnabled === 'true' || $harpEnabled === '1'; + } + + /** + * Check if Docker Socket Proxy is enabled in AIO + */ + public function isDockerSocketProxyEnabled(): bool { + $dspEnabled = getenv('DOCKER_SOCKET_PROXY_ENABLED'); + return $dspEnabled === 'yes' || $dspEnabled === 'true' || $dspEnabled === '1'; + } + + /** + * Get the HP_SHARED_KEY from environment + */ + public function getHarpSharedKey(): ?string { + $key = getenv('HP_SHARED_KEY'); + return $key !== false && $key !== '' ? $key : null; + } + + /** + * Registers DaemonConfig with default params to use AIO HaRP + */ + public function registerAIOHarpDaemonConfig(): ?DaemonConfig { + // Check if HaRP daemon config already exists + $daemonConfig = $this->daemonConfigService->getDaemonConfigByName(self::AIO_HARP_DAEMON_CONFIG_NAME); + if ($daemonConfig !== null) { + return null; + } + + $harpSharedKey = $this->getHarpSharedKey(); + if ($harpSharedKey === null) { + return null; + } + + $deployConfig = [ + 'net' => 'nextcloud-aio', + 'nextcloud_url' => 'https://' . getenv('NC_DOMAIN'), + 'haproxy_password' => $harpSharedKey, // will be encrypted by DaemonConfigService + 'harp' => [ + 'exapp_direct' => true, + ], + 'computeDevice' => [ + 'id' => 'cpu', + 'label' => 'CPU', + ], + ]; + + $daemonConfigParams = [ + 'name' => self::AIO_HARP_DAEMON_CONFIG_NAME, + 'display_name' => 'AIO HaRP', + 'accepts_deploy_id' => 'docker-install', + 'protocol' => 'http', + 'host' => self::AIO_HARP_HOST, + 'deploy_config' => $deployConfig, + ]; + + $daemonConfig = $this->daemonConfigService->registerDaemonConfig($daemonConfigParams); + if ($daemonConfig !== null) { + $this->appConfig->setValueString(Application::APP_ID, 'default_daemon_config', $daemonConfig->getName(), lazy: true); + } + return $daemonConfig; + } } diff --git a/lib/Migration/DataInitializationStep.php b/lib/Migration/DataInitializationStep.php index ab8a1395..0be76e0d 100644 --- a/lib/Migration/DataInitializationStep.php +++ b/lib/Migration/DataInitializationStep.php @@ -25,11 +25,27 @@ public function getName(): string { } public function run(IOutput $output): void { - // If in AIO - automatically register default DaemonConfig + // If in AIO - automatically register default DaemonConfig(s) if ($this->AIODockerActions->isAIO()) { - $output->info('AIO installation detected. Registering default daemon'); - if ($this->AIODockerActions->registerAIODaemonConfig() !== null) { - $output->info('AIO DaemonConfig successfully registered'); + $output->info('AIO installation detected. Registering daemon(s)'); + + $harpEnabled = $this->AIODockerActions->isHarpEnabled(); + $dspEnabled = $this->AIODockerActions->isDockerSocketProxyEnabled(); + + // Register Docker Socket Proxy daemon if enabled + if ($dspEnabled) { + $output->info('Docker Socket Proxy is enabled in AIO. Registering DSP daemon'); + if ($this->AIODockerActions->registerAIODaemonConfig() !== null) { + $output->info('AIO Docker Socket Proxy DaemonConfig successfully registered'); + } + } + + // Register HaRP daemon if enabled (HaRP becomes default when both are enabled) + if ($harpEnabled) { + $output->info('HaRP is enabled in AIO. Registering HaRP daemon'); + if ($this->AIODockerActions->registerAIOHarpDaemonConfig() !== null) { + $output->info('AIO HaRP DaemonConfig successfully registered'); + } } } }