Skip to content

Commit ff850b2

Browse files
committed
occ: make daemon commands harp combatible
Signed-off-by: Anupam Kumar <[email protected]>
1 parent ef574df commit ff850b2

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
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']);
46+
$table->setHeaders(['Def', 'Name', 'Display name', 'Deploy ID', 'Protocol', 'Host', 'NC Url', 'Is HaRP']);
4747
$rows = [];
4848

4949
foreach ($daemonConfigs as $daemon) {
@@ -53,7 +53,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5353
$daemon->getAcceptsDeployId(),
5454
$daemon->getProtocol(),
5555
$daemon->getHost(),
56-
$daemon->getDeployConfig()['nextcloud_url']
56+
$daemon->getDeployConfig()['nextcloud_url'],
57+
$daemon->getDeployConfig()['harp'] ? 'yes' : 'no',
5758
];
5859
}
5960

lib/Command/Daemon/RegisterDaemon.php

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ protected function configure(): void {
3232
$this->setName('app_api:daemon:register');
3333
$this->setDescription('Register daemon config for ExApp deployment');
3434

35+
// todo: add docs
3536
$this->addArgument('name', InputArgument::REQUIRED);
3637
$this->addArgument('display-name', InputArgument::REQUIRED);
3738
$this->addArgument('accepts-deploy-id', InputArgument::REQUIRED);
@@ -42,13 +43,16 @@ protected function configure(): void {
4243
// daemon-config settings
4344
$this->addOption('net', null, InputOption::VALUE_REQUIRED, 'DeployConfig, the name of the docker network to attach App to');
4445
$this->addOption('haproxy_password', null, InputOption::VALUE_REQUIRED, 'AppAPI Docker Socket Proxy password for HAProxy Basic auth');
45-
4646
$this->addOption('compute_device', null, InputOption::VALUE_REQUIRED, 'Compute device for GPU support (cpu|cuda|rocm)');
47-
4847
$this->addOption('set-default', null, InputOption::VALUE_NONE, 'Set DaemonConfig as default');
49-
50-
$this->addUsage('local_docker "Docker local" "docker-install" "http" "/var/run/docker.sock" "http://nextcloud.local" --net=nextcloud');
51-
$this->addUsage('local_docker "Docker local" "docker-install" "http" "/var/run/docker.sock" "http://nextcloud.local" --net=nextcloud --set-default --compute_device=cuda');
48+
$this->addOption('harp', null, InputOption::VALUE_NONE, 'Set daemon to use HaRP for all docker and exapp communication');
49+
$this->addOption('harp_shared_key', null, InputOption::VALUE_REQUIRED, 'HaRP shared key for secure communication between HaRP and AppAPI');
50+
51+
$this->addUsage('manual_install "Manual Install" "manual-install" "http" null "http://nextcloud.local"');
52+
$this->addUsage('local_docker "Docker Local" "docker-install" "http" "/var/run/docker.sock" "http://nextcloud.local" --net=nextcloud');
53+
$this->addUsage('local_docker "Docker Local" "docker-install" "http" "/var/run/docker.sock" "http://nextcloud.local" --net=nextcloud --set-default --compute_device=cuda');
54+
$this->addUsage('docker_install "Docker Socket Proxy" "docker-install" "http" "nextcloud-appapi-dsp:2375" "http://nextcloud.local" --net=nextcloud --set-default --compute_device=cuda');
55+
$this->addUsage('harp_install "Harp Install" "docker-install" "http" "nextcloud-appapi-harp:8780" "http://nextcloud.local" --harp --harp_shared_key "some_very_secure_password" --set-default --compute_device=cuda');
5256
}
5357

5458
protected function execute(InputInterface $input, OutputInterface $output): int {
@@ -58,28 +62,43 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5862
$protocol = $input->getArgument('protocol');
5963
$host = $input->getArgument('host');
6064
$nextcloudUrl = $input->getArgument('nextcloud_url');
61-
62-
$deployConfig = [
63-
'net' => $input->getOption('net') ?? 'host',
64-
'nextcloud_url' => $nextcloudUrl,
65-
'haproxy_password' => $input->getOption('haproxy_password') ?? '',
66-
'computeDevice' => $this->buildComputeDevice($input->getOption('compute_device') ?? 'cpu'),
67-
];
65+
$isHarp = $input->getOption('harp') !== null;
6866

6967
if (($protocol !== 'http') && ($protocol !== 'https')) {
7068
$output->writeln('Value error: The protocol must be `http` or `https`.');
7169
return 1;
7270
}
73-
if (($acceptsDeployId === 'manual-install') && ($protocol !== 'http')) {
71+
if ($acceptsDeployId === 'manual-install' && $protocol !== 'http') {
7472
$output->writeln('Value error: Manual-install daemon supports only `http` protocol.');
7573
return 1;
7674
}
75+
// todo:
76+
if ($acceptsDeployId === 'manual-install' && $isHarp) {
77+
$output->writeln('Value error: Manual-install daemon does not support HaRP.');
78+
return 1;
79+
}
80+
if ($isHarp && !$input->getOption('harp_shared_key')) {
81+
$output->writeln('Value error: HaRP enabled daemon requires `harp_shared_key` option.');
82+
return 1;
83+
}
7784

7885
if ($this->daemonConfigService->getDaemonConfigByName($name) !== null) {
7986
$output->writeln(sprintf('Skip registration, as daemon config `%s` already registered.', $name));
8087
return 0;
8188
}
8289

90+
$secret = $isHarp
91+
? $input->getOption('harp_shared_key')
92+
: $input->getOption('haproxy_password') ?? '';
93+
94+
$deployConfig = [
95+
'net' => $input->getOption('net') ?? 'host',
96+
'nextcloud_url' => $nextcloudUrl,
97+
'haproxy_password' => $secret,
98+
'computeDevice' => $this->buildComputeDevice($input->getOption('compute_device') ?? 'cpu'),
99+
'harp' => $isHarp,
100+
];
101+
83102
$daemonConfig = $this->daemonConfigService->registerDaemonConfig([
84103
'name' => $name,
85104
'display_name' => $displayName,

0 commit comments

Comments
 (0)