allow to set aio_variables from containers.json

Signed-off-by: Simon L <szaimen@e.mail.de>
This commit is contained in:
Simon L 2023-09-29 21:44:12 +02:00
parent 49aca0d955
commit 395380ea2b
5 changed files with 56 additions and 1 deletions

View file

@ -83,6 +83,13 @@
}
}
},
"aio_variables": {
"type": "array",
"items": {
"type": "string",
"pattern": "^[A-Z_-a-z]+=.*$"
}
},
"restart": {
"type": "string",
"pattern": "^unless-stopped$"

View file

@ -0,0 +1,19 @@
<?php
namespace AIO\Container;
class AioVariables {
/** @var string[] */
private array $variables = [];
public function AddVariable(string $variable) : void {
$this->variables[] = $variable;
}
/**
* @return string[]
*/
public function GetVariables() : array {
return $this->variables;
}
}

View file

@ -34,6 +34,7 @@ class Container {
private array $tmpfs;
private bool $init;
private string $imageTag;
private AioVariables $aioVariables;
private DockerActionManager $dockerActionManager;
public function __construct(
@ -58,6 +59,7 @@ class Container {
array $tmpfs,
bool $init,
string $imageTag,
AioVariables $aioVariables,
DockerActionManager $dockerActionManager
) {
$this->identifier = $identifier;
@ -81,6 +83,7 @@ class Container {
$this->tmpfs = $tmpfs;
$this->init = $init;
$this->imageTag = $imageTag;
$this->aioVariables = $aioVariables;
$this->dockerActionManager = $dockerActionManager;
}
@ -186,4 +189,8 @@ class Container {
public function GetEnvironmentVariables() : ContainerEnvironmentVariables {
return $this->containerEnvironmentVariables;
}
public function GetAioVariables() : AioVariables {
return $this->aioVariables;
}
}

View file

@ -2,6 +2,7 @@
namespace AIO;
use AIO\Container\AioVariables;
use AIO\Container\Container;
use AIO\Container\ContainerEnvironmentVariables;
use AIO\Container\ContainerPort;
@ -54,6 +55,7 @@ class ContainerDefinitionFetcher
$additionalData = json_decode(file_get_contents($path), true);
$data = array_merge_recursive($data, $additionalData);
if (isset($additionalData['aio_services_v1'][0]['display_name']) && $additionalData['aio_services_v1'][0]['display_name'] !== '') {
// Store container_name of community containers in variable for later
$additionalContainerNames[] = $additionalData['aio_services_v1'][0]['container_name'];
}
}
@ -168,9 +170,12 @@ class ContainerDefinitionFetcher
if (isset($entry['depends_on'])) {
$valueDependsOn = $entry['depends_on'];
if ($entry['container_name'] === 'nextcloud-aio-apache') {
// Add community containers first and default ones last so that aio_variables works correctly
$valueDependsOnTemp = [];
foreach ($additionalContainerNames as $containerName) {
$valueDependsOn[] = $containerName;
$valueDependsOnTemp[] = $containerName;
}
$valueDependsOn = array_merge_recursive($valueDependsOnTemp, $valueDependsOn);
}
foreach ($valueDependsOn as $value) {
if ($value === 'nextcloud-aio-clamav') {
@ -217,6 +222,13 @@ class ContainerDefinitionFetcher
}
}
$aioVariables = new AioVariables();
if (isset($entry['aio_variables'])) {
foreach ($entry['aio_variables'] as $value) {
$aioVariables->AddVariable($value);
}
}
$displayName = '';
if (isset($entry['display_name'])) {
$displayName = $entry['display_name'];
@ -314,6 +326,7 @@ class ContainerDefinitionFetcher
$tmpfs,
$init,
$imageTag,
$aioVariables,
$this->container->get(DockerActionManager::class)
);
}

View file

@ -248,6 +248,15 @@ class DockerActionManager
$this->configurationManager->GetAndGenerateSecret($secret);
}
$aioVariables = $container->GetAioVariables()->GetVariables();
foreach($aioVariables as $variable) {
$config = $this->configurationManager->GetConfig();
$variableArray = explode('=', $variable);
$config[$variableArray[0]] = $variableArray[1];
$this->configurationManager->WriteConfig($config);
sleep(1);
}
$envs = $container->GetEnvironmentVariables()->GetVariables();
// Special thing for the nextcloud container
if ($container->GetIdentifier() === 'nextcloud-aio-nextcloud') {