Skip to content

Commit

Permalink
fix set_memory for imaginary and move cap_add to containers.json
Browse files Browse the repository at this point in the history
Signed-off-by: Simon L <[email protected]>
  • Loading branch information
szaimen committed Mar 6, 2023
1 parent c54395a commit 57b4180
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
6 changes: 6 additions & 0 deletions php/containers-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
"type": "string"
}
},
"cap_add": {
"type": "array",
"items": {
"type": "string"
}
},
"depends_on": {
"type": "array",
"items": {
Expand Down
8 changes: 7 additions & 1 deletion php/containers.json
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@
],
"devices": [
"/dev/fuse"
],
"cap_add": [
"SYS_ADMIN"
]
},
{
Expand Down Expand Up @@ -411,7 +414,10 @@
"environment": [
"TZ=%TIMEZONE%"
],
"restart": "unless-stopped"
"restart": "unless-stopped",
"cap_add": [
"CAP_SYS_NICE"
]
},
{
"container_name": "nextcloud-aio-fulltextsearch",
Expand Down
8 changes: 8 additions & 0 deletions php/src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -38,6 +40,7 @@ public function __construct(
array $dependsOn,
array $secrets,
array $devices,
array $capAdd,
DockerActionManager $dockerActionManager
) {
$this->identifier = $identifier;
Expand All @@ -52,6 +55,7 @@ public function __construct(
$this->dependsOn = $dependsOn;
$this->secrets = $secrets;
$this->devices = $devices;
$this->capAdd = $capAdd;
$this->dockerActionManager = $dockerActionManager;
}

Expand Down Expand Up @@ -83,6 +87,10 @@ public function GetDevices() : array {
return $this->devices;
}

public function GetCapAdds() : array {
return $this->capAdd;
}

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

$capAdd = [];
if (isset($entry['cap_add'])) {
$capAdd = $entry['cap_add'];
}

$containers[] = new Container(
$entry['container_name'],
$displayName,
Expand All @@ -226,6 +231,7 @@ private function GetDefinition(bool $latest): array
$dependsOn,
$secrets,
$devices,
$capAdd,
$this->container->get(DockerActionManager::class)
);
}
Expand Down
6 changes: 5 additions & 1 deletion php/src/Docker/DockerActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,13 @@ public function CreateContainer(Container $container) : void {
$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
Expand Down

0 comments on commit 57b4180

Please sign in to comment.