Merge pull request #2454 from nextcloud/enh/noid/nextcloud-exec-commands

allow to define nextcloud_exec_commands in containers definition
This commit is contained in:
Simon L 2023-05-30 11:42:46 +02:00 committed by GitHub
commit d037ebba66
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 77 additions and 17 deletions

View file

@ -29,6 +29,7 @@ class Container {
private bool $apparmorUnconfined;
/** @var string[] */
private array $backupVolumes;
private array $nextcloudExecCommands;
private DockerActionManager $dockerActionManager;
public function __construct(
@ -48,6 +49,7 @@ class Container {
int $shmSize,
bool $apparmorUnconfined,
array $backupVolumes,
array $nextcloudExecCommands,
DockerActionManager $dockerActionManager
) {
$this->identifier = $identifier;
@ -66,6 +68,7 @@ class Container {
$this->shmSize = $shmSize;
$this->apparmorUnconfined = $apparmorUnconfined;
$this->backupVolumes = $backupVolumes;
$this->nextcloudExecCommands = $nextcloudExecCommands;
$this->dockerActionManager = $dockerActionManager;
}
@ -148,6 +151,10 @@ class Container {
return $this->dependsOn;
}
public function GetNextcloudExecCommands() : array {
return $this->nextcloudExecCommands;
}
public function GetEnvironmentVariables() : ContainerEnvironmentVariables {
return $this->containerEnvironmentVariables;
}

View file

@ -249,6 +249,11 @@ class ContainerDefinitionFetcher
$backupVolumes = $entry['backup_volumes'];
}
$nextcloudExecCommands = [];
if (isset($entry['nextcloud_exec_commands'])) {
$nextcloudExecCommands = $entry['nextcloud_exec_commands'];
}
$containers[] = new Container(
$entry['container_name'],
$displayName,
@ -266,6 +271,7 @@ class ContainerDefinitionFetcher
$shmSize,
$apparmorUnconfined,
$backupVolumes,
$nextcloudExecCommands,
$this->container->get(DockerActionManager::class)
);
}

View file

@ -235,6 +235,10 @@ class DockerActionManager
}
$envs = $container->GetEnvironmentVariables()->GetVariables();
// Special thing for the nextcloud container
if ($container->GetIdentifier() === 'nextcloud-aio-nextcloud') {
$envs[] = $this->GetAllNextcloudExecCommands();
}
foreach($envs as $key => $env) {
// TODO: This whole block below is a hack and needs to get reworked in order to support multiple substitutions per line by default for all envs
if (str_starts_with($env, 'extra_params=')) {
@ -535,6 +539,26 @@ class DockerActionManager
return array_unique($backupVolumesArrayFlat);
}
private function GetNextcloudExecCommands(string $id) : string
{
$container = $this->containerDefinitionFetcher->GetContainerById($id);
$nextcloudExecCommands = '';
foreach ($container->GetNextcloudExecCommands() as $execCommand) {
$nextcloudExecCommands .= $execCommand . PHP_EOL;
}
foreach ($container->GetDependsOn() as $dependency) {
$nextcloudExecCommands .= $this->GetNextcloudExecCommands($dependency);
}
return $nextcloudExecCommands;
}
private function GetAllNextcloudExecCommands() : string
{
$id = 'nextcloud-aio-apache';
return 'NEXTCLOUD_EXEC_COMMANDS=' . $this->GetNextcloudExecCommands($id);
}
private function GetRepoDigestsOfContainer(string $containerName) : ?array {
try {
$containerUrl = $this->BuildApiUrl(sprintf('containers/%s/json', $containerName));