diff --git a/manual-install/update-yaml.sh b/manual-install/update-yaml.sh index 6fc03120804..ca50abcceca 100644 --- a/manual-install/update-yaml.sh +++ b/manual-install/update-yaml.sh @@ -5,11 +5,11 @@ sed -i 's|","location":"|:|g' /tmp/containers.json sed -i 's|","writeable":false|:ro"|g' /tmp/containers.json sed -i 's|","writeable":true|:rw"|g' /tmp/containers.json OUTPUT="$(cat /tmp/containers.json)" -OUTPUT="$(echo "$OUTPUT" | jq 'del(.production[].internalPorts)')" -OUTPUT="$(echo "$OUTPUT" | jq 'del(.production[].secrets)')" -OUTPUT="$(echo "$OUTPUT" | jq 'del(.production[] | select(.identifier == "nextcloud-aio-watchtower"))')" -OUTPUT="$(echo "$OUTPUT" | jq 'del(.production[] | select(.identifier == "nextcloud-aio-domaincheck"))')" -OUTPUT="$(echo "$OUTPUT" | jq 'del(.production[] | select(.identifier == "nextcloud-aio-borgbackup"))')" +OUTPUT="$(echo "$OUTPUT" | jq 'del(.services[].internal_port)')" +OUTPUT="$(echo "$OUTPUT" | jq 'del(.services[].secrets)')" +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"))')" snap install yq mkdir -p ./manual-install @@ -17,16 +17,9 @@ echo "$OUTPUT" | yq -P > ./manual-install/containers.yml cd manual-install || exit sed -i "s|'||g" containers.yml -sed -i 's|production:|services:|' containers.yml -sed -i 's|- identifier:| container_name:|' containers.yml -sed -i 's|restartPolicy:|restart:|' containers.yml -sed -i 's|environmentVariables:|environment:|' containers.yml -sed -i '/displayName:/d' containers.yml -sed -i 's|maxShutdownTime:|stop_grace_period:|' containers.yml +sed -i '/display_name:/d' containers.yml sed -i '/stop_grace_period:/s/$/s/' containers.yml -sed -i 's|containerName:|image:|' containers.yml sed -i '/: \[\]/d' containers.yml -sed -i 's|dependsOn:|depends_on:|' containers.yml sed -i 's|- name: |- |' containers.yml TCP="$(grep -oP '[%A-Z0-9_]+/tcp' containers.yml | sort -u)" diff --git a/php/containers-schema.json b/php/containers-schema.json index 1a668d3892d..b13da609683 100644 --- a/php/containers-schema.json +++ b/php/containers-schema.json @@ -4,41 +4,38 @@ "additionalProperties": false, "minProperties": 1, "properties": { - "production": { + "services": { "type": "array", "items": { "type": "object", "additionalProperties": false, "minProperties": 11, "properties": { - "containerName": { + "image": { "type": "string" }, - "dependsOn": { + "depends_on": { "type": "array", "items": { "type": "string" } }, - "displayName": { + "display_name": { "type": "string" }, - "environmentVariables": { + "environment": { "type": "array", "items": { "type": "string" } }, - "identifier": { + "container_name": { "type": "string" }, - "internalPorts": { - "type": "array", - "items": { - "type": "string" - } + "internal_port": { + "type": "string" }, - "maxShutdownTime": { + "stop_grace_period": { "type": "integer" }, "ports": { @@ -47,11 +44,14 @@ "type": "string" } }, - "restartPolicy": { + "restart": { "type": "string" }, "secrets": { - "type": "array" + "type": "array", + "items": { + "type": "string" + } }, "volumes": { "type": "array", diff --git a/php/containers.json b/php/containers.json index 77bbcb76381..2f49c6deba4 100644 --- a/php/containers.json +++ b/php/containers.json @@ -1,23 +1,21 @@ { - "production": [ + "services": [ { - "identifier": "nextcloud-aio-apache", - "dependsOn": [ + "container_name": "nextcloud-aio-apache", + "depends_on": [ "nextcloud-aio-onlyoffice", "nextcloud-aio-collabora", "nextcloud-aio-talk", "nextcloud-aio-nextcloud" ], - "displayName": "Apache", - "containerName": "nextcloud/aio-apache", + "display_name": "Apache", + "image": "nextcloud/aio-apache", "ports": [ "%APACHE_PORT%/tcp" ], - "internalPorts": [ - "%APACHE_PORT%" - ], + "internal_port": "%APACHE_PORT%", "secrets": [], - "environmentVariables": [ + "environment": [ "NC_DOMAIN=%NC_DOMAIN%", "NEXTCLOUD_HOST=nextcloud-aio-nextcloud", "COLLABORA_HOST=nextcloud-aio-collabora", @@ -40,18 +38,16 @@ "writeable": true } ], - "maxShutdownTime": 10, - "restartPolicy": "unless-stopped" + "stop_grace_period": 10, + "restart": "unless-stopped" }, { - "identifier": "nextcloud-aio-database", - "dependsOn": [], - "displayName": "Database", - "containerName": "nextcloud/aio-postgresql", + "container_name": "nextcloud-aio-database", + "depends_on": [], + "display_name": "Database", + "image": "nextcloud/aio-postgresql", "ports": [], - "internalPorts": [ - "5432" - ], + "internal_port": "5432", "secrets": [ "DATABASE_PASSWORD" ], @@ -67,31 +63,29 @@ "writeable": true } ], - "environmentVariables": [ + "environment": [ "POSTGRES_PASSWORD=%DATABASE_PASSWORD%", "POSTGRES_DB=nextcloud_database", "POSTGRES_USER=nextcloud", "TZ=%TIMEZONE%", "PGTZ=%TIMEZONE%" ], - "maxShutdownTime": 1800, - "restartPolicy": "unless-stopped" + "stop_grace_period": 1800, + "restart": "unless-stopped" }, { - "identifier": "nextcloud-aio-nextcloud", - "dependsOn": [ + "container_name": "nextcloud-aio-nextcloud", + "depends_on": [ "nextcloud-aio-database", "nextcloud-aio-redis", "nextcloud-aio-clamav", "nextcloud-aio-fulltextsearch", "nextcloud-aio-imaginary" ], - "displayName": "Nextcloud", - "containerName": "nextcloud/aio-nextcloud", + "display_name": "Nextcloud", + "image": "nextcloud/aio-nextcloud", "ports": [], - "internalPorts": [ - "9000" - ], + "internal_port": "9000", "secrets": [ "DATABASE_PASSWORD", "REDIS_PASSWORD", @@ -121,7 +115,7 @@ "writeable": false } ], - "environmentVariables": [ + "environment": [ "POSTGRES_HOST=nextcloud-aio-database", "POSTGRES_PASSWORD=%DATABASE_PASSWORD%", "POSTGRES_DB=nextcloud_database", @@ -162,19 +156,17 @@ "ADDITIONAL_APKS=%NEXTCLOUD_ADDITIONAL_APKS%", "ADDITIONAL_PHP_EXTENSIONS=%NEXTCLOUD_ADDITIONAL_PHP_EXTENSIONS%" ], - "maxShutdownTime": 10, - "restartPolicy": "unless-stopped" + "stop_grace_period": 10, + "restart": "unless-stopped" }, { - "identifier": "nextcloud-aio-redis", - "dependsOn": [], - "displayName": "Redis", - "containerName": "nextcloud/aio-redis", + "container_name": "nextcloud-aio-redis", + "depends_on": [], + "display_name": "Redis", + "image": "nextcloud/aio-redis", "ports": [], - "internalPorts": [ - "6379" - ], - "environmentVariables": [ + "internal_port": "6379", + "environment": [ "REDIS_HOST_PASSWORD=%REDIS_PASSWORD%", "TZ=%TIMEZONE%" ], @@ -189,19 +181,17 @@ "REDIS_PASSWORD", "ONLYOFFICE_SECRET" ], - "maxShutdownTime": 10, - "restartPolicy": "unless-stopped" + "stop_grace_period": 10, + "restart": "unless-stopped" }, { - "identifier": "nextcloud-aio-collabora", - "dependsOn": [], - "displayName": "Collabora", - "containerName": "nextcloud/aio-collabora", + "container_name": "nextcloud-aio-collabora", + "depends_on": [], + "display_name": "Collabora", + "image": "nextcloud/aio-collabora", "ports": [], - "internalPorts": [ - "9980" - ], - "environmentVariables": [ + "internal_port": "9980", + "environment": [ "aliasgroup1=https://%NC_DOMAIN%:443", "extra_params=--o:ssl.enable=false --o:ssl.termination=true --o:logging.level=warning --o:home_mode.enable=true %COLLABORA_SECCOMP_POLICY%", "dictionaries=%COLLABORA_DICTIONARIES%", @@ -215,22 +205,20 @@ } ], "secrets": [], - "maxShutdownTime": 10, - "restartPolicy": "unless-stopped" + "stop_grace_period": 10, + "restart": "unless-stopped" }, { - "identifier": "nextcloud-aio-talk", - "dependsOn": [], - "displayName": "Talk", - "containerName": "nextcloud/aio-talk", + "container_name": "nextcloud-aio-talk", + "depends_on": [], + "display_name": "Talk", + "image": "nextcloud/aio-talk", "ports": [ "%TALK_PORT%/tcp", "%TALK_PORT%/udp" ], - "internalPorts": [ - "%TALK_PORT%" - ], - "environmentVariables": [ + "internal_port": "%TALK_PORT%", + "environment": [ "NC_DOMAIN=%NC_DOMAIN%", "TURN_SECRET=%TURN_SECRET%", "SIGNALING_SECRET=%SIGNALING_SECRET%", @@ -244,17 +232,17 @@ "SIGNALING_SECRET", "JANUS_API_KEY" ], - "maxShutdownTime": 10, - "restartPolicy": "unless-stopped" + "stop_grace_period": 10, + "restart": "unless-stopped" }, { - "identifier": "nextcloud-aio-borgbackup", - "dependsOn": [], - "displayName": "Borgbackup", - "containerName": "nextcloud/aio-borgbackup", + "container_name": "nextcloud-aio-borgbackup", + "depends_on": [], + "display_name": "Borgbackup", + "image": "nextcloud/aio-borgbackup", "ports": [], - "internalPorts": [], - "environmentVariables": [ + "internal_port": "", + "environment": [ "BORG_PASSWORD=%BORGBACKUP_PASSWORD%", "BORG_MODE=%BORGBACKUP_MODE%", "SELECTED_RESTORE_TIME=%SELECTED_RESTORE_TIME%", @@ -317,17 +305,17 @@ "secrets": [ "BORGBACKUP_PASSWORD" ], - "maxShutdownTime": 10, - "restartPolicy": "" + "stop_grace_period": 10, + "restart": "" }, { - "identifier": "nextcloud-aio-watchtower", - "dependsOn": [], - "displayName": "Watchtower", - "containerName": "nextcloud/aio-watchtower", + "container_name": "nextcloud-aio-watchtower", + "depends_on": [], + "display_name": "Watchtower", + "image": "nextcloud/aio-watchtower", "ports": [], - "internalPorts": [], - "environmentVariables": [ + "internal_port": "", + "environment": [ "CONTAINER_TO_UPDATE=nextcloud-aio-mastercontainer" ], "volumes": [ @@ -338,19 +326,19 @@ } ], "secrets": [], - "maxShutdownTime": 10, - "restartPolicy": "" + "stop_grace_period": 10, + "restart": "" }, { - "dependsOn": [], - "identifier": "nextcloud-aio-domaincheck", - "displayName": "Domaincheck", - "containerName": "nextcloud/aio-domaincheck", + "depends_on": [], + "container_name": "nextcloud-aio-domaincheck", + "display_name": "Domaincheck", + "image": "nextcloud/aio-domaincheck", "ports": [ "%APACHE_PORT%/tcp" ], - "internalPorts": [], - "environmentVariables": [ + "internal_port": "", + "environment": [ "INSTANCE_ID=%INSTANCE_ID%", "APACHE_PORT=%APACHE_PORT%" ], @@ -358,19 +346,17 @@ "secrets": [ "INSTANCE_ID" ], - "maxShutdownTime": 1, - "restartPolicy": "" + "stop_grace_period": 1, + "restart": "" }, { - "identifier": "nextcloud-aio-clamav", - "dependsOn": [], - "displayName": "ClamAV", - "containerName": "nextcloud/aio-clamav", + "container_name": "nextcloud-aio-clamav", + "depends_on": [], + "display_name": "ClamAV", + "image": "nextcloud/aio-clamav", "ports": [], - "internalPorts": [ - "3310" - ], - "environmentVariables": [ + "internal_port": "3310", + "environment": [ "TZ=%TIMEZONE%", "CLAMD_STARTUP_TIMEOUT=90" ], @@ -382,19 +368,17 @@ } ], "secrets": [], - "maxShutdownTime": 10, - "restartPolicy": "unless-stopped" + "stop_grace_period": 10, + "restart": "unless-stopped" }, { - "identifier": "nextcloud-aio-onlyoffice", - "dependsOn": [], - "displayName": "OnlyOffice", - "containerName": "nextcloud/aio-onlyoffice", + "container_name": "nextcloud-aio-onlyoffice", + "depends_on": [], + "display_name": "OnlyOffice", + "image": "nextcloud/aio-onlyoffice", "ports": [], - "internalPorts": [ - "80" - ], - "environmentVariables": [ + "internal_port": "80", + "environment": [ "TZ=%TIMEZONE%", "JWT_ENABLED=true", "JWT_HEADER=AuthorizationJwt", @@ -410,36 +394,32 @@ "secrets": [ "ONLYOFFICE_SECRET" ], - "maxShutdownTime": 10, - "restartPolicy": "unless-stopped" + "stop_grace_period": 10, + "restart": "unless-stopped" }, { - "identifier": "nextcloud-aio-imaginary", - "dependsOn": [], - "displayName": "Imaginary", - "containerName": "nextcloud/aio-imaginary", + "container_name": "nextcloud-aio-imaginary", + "depends_on": [], + "display_name": "Imaginary", + "image": "nextcloud/aio-imaginary", "ports": [], - "internalPorts": [ - "9000" - ], - "environmentVariables": [ + "internal_port": "9000", + "environment": [ "TZ=%TIMEZONE%" ], "volumes": [], "secrets": [], - "maxShutdownTime": 10, - "restartPolicy": "unless-stopped" + "stop_grace_period": 10, + "restart": "unless-stopped" }, { - "identifier": "nextcloud-aio-fulltextsearch", - "dependsOn": [], - "displayName": "Fulltextsearch", - "containerName": "nextcloud/aio-fulltextsearch", + "container_name": "nextcloud-aio-fulltextsearch", + "depends_on": [], + "display_name": "Fulltextsearch", + "image": "nextcloud/aio-fulltextsearch", "ports": [], - "internalPorts": [ - "9200" - ], - "environmentVariables": [ + "internal_port": "9200", + "environment": [ "TZ=%TIMEZONE%", "discovery.type=single-node", "ES_JAVA_OPTS=-Xms1024M -Xmx1024M" @@ -452,8 +432,8 @@ } ], "secrets": [], - "maxShutdownTime": 10, - "restartPolicy": "unless-stopped" + "stop_grace_period": 10, + "restart": "unless-stopped" } ] } diff --git a/php/psalm-baseline.xml b/php/psalm-baseline.xml index e62c34f047f..ce18679f371 100644 --- a/php/psalm-baseline.xml +++ b/php/psalm-baseline.xml @@ -46,7 +46,7 @@ $internalPort - $container->GetInternalPorts() !== null + $container->GetInternalPort() !== null diff --git a/php/src/Container/Container.php b/php/src/Container/Container.php index c1330da32e5..9697911b300 100644 --- a/php/src/Container/Container.php +++ b/php/src/Container/Container.php @@ -14,7 +14,7 @@ class Container { private string $restartPolicy; private int $maxShutdownTime; private ContainerPorts $ports; - private ContainerInternalPorts $internalPorts; + private string $internalPorts; private ContainerVolumes $volumes; private ContainerEnvironmentVariables $containerEnvironmentVariables; /** @var string[] */ @@ -30,7 +30,7 @@ public function __construct( string $restartPolicy, int $maxShutdownTime, ContainerPorts $ports, - ContainerInternalPorts $internalPorts, + string $internalPorts, ContainerVolumes $volumes, ContainerEnvironmentVariables $containerEnvironmentVariables, array $dependsOn, @@ -79,7 +79,7 @@ public function GetPorts() : ContainerPorts { return $this->ports; } - public function GetInternalPorts() : ContainerInternalPorts { + public function GetInternalPort() : string { return $this->internalPorts; } diff --git a/php/src/Container/ContainerInternalPorts.php b/php/src/Container/ContainerInternalPorts.php deleted file mode 100644 index fb0716bf23d..00000000000 --- a/php/src/Container/ContainerInternalPorts.php +++ /dev/null @@ -1,19 +0,0 @@ -internalPorts[] = $internalPort; - } - - /** - * @return string[] - */ - public function GetInternalPorts() : array { - return $this->internalPorts; - } -} diff --git a/php/src/ContainerDefinitionFetcher.php b/php/src/ContainerDefinitionFetcher.php index f2d30804cbc..8a5341bf7f8 100644 --- a/php/src/ContainerDefinitionFetcher.php +++ b/php/src/ContainerDefinitionFetcher.php @@ -5,7 +5,6 @@ use AIO\Container\Container; use AIO\Container\ContainerEnvironmentVariables; use AIO\Container\ContainerPorts; -use AIO\Container\ContainerInternalPorts; use AIO\Container\ContainerVolume; use AIO\Container\ContainerVolumes; use AIO\Container\State\RunningState; @@ -48,28 +47,28 @@ private function GetDefinition(bool $latest): array $data = json_decode(file_get_contents(__DIR__ . '/../containers.json'), true); $containers = []; - foreach ($data['production'] as $entry) { - if ($entry['identifier'] === 'nextcloud-aio-clamav') { + foreach ($data['services'] as $entry) { + if ($entry['container_name'] === 'nextcloud-aio-clamav') { if (!$this->configurationManager->isClamavEnabled()) { continue; } - } elseif ($entry['identifier'] === 'nextcloud-aio-onlyoffice') { + } elseif ($entry['container_name'] === 'nextcloud-aio-onlyoffice') { if (!$this->configurationManager->isOnlyofficeEnabled()) { continue; } - } elseif ($entry['identifier'] === 'nextcloud-aio-collabora') { + } elseif ($entry['container_name'] === 'nextcloud-aio-collabora') { if (!$this->configurationManager->isCollaboraEnabled()) { continue; } - } elseif ($entry['identifier'] === 'nextcloud-aio-talk') { + } elseif ($entry['container_name'] === 'nextcloud-aio-talk') { if (!$this->configurationManager->isTalkEnabled()) { continue; } - } elseif ($entry['identifier'] === 'nextcloud-aio-imaginary') { + } elseif ($entry['container_name'] === 'nextcloud-aio-imaginary') { if (!$this->configurationManager->isImaginaryEnabled()) { continue; } - } elseif ($entry['identifier'] === 'nextcloud-aio-fulltextsearch') { + } elseif ($entry['container_name'] === 'nextcloud-aio-fulltextsearch') { if (!$this->configurationManager->isFulltextsearchEnabled()) { continue; } @@ -87,14 +86,10 @@ private function GetDefinition(bool $latest): array $ports->AddPort($port); } - $internalPorts = new ContainerInternalPorts(); - foreach ($entry['internalPorts'] as $internalPort) { - if($internalPort === '%APACHE_PORT%') { - $internalPort = $this->configurationManager->GetApachePort(); - } elseif($internalPort === '%TALK_PORT%') { - $internalPort = $this->configurationManager->GetTalkPort(); - } - $internalPorts->AddInternalPort($internalPort); + if($entry['internal_port'] === '%APACHE_PORT%') { + $entry['internal_port'] = $this->configurationManager->GetApachePort(); + } elseif($entry['internal_port'] === '%TALK_PORT%') { + $entry['internal_port'] = $this->configurationManager->GetTalkPort(); } $volumes = new ContainerVolumes(); @@ -142,7 +137,7 @@ private function GetDefinition(bool $latest): array } $dependsOn = []; - foreach ($entry['dependsOn'] as $value) { + foreach ($entry['depends_on'] as $value) { if ($value === 'nextcloud-aio-clamav') { if (!$this->configurationManager->isClamavEnabled()) { continue; @@ -172,18 +167,18 @@ private function GetDefinition(bool $latest): array } $variables = new ContainerEnvironmentVariables(); - foreach ($entry['environmentVariables'] as $value) { + foreach ($entry['environment'] as $value) { $variables->AddVariable($value); } $containers[] = new Container( - $entry['identifier'], - $entry['displayName'], - $entry['containerName'], - $entry['restartPolicy'], - $entry['maxShutdownTime'], + $entry['container_name'], + $entry['display_name'], + $entry['image'], + $entry['restart'], + $entry['stop_grace_period'], $ports, - $internalPorts, + $entry['internal_port'], $volumes, $variables, $dependsOn, diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index 9550dd44d69..eed07c35e61 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -124,15 +124,13 @@ public function GetContainerStartingState(Container $container) : IContainerStat } $containerName = $container->GetIdentifier(); - if ($container->GetInternalPorts() !== null) { - foreach($container->GetInternalPorts()->GetInternalPorts() as $internalPort) { - $connection = @fsockopen($containerName, $internalPort, $errno, $errstr, 0.1); - if ($connection) { - fclose($connection); - return new RunningState(); - } else { - return new StartingState(); - } + if ($container->GetInternalPort() !== "") { + $connection = @fsockopen($containerName, (int)$container->GetInternalPort(), $errno, $errstr, 0.1); + if ($connection) { + fclose($connection); + return new RunningState(); + } else { + return new StartingState(); } } else { return new RunningState();