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
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|","writeable":false|:ro"|g' /tmp/containers.json
sed -i 's|","writeable":true|:rw"|g' /tmp/containers.json

View file

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

View file

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

View file

@ -48,7 +48,7 @@ class ContainerDefinitionFetcher
$data = json_decode(file_get_contents(__DIR__ . '/../containers.json'), true);
$containers = [];
foreach ($data['services'] as $entry) {
foreach ($data['aio_services_v1'] as $entry) {
if ($entry['container_name'] === 'nextcloud-aio-clamav') {
if (!$this->configurationManager->isClamavEnabled()) {
continue;
@ -76,118 +76,150 @@ class ContainerDefinitionFetcher
}
$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%') {
$value['port_number'] = $this->configurationManager->GetApachePort();
} elseif ($value['port_number'] === '%TALK_PORT%') {
$value['port_number'] = $this->configurationManager->GetTalkPort();
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']
)
);
}
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();
foreach ($entry['volumes'] as $value) {
if($value['source'] === '%BORGBACKUP_HOST_LOCATION%') {
$value['source'] = $this->configurationManager->GetBorgBackupHostLocation();
if($value['source'] === '') {
continue;
if (isset($entry['volumes'])) {
foreach ($entry['volumes'] as $value) {
if($value['source'] === '%BORGBACKUP_HOST_LOCATION%') {
$value['source'] = $this->configurationManager->GetBorgBackupHostLocation();
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 = [];
foreach ($entry['depends_on'] as $value) {
if ($value === 'nextcloud-aio-clamav') {
if (!$this->configurationManager->isClamavEnabled()) {
continue;
}
} elseif ($value === 'nextcloud-aio-onlyoffice') {
if (!$this->configurationManager->isOnlyofficeEnabled()) {
continue;
}
} elseif ($value === 'nextcloud-aio-collabora') {
if (!$this->configurationManager->isCollaboraEnabled()) {
continue;
}
} elseif ($value === 'nextcloud-aio-talk') {
if (!$this->configurationManager->isTalkEnabled()) {
continue;
}
} elseif ($value === 'nextcloud-aio-imaginary') {
if (!$this->configurationManager->isImaginaryEnabled()) {
continue;
}
} elseif ($value === 'nextcloud-aio-fulltextsearch') {
if (!$this->configurationManager->isFulltextsearchEnabled()) {
continue;
if (isset($entry['depends_on'])) {
foreach ($entry['depends_on'] as $value) {
if ($value === 'nextcloud-aio-clamav') {
if (!$this->configurationManager->isClamavEnabled()) {
continue;
}
} elseif ($value === 'nextcloud-aio-onlyoffice') {
if (!$this->configurationManager->isOnlyofficeEnabled()) {
continue;
}
} elseif ($value === 'nextcloud-aio-collabora') {
if (!$this->configurationManager->isCollaboraEnabled()) {
continue;
}
} elseif ($value === 'nextcloud-aio-talk') {
if (!$this->configurationManager->isTalkEnabled()) {
continue;
}
} elseif ($value === 'nextcloud-aio-imaginary') {
if (!$this->configurationManager->isImaginaryEnabled()) {
continue;
}
} elseif ($value === 'nextcloud-aio-fulltextsearch') {
if (!$this->configurationManager->isFulltextsearchEnabled()) {
continue;
}
}
$dependsOn[] = $value;
}
$dependsOn[] = $value;
}
$variables = new ContainerEnvironmentVariables();
foreach ($entry['environment'] as $value) {
$variables->AddVariable($value);
if (isset($entry['environment'])) {
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(
$entry['container_name'],
$entry['display_name'],
$displayName,
$entry['image'],
$entry['restart'],
$entry['stop_grace_period'],
$restartPolicy,
$maxShutdownTime,
$ports,
$entry['internal_port'],
$internalPort,
$volumes,
$variables,
$dependsOn,
$entry['secrets'],
$secrets,
$this->container->get(DockerActionManager::class)
);
}