Skip to content

Commit

Permalink
merge containers.json and make sure they depend on the apache container
Browse files Browse the repository at this point in the history
Signed-off-by: Simon L <szaimen@e.mail.de>
  • Loading branch information
szaimen committed Sep 27, 2023
1 parent 538ee32 commit ac890f0
Showing 1 changed file with 19 additions and 32 deletions.
51 changes: 19 additions & 32 deletions php/src/ContainerDefinitionFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,20 @@ public function GetContainerById(string $id): Container
/**
* @return array
*/
private function GetDefinition(bool $latest): array
private function GetDefinition(): array
{
$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 = [];
foreach ($data['aio_services_v1'] as $entry) {
if ($entry['container_name'] === 'nextcloud-aio-clamav') {
Expand Down Expand Up @@ -154,7 +164,13 @@ private function GetDefinition(bool $latest): array

$dependsOn = [];
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 (!$this->configurationManager->isClamavEnabled()) {
continue;
Expand Down Expand Up @@ -305,35 +321,6 @@ private function GetDefinition(bool $latest): array

public function FetchDefinition(): array
{
if (!file_exists(DataConst::GetDataDirectory() . '/containers.json')) {
$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;
return $this->GetDefinition();
}
}

0 comments on commit ac890f0

Please sign in to comment.