Skip to content

Commit

Permalink
allow to define nextcloud_exec_commands in containers definition
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 May 26, 2023
1 parent 3e04dd5 commit df62143
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Containers/nextcloud/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down
13 changes: 0 additions & 13 deletions Containers/nextcloud/activate-collabora.sh

This file was deleted.

23 changes: 23 additions & 0 deletions Containers/nextcloud/run-exec-commands.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions Containers/nextcloud/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions manual-install/update-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"))')"
Expand Down
8 changes: 8 additions & 0 deletions php/containers-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 5 additions & 1 deletion php/containers.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions php/src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Container {
private bool $apparmorUnconfined;
/** @var string[] */
private array $backupVolumes;
private array $nextcloudExecCommands;
private DockerActionManager $dockerActionManager;

public function __construct(
Expand All @@ -48,6 +49,7 @@ public function __construct(
int $shmSize,
bool $apparmorUnconfined,
array $backupVolumes,
array $nextcloudExecCommands,
DockerActionManager $dockerActionManager
) {
$this->identifier = $identifier;
Expand All @@ -66,6 +68,7 @@ public function __construct(
$this->shmSize = $shmSize;
$this->apparmorUnconfined = $apparmorUnconfined;
$this->backupVolumes = $backupVolumes;
$this->nextcloudExecCommands = $nextcloudExecCommands;
$this->dockerActionManager = $dockerActionManager;
}

Expand Down Expand Up @@ -148,6 +151,10 @@ public function GetDependsOn() : array {
return $this->dependsOn;
}

public function GetNextcloudExecCommands() : array {
return $this->nextcloudExecCommands;
}

public function GetEnvironmentVariables() : ContainerEnvironmentVariables {
return $this->containerEnvironmentVariables;
}
Expand Down
6 changes: 6 additions & 0 deletions php/src/ContainerDefinitionFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ private function GetDefinition(bool $latest): array
$backupVolumes = $entry['backup_volumes'];
}

$nextcloudExecCommands = [];
if (isset($entry['nextcloud_exec_commands'])) {
$nextcloudExecCommands = $entry['nextcloud_exec_commands'];
}

$containers[] = new Container(
$entry['container_name'],
$displayName,
Expand All @@ -250,6 +255,7 @@ private function GetDefinition(bool $latest): array
$shmSize,
$apparmorUnconfined,
$backupVolumes,
$nextcloudExecCommands,
$this->container->get(DockerActionManager::class)
);
}
Expand Down
24 changes: 24 additions & 0 deletions php/src/Docker/DockerActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ public function CreateContainer(Container $container) : void {
}

$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=')) {
Expand Down Expand Up @@ -533,6 +537,26 @@ private function getAllBackupVolumes() : array {
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));
Expand Down

0 comments on commit df62143

Please sign in to comment.