Merge pull request #1604 from nextcloud/enh/noid/improve-containers-schema

improve containeers schema
This commit is contained in:
Simon L 2023-01-02 22:19:09 +01:00 committed by GitHub
commit cf27112c04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 130 additions and 146 deletions

View file

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
jq -c . ./php/containers.json > /tmp/containers.json jq -c . ./php/containers.json > /tmp/containers.json
sed -i 's|aio_services_v1|services|g' /tmp/containers.json
sed -i 's|","destination":"|:|g' /tmp/containers.json sed -i 's|","destination":"|:|g' /tmp/containers.json
sed -i 's|","writeable":false|:ro"|g' /tmp/containers.json sed -i 's|","writeable":false|:ro"|g' /tmp/containers.json
sed -i 's|","writeable":true|:rw"|g' /tmp/containers.json sed -i 's|","writeable":true|:rw"|g' /tmp/containers.json

View file

@ -1,15 +1,16 @@
{ {
"type": "object", "type": "object",
"description": "AIO containers definition schema", "description": "AIO containers definition schema",
"additionalProperties": false,
"minProperties": 1, "minProperties": 1,
"required": ["aio_services_v1"],
"properties": { "properties": {
"services": { "aio_services_v1": {
"type": "array", "type": "array",
"items": { "items": {
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"minProperties": 11, "minProperties": 2,
"required": ["image", "container_name"],
"properties": { "properties": {
"image": { "image": {
"type": "string" "type": "string"

View file

@ -1,5 +1,5 @@
{ {
"services": [ "aio_services_v1": [
{ {
"container_name": "nextcloud-aio-apache", "container_name": "nextcloud-aio-apache",
"depends_on": [ "depends_on": [
@ -18,7 +18,6 @@
} }
], ],
"internal_port": "%APACHE_PORT%", "internal_port": "%APACHE_PORT%",
"secrets": [],
"environment": [ "environment": [
"NC_DOMAIN=%NC_DOMAIN%", "NC_DOMAIN=%NC_DOMAIN%",
"NEXTCLOUD_HOST=nextcloud-aio-nextcloud", "NEXTCLOUD_HOST=nextcloud-aio-nextcloud",
@ -42,15 +41,12 @@
"writeable": true "writeable": true
} }
], ],
"stop_grace_period": 10,
"restart": "unless-stopped" "restart": "unless-stopped"
}, },
{ {
"container_name": "nextcloud-aio-database", "container_name": "nextcloud-aio-database",
"depends_on": [],
"display_name": "Database", "display_name": "Database",
"image": "nextcloud/aio-postgresql", "image": "nextcloud/aio-postgresql",
"ports": [],
"internal_port": "5432", "internal_port": "5432",
"secrets": [ "secrets": [
"DATABASE_PASSWORD" "DATABASE_PASSWORD"
@ -88,7 +84,6 @@
], ],
"display_name": "Nextcloud", "display_name": "Nextcloud",
"image": "nextcloud/aio-nextcloud", "image": "nextcloud/aio-nextcloud",
"ports": [],
"internal_port": "9000", "internal_port": "9000",
"secrets": [ "secrets": [
"DATABASE_PASSWORD", "DATABASE_PASSWORD",
@ -160,15 +155,12 @@
"ADDITIONAL_APKS=%NEXTCLOUD_ADDITIONAL_APKS%", "ADDITIONAL_APKS=%NEXTCLOUD_ADDITIONAL_APKS%",
"ADDITIONAL_PHP_EXTENSIONS=%NEXTCLOUD_ADDITIONAL_PHP_EXTENSIONS%" "ADDITIONAL_PHP_EXTENSIONS=%NEXTCLOUD_ADDITIONAL_PHP_EXTENSIONS%"
], ],
"stop_grace_period": 10,
"restart": "unless-stopped" "restart": "unless-stopped"
}, },
{ {
"container_name": "nextcloud-aio-redis", "container_name": "nextcloud-aio-redis",
"depends_on": [],
"display_name": "Redis", "display_name": "Redis",
"image": "nextcloud/aio-redis", "image": "nextcloud/aio-redis",
"ports": [],
"internal_port": "6379", "internal_port": "6379",
"environment": [ "environment": [
"REDIS_HOST_PASSWORD=%REDIS_PASSWORD%", "REDIS_HOST_PASSWORD=%REDIS_PASSWORD%",
@ -185,15 +177,12 @@
"REDIS_PASSWORD", "REDIS_PASSWORD",
"ONLYOFFICE_SECRET" "ONLYOFFICE_SECRET"
], ],
"stop_grace_period": 10,
"restart": "unless-stopped" "restart": "unless-stopped"
}, },
{ {
"container_name": "nextcloud-aio-collabora", "container_name": "nextcloud-aio-collabora",
"depends_on": [],
"display_name": "Collabora", "display_name": "Collabora",
"image": "nextcloud/aio-collabora", "image": "nextcloud/aio-collabora",
"ports": [],
"internal_port": "9980", "internal_port": "9980",
"environment": [ "environment": [
"aliasgroup1=https://%NC_DOMAIN%:443", "aliasgroup1=https://%NC_DOMAIN%:443",
@ -208,13 +197,10 @@
"writeable": true "writeable": true
} }
], ],
"secrets": [],
"stop_grace_period": 10,
"restart": "unless-stopped" "restart": "unless-stopped"
}, },
{ {
"container_name": "nextcloud-aio-talk", "container_name": "nextcloud-aio-talk",
"depends_on": [],
"display_name": "Talk", "display_name": "Talk",
"image": "nextcloud/aio-talk", "image": "nextcloud/aio-talk",
"ports": [ "ports": [
@ -238,22 +224,16 @@
"TZ=%TIMEZONE%", "TZ=%TIMEZONE%",
"TALK_PORT=%TALK_PORT%" "TALK_PORT=%TALK_PORT%"
], ],
"volumes": [],
"secrets": [ "secrets": [
"TURN_SECRET", "TURN_SECRET",
"SIGNALING_SECRET", "SIGNALING_SECRET",
"JANUS_API_KEY" "JANUS_API_KEY"
], ],
"stop_grace_period": 10,
"restart": "unless-stopped" "restart": "unless-stopped"
}, },
{ {
"container_name": "nextcloud-aio-borgbackup", "container_name": "nextcloud-aio-borgbackup",
"depends_on": [],
"display_name": "",
"image": "nextcloud/aio-borgbackup", "image": "nextcloud/aio-borgbackup",
"ports": [],
"internal_port": "",
"environment": [ "environment": [
"BORG_PASSWORD=%BORGBACKUP_PASSWORD%", "BORG_PASSWORD=%BORGBACKUP_PASSWORD%",
"BORG_MODE=%BORGBACKUP_MODE%", "BORG_MODE=%BORGBACKUP_MODE%",
@ -316,17 +296,11 @@
], ],
"secrets": [ "secrets": [
"BORGBACKUP_PASSWORD" "BORGBACKUP_PASSWORD"
], ]
"stop_grace_period": 10,
"restart": ""
}, },
{ {
"container_name": "nextcloud-aio-watchtower", "container_name": "nextcloud-aio-watchtower",
"depends_on": [],
"display_name": "",
"image": "nextcloud/aio-watchtower", "image": "nextcloud/aio-watchtower",
"ports": [],
"internal_port": "",
"environment": [ "environment": [
"CONTAINER_TO_UPDATE=nextcloud-aio-mastercontainer" "CONTAINER_TO_UPDATE=nextcloud-aio-mastercontainer"
], ],
@ -336,15 +310,10 @@
"destination": "/var/run/docker.sock", "destination": "/var/run/docker.sock",
"writeable": false "writeable": false
} }
], ]
"secrets": [],
"stop_grace_period": 10,
"restart": ""
}, },
{ {
"depends_on": [],
"container_name": "nextcloud-aio-domaincheck", "container_name": "nextcloud-aio-domaincheck",
"display_name": "",
"image": "nextcloud/aio-domaincheck", "image": "nextcloud/aio-domaincheck",
"ports": [ "ports": [
{ {
@ -353,24 +322,19 @@
"protocol": "tcp" "protocol": "tcp"
} }
], ],
"internal_port": "",
"environment": [ "environment": [
"INSTANCE_ID=%INSTANCE_ID%", "INSTANCE_ID=%INSTANCE_ID%",
"APACHE_PORT=%APACHE_PORT%" "APACHE_PORT=%APACHE_PORT%"
], ],
"volumes": [],
"secrets": [ "secrets": [
"INSTANCE_ID" "INSTANCE_ID"
], ],
"stop_grace_period": 1, "stop_grace_period": 1
"restart": ""
}, },
{ {
"container_name": "nextcloud-aio-clamav", "container_name": "nextcloud-aio-clamav",
"depends_on": [],
"display_name": "ClamAV", "display_name": "ClamAV",
"image": "nextcloud/aio-clamav", "image": "nextcloud/aio-clamav",
"ports": [],
"internal_port": "3310", "internal_port": "3310",
"environment": [ "environment": [
"TZ=%TIMEZONE%", "TZ=%TIMEZONE%",
@ -383,16 +347,12 @@
"writeable": true "writeable": true
} }
], ],
"secrets": [],
"stop_grace_period": 10,
"restart": "unless-stopped" "restart": "unless-stopped"
}, },
{ {
"container_name": "nextcloud-aio-onlyoffice", "container_name": "nextcloud-aio-onlyoffice",
"depends_on": [],
"display_name": "OnlyOffice", "display_name": "OnlyOffice",
"image": "nextcloud/aio-onlyoffice", "image": "nextcloud/aio-onlyoffice",
"ports": [],
"internal_port": "80", "internal_port": "80",
"environment": [ "environment": [
"TZ=%TIMEZONE%", "TZ=%TIMEZONE%",
@ -410,30 +370,22 @@
"secrets": [ "secrets": [
"ONLYOFFICE_SECRET" "ONLYOFFICE_SECRET"
], ],
"stop_grace_period": 10,
"restart": "unless-stopped" "restart": "unless-stopped"
}, },
{ {
"container_name": "nextcloud-aio-imaginary", "container_name": "nextcloud-aio-imaginary",
"depends_on": [],
"display_name": "Imaginary", "display_name": "Imaginary",
"image": "nextcloud/aio-imaginary", "image": "nextcloud/aio-imaginary",
"ports": [],
"internal_port": "9000", "internal_port": "9000",
"environment": [ "environment": [
"TZ=%TIMEZONE%" "TZ=%TIMEZONE%"
], ],
"volumes": [],
"secrets": [],
"stop_grace_period": 10,
"restart": "unless-stopped" "restart": "unless-stopped"
}, },
{ {
"container_name": "nextcloud-aio-fulltextsearch", "container_name": "nextcloud-aio-fulltextsearch",
"depends_on": [],
"display_name": "Fulltextsearch", "display_name": "Fulltextsearch",
"image": "nextcloud/aio-fulltextsearch", "image": "nextcloud/aio-fulltextsearch",
"ports": [],
"internal_port": "9200", "internal_port": "9200",
"environment": [ "environment": [
"TZ=%TIMEZONE%", "TZ=%TIMEZONE%",
@ -447,8 +399,6 @@
"writeable": true "writeable": true
} }
], ],
"secrets": [],
"stop_grace_period": 10,
"restart": "unless-stopped" "restart": "unless-stopped"
} }
] ]

View file

@ -48,7 +48,7 @@ class ContainerDefinitionFetcher
$data = json_decode(file_get_contents(__DIR__ . '/../containers.json'), true); $data = json_decode(file_get_contents(__DIR__ . '/../containers.json'), true);
$containers = []; $containers = [];
foreach ($data['services'] as $entry) { foreach ($data['aio_services_v1'] as $entry) {
if ($entry['container_name'] === 'nextcloud-aio-clamav') { if ($entry['container_name'] === 'nextcloud-aio-clamav') {
if (!$this->configurationManager->isClamavEnabled()) { if (!$this->configurationManager->isClamavEnabled()) {
continue; continue;
@ -76,118 +76,150 @@ class ContainerDefinitionFetcher
} }
$ports = new ContainerPorts(); $ports = new ContainerPorts();
foreach ($entry['ports'] as $value) { if (isset($entry['ports'])) {
foreach ($entry['ports'] as $value) {
if ($value['port_number'] === '%APACHE_PORT%') {
$value['port_number'] = $this->configurationManager->GetApachePort();
} elseif ($value['port_number'] === '%TALK_PORT%') {
$value['port_number'] = $this->configurationManager->GetTalkPort();
}
if ($value['port_number'] === '%APACHE_PORT%') { if ($value['ip_binding'] === '%APACHE_IP_BINDING%') {
$value['port_number'] = $this->configurationManager->GetApachePort(); $value['ip_binding'] = $this->configurationManager->GetApacheIPBinding();
} elseif ($value['port_number'] === '%TALK_PORT%') { }
$value['port_number'] = $this->configurationManager->GetTalkPort();
$ports->AddPort(
new ContainerPort(
$value['port_number'],
$value['ip_binding'],
$value['protocol']
)
);
} }
if ($value['ip_binding'] === '%APACHE_IP_BINDING%') {
$value['ip_binding'] = $this->configurationManager->GetApacheIPBinding();
}
$ports->AddPort(
new ContainerPort(
$value['port_number'],
$value['ip_binding'],
$value['protocol']
)
);
} }
$volumes = new ContainerVolumes(); $volumes = new ContainerVolumes();
foreach ($entry['volumes'] as $value) { if (isset($entry['volumes'])) {
if($value['source'] === '%BORGBACKUP_HOST_LOCATION%') { foreach ($entry['volumes'] as $value) {
$value['source'] = $this->configurationManager->GetBorgBackupHostLocation(); if($value['source'] === '%BORGBACKUP_HOST_LOCATION%') {
if($value['source'] === '') { $value['source'] = $this->configurationManager->GetBorgBackupHostLocation();
continue; if($value['source'] === '') {
continue;
}
} }
if($value['source'] === '%NEXTCLOUD_MOUNT%') {
$value['source'] = $this->configurationManager->GetNextcloudMount();
if($value['source'] === '') {
continue;
}
} elseif ($value['source'] === '%NEXTCLOUD_DATADIR%') {
$value['source'] = $this->configurationManager->GetNextcloudDatadirMount();
if ($value['source'] === '') {
continue;
}
} elseif ($value['source'] === '%DOCKER_SOCKET_PATH%') {
$value['source'] = $this->configurationManager->GetDockerSocketPath();
if($value['source'] === '') {
continue;
}
} elseif ($value['source'] === '%NEXTCLOUD_TRUSTED_CACERTS_DIR%') {
$value['source'] = $this->configurationManager->GetTrustedCacertsDir();
if($value['source'] === '') {
continue;
}
}
if ($value['destination'] === '%NEXTCLOUD_MOUNT%') {
$value['destination'] = $this->configurationManager->GetNextcloudMount();
if($value['destination'] === '') {
continue;
}
}
$volumes->AddVolume(
new ContainerVolume(
$value['source'],
$value['destination'],
$value['writeable']
)
);
} }
if($value['source'] === '%NEXTCLOUD_MOUNT%') {
$value['source'] = $this->configurationManager->GetNextcloudMount();
if($value['source'] === '') {
continue;
}
} elseif ($value['source'] === '%NEXTCLOUD_DATADIR%') {
$value['source'] = $this->configurationManager->GetNextcloudDatadirMount();
if ($value['source'] === '') {
continue;
}
} elseif ($value['source'] === '%DOCKER_SOCKET_PATH%') {
$value['source'] = $this->configurationManager->GetDockerSocketPath();
if($value['source'] === '') {
continue;
}
} elseif ($value['source'] === '%NEXTCLOUD_TRUSTED_CACERTS_DIR%') {
$value['source'] = $this->configurationManager->GetTrustedCacertsDir();
if($value['source'] === '') {
continue;
}
}
if ($value['destination'] === '%NEXTCLOUD_MOUNT%') {
$value['destination'] = $this->configurationManager->GetNextcloudMount();
if($value['destination'] === '') {
continue;
}
}
$volumes->AddVolume(
new ContainerVolume(
$value['source'],
$value['destination'],
$value['writeable']
)
);
} }
$dependsOn = []; $dependsOn = [];
foreach ($entry['depends_on'] as $value) { if (isset($entry['depends_on'])) {
if ($value === 'nextcloud-aio-clamav') { foreach ($entry['depends_on'] as $value) {
if (!$this->configurationManager->isClamavEnabled()) { if ($value === 'nextcloud-aio-clamav') {
continue; if (!$this->configurationManager->isClamavEnabled()) {
} continue;
} elseif ($value === 'nextcloud-aio-onlyoffice') { }
if (!$this->configurationManager->isOnlyofficeEnabled()) { } elseif ($value === 'nextcloud-aio-onlyoffice') {
continue; if (!$this->configurationManager->isOnlyofficeEnabled()) {
} continue;
} elseif ($value === 'nextcloud-aio-collabora') { }
if (!$this->configurationManager->isCollaboraEnabled()) { } elseif ($value === 'nextcloud-aio-collabora') {
continue; if (!$this->configurationManager->isCollaboraEnabled()) {
} continue;
} elseif ($value === 'nextcloud-aio-talk') { }
if (!$this->configurationManager->isTalkEnabled()) { } elseif ($value === 'nextcloud-aio-talk') {
continue; if (!$this->configurationManager->isTalkEnabled()) {
} continue;
} elseif ($value === 'nextcloud-aio-imaginary') { }
if (!$this->configurationManager->isImaginaryEnabled()) { } elseif ($value === 'nextcloud-aio-imaginary') {
continue; if (!$this->configurationManager->isImaginaryEnabled()) {
} continue;
} elseif ($value === 'nextcloud-aio-fulltextsearch') { }
if (!$this->configurationManager->isFulltextsearchEnabled()) { } elseif ($value === 'nextcloud-aio-fulltextsearch') {
continue; if (!$this->configurationManager->isFulltextsearchEnabled()) {
continue;
}
} }
$dependsOn[] = $value;
} }
$dependsOn[] = $value;
} }
$variables = new ContainerEnvironmentVariables(); $variables = new ContainerEnvironmentVariables();
foreach ($entry['environment'] as $value) { if (isset($entry['environment'])) {
$variables->AddVariable($value); foreach ($entry['environment'] as $value) {
$variables->AddVariable($value);
}
}
$displayName = '';
if (isset($entry['display_name'])) {
$displayName = $entry['display_name'];
}
$restartPolicy = '';
if (isset($entry['restart'])) {
$restartPolicy = $entry['restart'];
}
$maxShutdownTime = 10;
if (isset($entry['stop_grace_period'])) {
$maxShutdownTime = $entry['stop_grace_period'];
}
$internalPort = '';
if (isset($entry['internal_port'])) {
$internalPort = $entry['internal_port'];
}
$secrets = [];
if (isset($entry['secrets'])) {
$secrets = $entry['secrets'];
} }
$containers[] = new Container( $containers[] = new Container(
$entry['container_name'], $entry['container_name'],
$entry['display_name'], $displayName,
$entry['image'], $entry['image'],
$entry['restart'], $restartPolicy,
$entry['stop_grace_period'], $maxShutdownTime,
$ports, $ports,
$entry['internal_port'], $internalPort,
$volumes, $volumes,
$variables, $variables,
$dependsOn, $dependsOn,
$entry['secrets'], $secrets,
$this->container->get(DockerActionManager::class) $this->container->get(DockerActionManager::class)
); );
} }