Skip to content

Commit

Permalink
Add containers schema
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Yves <7360784+docjyJ@users.noreply.github.com>
  • Loading branch information
docjyJ committed Dec 17, 2024
1 parent e2bce7e commit 66f9cf2
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions community-containers/jellyfin/jellyfin.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"devices": [
"/dev/dri"
],
"nvidia": true,
"backup_volumes": [
"nextcloud_aio_jellyfin"
]
Expand Down
1 change: 1 addition & 0 deletions community-containers/memories/memories.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"devices": [
"/dev/dri"
],
"nvidia": true,
"nextcloud_exec_commands": [
"php /var/www/html/occ app:install memories",
"php /var/www/html/occ app:enable memories",
Expand Down
1 change: 1 addition & 0 deletions community-containers/plex/plex.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"devices": [
"/dev/dri"
],
"nvidia": true,
"backup_volumes": [
"nextcloud_aio_plex"
]
Expand Down
3 changes: 3 additions & 0 deletions php/containers-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@
"pattern": "^/dev/[a-z]+$"
}
},
"nvidia": {
"type": "boolean"
},
"apparmor_unconfined": {
"type": "boolean"
},
Expand Down
1 change: 1 addition & 0 deletions php/containers.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
"devices": [
"/dev/dri"
],
"nvidia": true,
"backup_volumes": [
"nextcloud_aio_nextcloud"
],
Expand Down
5 changes: 5 additions & 0 deletions php/src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function __construct(
private array $secrets,
/** @var string[] */
private array $devices,
private bool $nvidia,
/** @var string[] */
private array $capAdd,
private int $shmSize,
Expand Down Expand Up @@ -92,6 +93,10 @@ public function GetDevices() : array {
return $this->devices;
}

public function CanUseNvidia() : bool {
return $this->nvidia;
}

public function GetCapAdds() : array {
return $this->capAdd;
}
Expand Down
3 changes: 3 additions & 0 deletions php/src/ContainerDefinitionFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ private function GetDefinition(): array
$devices = $entry['devices'];
}

$nvidia = $entry['nvidia'] === true;

$capAdd = [];
if (isset($entry['cap_add'])) {
$capAdd = $entry['cap_add'];
Expand Down Expand Up @@ -312,6 +314,7 @@ private function GetDefinition(): array
$dependsOn,
$secrets,
$devices,
$nvidia,
$capAdd,
$shmSize,
$apparmorUnconfined,
Expand Down
22 changes: 12 additions & 10 deletions php/src/Docker/DockerActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,16 +491,18 @@ public function CreateContainer(Container $container) : void {
$requestBody['HostConfig']['Devices'] = $devices;
}

if ($this->configurationManager->isNvidiaRuntimeEnabled()) {
$requestBody['HostConfig']['Runtime'] = 'nvidia';
} elseif ($this->configurationManager->isNvidiaDeployEnabled()) {
$requestBody['HostConfig']['DeviceRequests'] = [
[
"Driver" => "nvidia",
"Count" => 1,
"Capabilities" => [["gpu"]],
]
];
if ($container->canUseNvidia()) {
if ($this->configurationManager->isNvidiaRuntimeEnabled()) {
$requestBody['HostConfig']['Runtime'] = 'nvidia';
} elseif ($this->configurationManager->isNvidiaDeployEnabled()) {
$requestBody['HostConfig']['DeviceRequests'] = [
[
"Driver" => "nvidia",
"Count" => 1,
"Capabilities" => [["gpu"]],
]
];
}
}

$shmSize = $container->GetShmSize();
Expand Down

0 comments on commit 66f9cf2

Please sign in to comment.