Merge pull request #2113 from nextcloud/enh/noid/cap_add

fix set_memory for imaginary and move cap_add to containers.json
This commit is contained in:
Simon L 2023-03-07 09:59:45 +01:00 committed by GitHub
commit 9f8d17d888
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 2 deletions

View file

@ -21,6 +21,12 @@
"type": "string"
}
},
"cap_add": {
"type": "array",
"items": {
"type": "string"
}
},
"depends_on": {
"type": "array",
"items": {

View file

@ -318,6 +318,9 @@
],
"devices": [
"/dev/fuse"
],
"cap_add": [
"SYS_ADMIN"
]
},
{
@ -411,7 +414,10 @@
"environment": [
"TZ=%TIMEZONE%"
],
"restart": "unless-stopped"
"restart": "unless-stopped",
"cap_add": [
"SYS_NICE"
]
},
{
"container_name": "nextcloud-aio-fulltextsearch",

View file

@ -23,6 +23,8 @@ class Container {
private array $secrets;
/** @var string[] */
private array $devices;
/** @var string[] */
private array $capAdd;
private DockerActionManager $dockerActionManager;
public function __construct(
@ -38,6 +40,7 @@ class Container {
array $dependsOn,
array $secrets,
array $devices,
array $capAdd,
DockerActionManager $dockerActionManager
) {
$this->identifier = $identifier;
@ -52,6 +55,7 @@ class Container {
$this->dependsOn = $dependsOn;
$this->secrets = $secrets;
$this->devices = $devices;
$this->capAdd = $capAdd;
$this->dockerActionManager = $dockerActionManager;
}
@ -83,6 +87,10 @@ class Container {
return $this->devices;
}
public function GetCapAdds() : array {
return $this->capAdd;
}
public function GetPorts() : ContainerPorts {
return $this->ports;
}

View file

@ -213,6 +213,11 @@ class ContainerDefinitionFetcher
$devices = $entry['devices'];
}
$capAdd = [];
if (isset($entry['cap_add'])) {
$capAdd = $entry['cap_add'];
}
$containers[] = new Container(
$entry['container_name'],
$displayName,
@ -226,6 +231,7 @@ class ContainerDefinitionFetcher
$dependsOn,
$secrets,
$devices,
$capAdd,
$this->container->get(DockerActionManager::class)
);
}

View file

@ -411,9 +411,13 @@ class DockerActionManager
$requestBody['HostConfig']['Devices'] = $devices;
}
$capAdds = $container->GetCapAdds();
if (count($capAdds) > 0) {
$requestBody['HostConfig']['CapAdd'] = $capAdds;
}
// Special things for the backup container which should not be exposed in the containers.json
if ($container->GetIdentifier() === 'nextcloud-aio-borgbackup') {
$requestBody['HostConfig']['CapAdd'] = ["SYS_ADMIN"];
$requestBody['HostConfig']['SecurityOpt'] = ["apparmor:unconfined"];
// Additional backup directories