|
20 | 20 | class AIODockerActions { |
21 | 21 | public const AIO_DAEMON_CONFIG_NAME = 'docker_aio'; |
22 | 22 | 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'; |
23 | 25 |
|
24 | 26 | public function __construct( |
25 | 27 | private readonly IAppConfig $appConfig, |
@@ -71,4 +73,72 @@ public function registerAIODaemonConfig(): ?DaemonConfig { |
71 | 73 | } |
72 | 74 | return $daemonConfig; |
73 | 75 | } |
| 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 | + } |
74 | 144 | } |
0 commit comments