merge containers.json and make sure they depend on the apache container

Signed-off-by: Simon L <szaimen@e.mail.de>
This commit is contained in:
Simon L 2023-09-27 20:23:25 +02:00
parent 538ee321a9
commit ac890f046b

View file

@ -43,10 +43,20 @@ class ContainerDefinitionFetcher
/** /**
* @return array * @return array
*/ */
private function GetDefinition(bool $latest): array private function GetDefinition(): array
{ {
$data = json_decode(file_get_contents(__DIR__ . '/../containers.json'), true); $data = json_decode(file_get_contents(__DIR__ . '/../containers.json'), true);
$additionalContainerNames = [];
foreach ($this->configurationManager->GetEnabledCommunityContainers() as $communityContainer) {
if ($communityContainer !== '') {
$path = DataConst::GetCommunityContainersDirectory() . $communityContainer . '/' . $communityContainer . '.json';
$additionalData = json_decode(file_get_contents($path), true);
$data = array_merge_recursive($data, $additionalData);
$additionalContainerNames[] = $additionalData['aio_services_v1'][]['container_name'];
}
}
$containers = []; $containers = [];
foreach ($data['aio_services_v1'] as $entry) { foreach ($data['aio_services_v1'] as $entry) {
if ($entry['container_name'] === 'nextcloud-aio-clamav') { if ($entry['container_name'] === 'nextcloud-aio-clamav') {
@ -154,7 +164,13 @@ class ContainerDefinitionFetcher
$dependsOn = []; $dependsOn = [];
if (isset($entry['depends_on'])) { if (isset($entry['depends_on'])) {
foreach ($entry['depends_on'] as $value) { $valueDependsOn = $entry['depends_on'];
if ($entry['container_name'] === 'nextcloud-aio-apache') {
foreach ($additionalContainerNames as $containerName) {
$valueDependsOn[] = $containerName;
}
}
foreach ($valueDependsOn as $value) {
if ($value === 'nextcloud-aio-clamav') { if ($value === 'nextcloud-aio-clamav') {
if (!$this->configurationManager->isClamavEnabled()) { if (!$this->configurationManager->isClamavEnabled()) {
continue; continue;
@ -305,35 +321,6 @@ class ContainerDefinitionFetcher
public function FetchDefinition(): array public function FetchDefinition(): array
{ {
if (!file_exists(DataConst::GetDataDirectory() . '/containers.json')) { return $this->GetDefinition();
$containers = $this->GetDefinition(true);
} else {
$containers = $this->GetDefinition(false);
}
$borgBackupMode = $this->configurationManager->GetBorgBackupMode();
$fetchLatest = false;
foreach ($containers as $container) {
if ($container->GetIdentifier() === 'nextcloud-aio-borgbackup') {
if ($container->GetRunningState() === RunningState::class) {
if ($borgBackupMode !== 'backup' && $borgBackupMode !== 'restore') {
$fetchLatest = true;
}
} else {
$fetchLatest = true;
}
} elseif ($container->GetIdentifier() === 'nextcloud-aio-watchtower' && $container->GetRunningState() === RunningState::class) {
return $containers;
}
}
if ($fetchLatest === true) {
$containers = $this->GetDefinition(true);
}
return $containers;
} }
} }