Skip to content

Commit 4faa1cd

Browse files
oleksandr-ncbackportbot[bot]
authored andcommitted
feat(HaRP): automatically register HaRP when it is installed
Signed-off-by: Oleksander Piskun <[email protected]>
1 parent ef84ffc commit 4faa1cd

File tree

2 files changed

+90
-4
lines changed

2 files changed

+90
-4
lines changed

lib/DeployActions/AIODockerActions.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
class AIODockerActions {
2121
public const AIO_DAEMON_CONFIG_NAME = 'docker_aio';
2222
public const AIO_DOCKER_SOCKET_PROXY_HOST = 'nextcloud-aio-docker-socket-proxy:2375';
23+
public const AIO_HARP_DAEMON_CONFIG_NAME = 'harp_aio';
24+
public const AIO_HARP_HOST = 'nextcloud-aio-harp:8780';
2325

2426
public function __construct(
2527
private readonly IAppConfig $appConfig,
@@ -71,4 +73,72 @@ public function registerAIODaemonConfig(): ?DaemonConfig {
7173
}
7274
return $daemonConfig;
7375
}
76+
77+
/**
78+
* Check if HaRP is enabled in AIO
79+
*/
80+
public function isHarpEnabled(): bool {
81+
$harpEnabled = getenv('HARP_ENABLED');
82+
return $harpEnabled === 'yes' || $harpEnabled === 'true' || $harpEnabled === '1';
83+
}
84+
85+
/**
86+
* Check if Docker Socket Proxy is enabled in AIO
87+
*/
88+
public function isDockerSocketProxyEnabled(): bool {
89+
$dspEnabled = getenv('DOCKER_SOCKET_PROXY_ENABLED');
90+
return $dspEnabled === 'yes' || $dspEnabled === 'true' || $dspEnabled === '1';
91+
}
92+
93+
/**
94+
* Get the HP_SHARED_KEY from environment
95+
*/
96+
public function getHarpSharedKey(): ?string {
97+
$key = getenv('HP_SHARED_KEY');
98+
return $key !== false && $key !== '' ? $key : null;
99+
}
100+
101+
/**
102+
* Registers DaemonConfig with default params to use AIO HaRP
103+
*/
104+
public function registerAIOHarpDaemonConfig(): ?DaemonConfig {
105+
// Check if HaRP daemon config already exists
106+
$daemonConfig = $this->daemonConfigService->getDaemonConfigByName(self::AIO_HARP_DAEMON_CONFIG_NAME);
107+
if ($daemonConfig !== null) {
108+
return null;
109+
}
110+
111+
$harpSharedKey = $this->getHarpSharedKey();
112+
if ($harpSharedKey === null) {
113+
return null;
114+
}
115+
116+
$deployConfig = [
117+
'net' => 'nextcloud-aio',
118+
'nextcloud_url' => 'https://' . getenv('NC_DOMAIN'),
119+
'haproxy_password' => $harpSharedKey, // will be encrypted by DaemonConfigService
120+
'harp' => [
121+
'exapp_direct' => true,
122+
],
123+
'computeDevice' => [
124+
'id' => 'cpu',
125+
'label' => 'CPU',
126+
],
127+
];
128+
129+
$daemonConfigParams = [
130+
'name' => self::AIO_HARP_DAEMON_CONFIG_NAME,
131+
'display_name' => 'AIO HaRP',
132+
'accepts_deploy_id' => 'docker-install',
133+
'protocol' => 'http',
134+
'host' => self::AIO_HARP_HOST,
135+
'deploy_config' => $deployConfig,
136+
];
137+
138+
$daemonConfig = $this->daemonConfigService->registerDaemonConfig($daemonConfigParams);
139+
if ($daemonConfig !== null) {
140+
$this->appConfig->setValueString(Application::APP_ID, 'default_daemon_config', $daemonConfig->getName(), lazy: true);
141+
}
142+
return $daemonConfig;
143+
}
74144
}

lib/Migration/DataInitializationStep.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,27 @@ public function getName(): string {
2525
}
2626

2727
public function run(IOutput $output): void {
28-
// If in AIO - automatically register default DaemonConfig
28+
// If in AIO - automatically register default DaemonConfig(s)
2929
if ($this->AIODockerActions->isAIO()) {
30-
$output->info('AIO installation detected. Registering default daemon');
31-
if ($this->AIODockerActions->registerAIODaemonConfig() !== null) {
32-
$output->info('AIO DaemonConfig successfully registered');
30+
$output->info('AIO installation detected. Registering daemon(s)');
31+
32+
$harpEnabled = $this->AIODockerActions->isHarpEnabled();
33+
$dspEnabled = $this->AIODockerActions->isDockerSocketProxyEnabled();
34+
35+
// Register Docker Socket Proxy daemon if enabled
36+
if ($dspEnabled) {
37+
$output->info('Docker Socket Proxy is enabled in AIO. Registering DSP daemon');
38+
if ($this->AIODockerActions->registerAIODaemonConfig() !== null) {
39+
$output->info('AIO Docker Socket Proxy DaemonConfig successfully registered');
40+
}
41+
}
42+
43+
// Register HaRP daemon if enabled (HaRP becomes default when both are enabled)
44+
if ($harpEnabled) {
45+
$output->info('HaRP is enabled in AIO. Registering HaRP daemon');
46+
if ($this->AIODockerActions->registerAIOHarpDaemonConfig() !== null) {
47+
$output->info('AIO HaRP DaemonConfig successfully registered');
48+
}
3349
}
3450
}
3551
}

0 commit comments

Comments
 (0)