From e4de4dcb67a9c5f9d9b39ff62ca2735f45e5db01 Mon Sep 17 00:00:00 2001 From: Simon L Date: Mon, 1 May 2023 18:37:33 +0200 Subject: [PATCH] allow to define nextcloud_exec_commands in containers definition Signed-off-by: Simon L --- Containers/nextcloud/Dockerfile | 2 +- Containers/nextcloud/activate-collabora.sh | 13 ------------ Containers/nextcloud/run-exec-commands.sh | 23 +++++++++++++++++++++ Containers/nextcloud/supervisord.conf | 4 ++-- manual-install/update-yaml.sh | 1 + php/containers-schema.json | 8 ++++++++ php/containers.json | 6 +++++- php/src/Container/Container.php | 7 +++++++ php/src/ContainerDefinitionFetcher.php | 6 ++++++ php/src/Docker/DockerActionManager.php | 24 ++++++++++++++++++++++ 10 files changed, 77 insertions(+), 17 deletions(-) delete mode 100644 Containers/nextcloud/activate-collabora.sh create mode 100644 Containers/nextcloud/run-exec-commands.sh diff --git a/Containers/nextcloud/Dockerfile b/Containers/nextcloud/Dockerfile index 38939287..89a3d692 100644 --- a/Containers/nextcloud/Dockerfile +++ b/Containers/nextcloud/Dockerfile @@ -241,7 +241,7 @@ RUN set -ex; \ chmod +x /cron.sh && \ chmod +x /notify.sh && \ chmod +x /notify-all.sh && \ - chmod +x /activate-collabora.sh && \ + chmod +x /run-exec-commands.sh && \ chmod +x /healthcheck.sh RUN set -ex; \ diff --git a/Containers/nextcloud/activate-collabora.sh b/Containers/nextcloud/activate-collabora.sh deleted file mode 100644 index 0c10ea02..00000000 --- a/Containers/nextcloud/activate-collabora.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -if [ "$COLLABORA_ENABLED" != yes ]; then - # Basically sleep for forever if collabora is not enabled - sleep inf -fi -while ! nc -z "$NC_DOMAIN" 443; do - sleep 5 -done -sleep 10 -echo "Activating collabora config..." -php /var/www/html/occ richdocuments:activate-config -sleep inf diff --git a/Containers/nextcloud/run-exec-commands.sh b/Containers/nextcloud/run-exec-commands.sh new file mode 100644 index 00000000..5df4962c --- /dev/null +++ b/Containers/nextcloud/run-exec-commands.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +while ! nc -z "$NC_DOMAIN" 443; do + sleep 5 +done +sleep 10 + +if [ -n "$NEXTCLOUD_EXEC_COMMANDS" ]; then + echo "#!/bin/bash" > /tmp/nextcloud-exec-commands + echo "$NEXTCLOUD_EXEC_COMMANDS" >> /tmp/nextcloud-exec-commands + if ! grep "one-click-instance" /tmp/nextcloud-exec-commands; then + bash /tmp/nextcloud-exec-commands + rm /tmp/nextcloud-exec-commands + fi +else + # Collabora must work also if using manual-install + if [ "$COLLABORA_ENABLED" = yes ]; then + echo "Activating collabora config..." + php /var/www/html/occ richdocuments:activate-config + fi +fi + +sleep inf diff --git a/Containers/nextcloud/supervisord.conf b/Containers/nextcloud/supervisord.conf index e54d13c0..23e85ca6 100644 --- a/Containers/nextcloud/supervisord.conf +++ b/Containers/nextcloud/supervisord.conf @@ -33,10 +33,10 @@ stderr_logfile_maxbytes=0 command=/var/www/html/custom_apps/notify_push/bin/%(ENV_CPU_ARCH)s/notify_push /var/www/html/config/config.php --port 7867 --redis-url redis://:%(ENV_REDIS_HOST_PASSWORD)s@%(ENV_REDIS_HOST)s user=www-data -[program:activate-collabora] +[program:run-exec-commands] stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr_logfile_maxbytes=0 -command=/activate-collabora.sh +command=/run-exec-commands.sh user=www-data diff --git a/manual-install/update-yaml.sh b/manual-install/update-yaml.sh index c37a45c1..98e08bfe 100644 --- a/manual-install/update-yaml.sh +++ b/manual-install/update-yaml.sh @@ -16,6 +16,7 @@ OUTPUT="$(echo "$OUTPUT" | jq 'del(.services[].internal_port)')" OUTPUT="$(echo "$OUTPUT" | jq 'del(.services[].secrets)')" OUTPUT="$(echo "$OUTPUT" | jq 'del(.services[].devices)')" OUTPUT="$(echo "$OUTPUT" | jq 'del(.services[].backup_volumes)')" +OUTPUT="$(echo "$OUTPUT" | jq 'del(.services[].nextcloud_exec_commands)')" OUTPUT="$(echo "$OUTPUT" | jq 'del(.services[] | select(.container_name == "nextcloud-aio-watchtower"))')" OUTPUT="$(echo "$OUTPUT" | jq 'del(.services[] | select(.container_name == "nextcloud-aio-domaincheck"))')" OUTPUT="$(echo "$OUTPUT" | jq 'del(.services[] | select(.container_name == "nextcloud-aio-borgbackup"))')" diff --git a/php/containers-schema.json b/php/containers-schema.json index e2d37767..69c04100 100644 --- a/php/containers-schema.json +++ b/php/containers-schema.json @@ -113,6 +113,14 @@ "pattern": "^nextcloud_aio_[a-z_]+$" } }, + "nextcloud_exec_commands": { + "type": "array", + "items": { + "type": "string", + "pattern": "^(php /var/www/html/occ .*|echo .*)$", + "minlength": 1 + } + }, "volumes": { "type": "array", "items": { diff --git a/php/containers.json b/php/containers.json index eb16c316..ed2bd5cd 100644 --- a/php/containers.json +++ b/php/containers.json @@ -228,7 +228,11 @@ "writeable": true } ], - "restart": "unless-stopped" + "restart": "unless-stopped", + "nextcloud_exec_commands": [ + "echo 'Activating collabora config...'", + "php /var/www/html/occ richdocuments:activate-config" + ] }, { "container_name": "nextcloud-aio-talk", diff --git a/php/src/Container/Container.php b/php/src/Container/Container.php index 0ca8e872..a89374c6 100644 --- a/php/src/Container/Container.php +++ b/php/src/Container/Container.php @@ -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; } diff --git a/php/src/ContainerDefinitionFetcher.php b/php/src/ContainerDefinitionFetcher.php index 75bd2c2e..95dcbd4f 100644 --- a/php/src/ContainerDefinitionFetcher.php +++ b/php/src/ContainerDefinitionFetcher.php @@ -233,6 +233,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, @@ -250,6 +255,7 @@ class ContainerDefinitionFetcher $shmSize, $apparmorUnconfined, $backupVolumes, + $nextcloudExecCommands, $this->container->get(DockerActionManager::class) ); } diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index c11f16a0..241a8365 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -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=')) { @@ -533,6 +537,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));