Skip to content

Commit f21b930

Browse files
committed
connect to internal dsp of harp if present
Signed-off-by: Anupam Kumar <[email protected]>
1 parent 5884ab7 commit f21b930

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/Command/Daemon/ListDaemons.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4343

4444
$output->writeln('Registered ExApp daemon configs:');
4545
$table = new Table($output);
46-
$table->setHeaders(['Def', 'Name', 'Display name', 'Deploy ID', 'Protocol', 'Host', 'NC Url', 'Is HaRP', 'HaRP FRP Address']);
46+
$table->setHeaders(['Def', 'Name', 'Display name', 'Deploy ID', 'Protocol', 'Host', 'NC Url', 'Is HaRP', 'HaRP FRP Address', 'HaRP Docker Socket Port']);
4747
$rows = [];
4848

4949
foreach ($daemonConfigs as $daemon) {
@@ -54,8 +54,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5454
$daemon->getProtocol(),
5555
$daemon->getHost(),
5656
$daemon->getDeployConfig()['nextcloud_url'],
57-
$daemon->getDeployConfig()['harp'] ? 'yes' : 'no',
57+
boolval($daemon->getDeployConfig()['harp'] ?? false) ? 'yes' : 'no',
5858
$daemon->getDeployConfig()['harp_frp_address'] ?? '(none)',
59+
$daemon->getDeployConfig()['harp_docker_socket_port'] ?? '(none)',
5960
];
6061
}
6162

lib/Command/Daemon/RegisterDaemon.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ protected function configure(): void {
4848
$this->addOption('harp', null, InputOption::VALUE_NONE, 'Set daemon to use HaRP for all docker and exapp communication');
4949
$this->addOption('harp_frp_address', null, InputOption::VALUE_REQUIRED, '[host]:[port] of the HaRP FRP server, default host is same as HaRP host and port is 8782');
5050
$this->addOption('harp_shared_key', null, InputOption::VALUE_REQUIRED, 'HaRP shared key for secure communication between HaRP and AppAPI');
51+
$this->addOption('harp_docker_socket_port', null, InputOption::VALUE_REQUIRED, '\'remotePort\' of the FRP client of the remote docker socket proxy. There is one included in the harp container so this can be skipped for default setups.', '24000');
5152

5253
$this->addUsage('manual_install "Manual Install" "manual-install" "http" null "http://nextcloud.local"');
5354
$this->addUsage('local_docker "Docker Local" "docker-install" "http" "/var/run/docker.sock" "http://nextcloud.local" --net=nextcloud');
@@ -103,6 +104,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
103104
'computeDevice' => $this->buildComputeDevice($input->getOption('compute_device') ?? 'cpu'),
104105
'harp' => $isHarp,
105106
'harp_frp_address' => $input->getOption('harp_frp_address') ?? '',
107+
'harp_docker_socket_port' => $input->getOption('harp_docker_socket_port'),
106108
];
107109

108110
$daemonConfig = $this->daemonConfigService->registerDaemonConfig([

lib/DeployActions/DockerActions.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,14 @@ public function healthcheckContainer(string $containerId, DaemonConfig $daemonCo
829829

830830
public function buildDockerUrl(DaemonConfig $daemonConfig): string {
831831
// When using local socket, we the curl URL needs to be set to http://localhost
832-
return $this->isLocalSocket($daemonConfig->getHost()) ? 'http://localhost' : $daemonConfig->getProtocol() . '://' . $daemonConfig->getHost();
832+
$url = $this->isLocalSocket($daemonConfig->getHost())
833+
? 'http://localhost'
834+
: $daemonConfig->getProtocol() . '://' . $daemonConfig->getHost();
835+
if (boolval($daemonConfig->getDeployConfig()['harp'] ?? false)) {
836+
// if there is a trailling slash, remove it
837+
$url = rtrim($url, '/') . '/exapps/app_api';
838+
}
839+
return $url;
833840
}
834841

835842
public function initGuzzleClient(DaemonConfig $daemonConfig): void {
@@ -849,6 +856,12 @@ public function initGuzzleClient(DaemonConfig $daemonConfig): void {
849856
$haproxyPass = $this->crypto->decrypt($daemonConfig->getDeployConfig()['haproxy_password']);
850857
$guzzleParams['auth'] = [self::APP_API_HAPROXY_USER, $haproxyPass];
851858
}
859+
if (boolval($daemonConfig->getDeployConfig()['harp'] ?? false)) {
860+
$guzzleParams['headers'] = [
861+
'harp-shared-key' => $guzzleParams['auth'][1],
862+
'docker-engine-port' => $daemonConfig->getDeployConfig()['harp_docker_socket_port'],
863+
];
864+
}
852865
$this->guzzleClient = new Client($guzzleParams);
853866
}
854867

0 commit comments

Comments
 (0)