Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions lib/DeployActions/AIODockerActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
24 changes: 20 additions & 4 deletions lib/Migration/DataInitializationStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
}
Expand Down
Loading