From 0fdd13762ddc08be11b0c77cf664705d03c432b8 Mon Sep 17 00:00:00 2001 From: Jean-Yves <7360784+docjyJ@users.noreply.github.com> Date: Tue, 17 Dec 2024 18:45:27 +0100 Subject: [PATCH] Rolback gpu mode Signed-off-by: Jean-Yves <7360784+docjyJ@users.noreply.github.com> --- community-containers/jellyfin/jellyfin.json | 5 ++++- community-containers/memories/memories.json | 5 ++++- community-containers/plex/plex.json | 5 ++++- compose.yaml | 3 ++- php/containers-schema.json | 2 +- php/containers.json | 5 ++++- php/src/Container/Container.php | 6 +++--- php/src/ContainerDefinitionFetcher.php | 2 +- php/src/Data/ConfigurationManager.php | 24 +++++++++++++++------ php/src/Docker/DockerActionManager.php | 17 ++++++++------- readme.md | 9 ++++---- tests/QA/060-environmental-variables.md | 2 +- 12 files changed, 54 insertions(+), 31 deletions(-) diff --git a/community-containers/jellyfin/jellyfin.json b/community-containers/jellyfin/jellyfin.json index b469c38b6cc..479725888cc 100644 --- a/community-containers/jellyfin/jellyfin.json +++ b/community-containers/jellyfin/jellyfin.json @@ -28,7 +28,10 @@ "writeable": false } ], - "enable_gpu": true, + "devices": [ + "/dev/dri" + ], + "enable_nvidia_gpu": true, "backup_volumes": [ "nextcloud_aio_jellyfin" ] diff --git a/community-containers/memories/memories.json b/community-containers/memories/memories.json index baa5a4493bc..cb84a72212f 100644 --- a/community-containers/memories/memories.json +++ b/community-containers/memories/memories.json @@ -24,7 +24,10 @@ "writeable": false } ], - "enable_gpu": true, + "devices": [ + "/dev/dri" + ], + "enable_nvidia_gpu": true, "nextcloud_exec_commands": [ "php /var/www/html/occ app:install memories", "php /var/www/html/occ app:enable memories", diff --git a/community-containers/plex/plex.json b/community-containers/plex/plex.json index 322f4c81faf..5fc8712a5a1 100644 --- a/community-containers/plex/plex.json +++ b/community-containers/plex/plex.json @@ -30,7 +30,10 @@ "writeable": false } ], - "enable_gpu": true, + "devices": [ + "/dev/dri" + ], + "enable_nvidia_gpu": true, "backup_volumes": [ "nextcloud_aio_plex" ] diff --git a/compose.yaml b/compose.yaml index a1d6bb2ff20..61b2175afd9 100644 --- a/compose.yaml +++ b/compose.yaml @@ -29,7 +29,8 @@ services: # NEXTCLOUD_STARTUP_APPS: deck twofactor_totp tasks calendar contacts notes # Allows to modify the Nextcloud apps that are installed on starting AIO the first time. See https://github.com/nextcloud/all-in-one#how-to-change-the-nextcloud-apps-that-are-installed-on-the-first-startup # NEXTCLOUD_ADDITIONAL_APKS: imagemagick # This allows to add additional packages to the Nextcloud container permanently. Default is imagemagick but can be overwritten by modifying this value. See https://github.com/nextcloud/all-in-one#how-to-add-os-packages-permanently-to-the-nextcloud-container # NEXTCLOUD_ADDITIONAL_PHP_EXTENSIONS: imagick # This allows to add additional php extensions to the Nextcloud container permanently. Default is imagick but can be overwritten by modifying this value. See https://github.com/nextcloud/all-in-one#how-to-add-php-extensions-permanently-to-the-nextcloud-container - # NEXTCLOUD_GPU_MODE: 'dri' # 'dri', 'nvidia-runtime' or 'nvidia-deploy':This allows to enable the GPU acceleration in the Nextcloud container. Make sure you follow https://github.com/nextcloud/all-in-one#how-to-enable-gpu-acceleration-for-nextcloud before setting this value. + # NEXTCLOUD_ENABLE_DRI_DEVICE: true # This allows to enable the /dev/dri device in the Nextcloud container. ⚠️⚠️⚠️ Warning: this only works if the '/dev/dri' device is present on the host! If it should not exist on your host, don't set this to true as otherwise the Nextcloud container will fail to start! See https://github.com/nextcloud/all-in-one#how-to-enable-hardware-transcoding-for-nextcloud + # NEXTCLOUD_NVIDIA_GPU_MODE: 'runtime' # 'runtime' or 'deploy': This allows to enable the [NVIDIA runtime](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html) or [GPU access](https://docs.docker.com/compose/gpu-support/) in the Nextcloud container. Make sure you follow the instructions before setting this value. If you're using WSL2 and want to use the NVIDIA runtime, please follow the instructions to [install the NVIDIA Container Toolkit meta-version in WSL](https://docs.nvidia.com/cuda/wsl-user-guide/index.html#cuda-support-for-wsl-2). # NEXTCLOUD_KEEP_DISABLED_APPS: false # Setting this to true will keep Nextcloud apps that are disabled in the AIO interface and not uninstall them if they should be installed. See https://github.com/nextcloud/all-in-one#how-to-keep-disabled-apps # SKIP_DOMAIN_VALIDATION: false # This should only be set to true if things are correctly configured. See https://github.com/nextcloud/all-in-one?tab=readme-ov-file#how-to-skip-the-domain-validation # TALK_PORT: 3478 # This allows to adjust the port that the talk container is using. See https://github.com/nextcloud/all-in-one#how-to-adjust-the-talk-port diff --git a/php/containers-schema.json b/php/containers-schema.json index a10fd09948a..d8dcfb0b73f 100644 --- a/php/containers-schema.json +++ b/php/containers-schema.json @@ -160,7 +160,7 @@ "pattern": "^/dev/[a-z]+$" } }, - "enable_gpu": { + "enable_nvidia_gpu": { "type": "boolean" }, "apparmor_unconfined": { diff --git a/php/containers.json b/php/containers.json index c7a986094ac..2d17b03abcc 100644 --- a/php/containers.json +++ b/php/containers.json @@ -260,7 +260,10 @@ ], "stop_grace_period": 600, "restart": "unless-stopped", - "enable_gpu": true, + "devices": [ + "/dev/dri" + ], + "enable_nvidia_gpu": true, "backup_volumes": [ "nextcloud_aio_nextcloud" ], diff --git a/php/src/Container/Container.php b/php/src/Container/Container.php index b30f72d60a2..40b2cc4e281 100644 --- a/php/src/Container/Container.php +++ b/php/src/Container/Container.php @@ -23,7 +23,7 @@ public function __construct( private array $secrets, /** @var string[] */ private array $devices, - private bool $enable_gpu, + private bool $enable_nvidia_gpu, /** @var string[] */ private array $capAdd, private int $shmSize, @@ -93,8 +93,8 @@ public function GetDevices() : array { return $this->devices; } - public function GetGpuMode() : bool { - return $this->enable_gpu; + public function CanUseNidiaGpu() : bool { + return $this->enable_nvidia_gpu; } public function GetCapAdds() : array { diff --git a/php/src/ContainerDefinitionFetcher.php b/php/src/ContainerDefinitionFetcher.php index 8d04fd6df40..6caf27598c9 100644 --- a/php/src/ContainerDefinitionFetcher.php +++ b/php/src/ContainerDefinitionFetcher.php @@ -249,7 +249,7 @@ private function GetDefinition(): array $devices = $entry['devices']; } - $enable_gpu = $entry['enable_gpu'] === true; + $enable_gpu = $entry['enable_nvidia_gpu'] === true; $capAdd = []; if (isset($entry['cap_add'])) { diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index c404c3e24cd..cd376030523 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -968,24 +968,34 @@ public function GetEnabledCommunityContainers() : array { return explode(' ', $this->GetCommunityContainers()); } - - private function GetEnabledGPUMode() : string { - $envVariableName = 'NEXTCLOUD_GPU_MODE'; - $configName = 'nextcloud_gpu_mode'; + private function GetEnabledDriDevice() : string { + $envVariableName = 'NEXTCLOUD_ENABLE_DRI_DEVICE'; + $configName = 'nextcloud_enable_dri_device'; $defaultValue = ''; return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue); } public function isDriDeviceEnabled() : bool { - return $this->GetEnabledGPUMode() === 'dri'; + if ($this->GetEnabledDriDevice() === 'true') { + return true; + } else { + return false; + } + } + + private function GetEnabledGPUMode() : string { + $envVariableName = 'NEXTCLOUD_NVIDIA_GPU_MODE'; + $configName = 'nextcloud_nvidia_gpu_mode'; + $defaultValue = ''; + return $this->GetEnvironmentalVariableOrConfig($envVariableName, $configName, $defaultValue); } public function isNvidiaRuntimeEnabled() : bool { - return $this->GetEnabledGPUMode() === 'nvidia-runtime'; + return $this->GetEnabledGPUMode() === 'runtime'; } public function isNvidiaDeployEnabled() : bool { - return $this->GetEnabledGPUMode() === 'nvidia-deploy'; + return $this->GetEnabledGPUMode() === 'deploy'; } private function GetKeepDisabledApps() : string { diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index b19a95dbb65..3a11ae842ac 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -481,13 +481,18 @@ public function CreateContainer(Container $container) : void { $devices = []; foreach($container->GetDevices() as $device) { + if ($device === '/dev/dri' && ! $this->configurationManager->isDriDeviceEnabled()) { + continue; + } $devices[] = ["PathOnHost" => $device, "PathInContainer" => $device, "CgroupPermissions" => "rwm"]; } - if ($container->canUseNvidia()) { - if($this->configurationManager->isDriDeviceEnabled()) { - $devices[] = ["PathOnHost" => '/dev/dri', "PathInContainer" => '/dev/dri', "CgroupPermissions" => "rwm"]; - } elseif ($this->configurationManager->isNvidiaRuntimeEnabled()) { + if (count($devices) > 0) { + $requestBody['HostConfig']['Devices'] = $devices; + } + + if ($container->CanUseNidiaGpu()) { + if ($this->configurationManager->isNvidiaRuntimeEnabled()) { $requestBody['HostConfig']['Runtime'] = 'nvidia'; } elseif ($this->configurationManager->isNvidiaDeployEnabled()) { $requestBody['HostConfig']['DeviceRequests'] = [ @@ -500,10 +505,6 @@ public function CreateContainer(Container $container) : void { } } - if (count($devices) > 0) { - $requestBody['HostConfig']['Devices'] = $devices; - } - $shmSize = $container->GetShmSize(); if ($shmSize > 0) { $requestBody['HostConfig']['ShmSize'] = $shmSize; diff --git a/readme.md b/readme.md index 373d6885d08..3249d4197f4 100644 --- a/readme.md +++ b/readme.md @@ -768,8 +768,6 @@ The [facerecognition app](https://apps.nextcloud.com/apps/facerecognition) requi ### How to enable GPU acceleration for Nextcloud? Some container can use GPU acceleration to increase performance like [memories app](https://apps.nextcloud.com/apps/memories) allows to enable hardware transcoding for videos. -To enable it you need to add `--env NEXTCLOUD_GPU_MODE=` to the docker run command of the mastercontainer (but before the last line `nextcloud/all-in-one:latest`! If it was started already, you will need to stop the mastercontainer, remove it (no data will be lost) and recreate it using the docker run command that you initially used). - #### With open source drivers MESA for AMD, Intel and **new** drivers `Nouveau` for Nvidia > [!WARNING] @@ -777,7 +775,8 @@ To enable it you need to add `--env NEXTCLOUD_GPU_MODE=` to the docker run A list of supported device can be fond in [MESA 3D documentation](https://docs.mesa3d.org/systems.html). -This methode use the [Direct Rendering Infrastructure](https://dri.freedesktop.org/wiki/) with the access to the `/dev/dri` device. To enable it, use `--env NEXTCLOUD_GPU_MODE=dri` as mode. +This methode use the [Direct Rendering Infrastructure](https://dri.freedesktop.org/wiki/) with the access to the `/dev/dri` device. In order to use that, you need to add `--env NEXTCLOUD_ENABLE_DRI_DEVICE=true` to the docker run command of the mastercontainer (but before the last line `nextcloud/all-in-one:latest`! If it was started already, you will need to stop the mastercontainer, remove it (no data will be lost) and recreate it using the docker run command that you initially used) which will mount the `/dev/dri` device into the container. There is now a community container which allows to easily add the transcoding container of Memories to AIO: https://github.com/nextcloud/all-in-one/tree/main/community-containers/memories + #### With proprietary drivers for Nvidia :warning: BETA @@ -788,9 +787,9 @@ This methode use the [Direct Rendering Infrastructure](https://dri.freedesktop.o This methode use the [Nvidia Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/index.html) with the nvidia runtime. -To enable it, use `--env NEXTCLOUD_GPU_MODE=nvidia-runtime` as mode. +To enable it, use `--env NEXTCLOUD_NVIDIA_GPU_MODE=runtime` to enable runtime. -You can also use [docker resource allocation](https://docs.docker.com/compose/gpu-support/) with `--env NEXTCLOUD_GPU_MODE=nvidia-deploy` as mode. +You can also use [docker resource allocation](https://docs.docker.com/compose/gpu-support/) with `--env NEXTCLOUD_NVIDIA_GPU_MODE=deploy` as mode. If you're using WSL2 and want to use the NVIDIA runtime, please follow the instructions to [install the NVIDIA Container Toolkit meta-version in WSL](https://docs.nvidia.com/cuda/wsl-user-guide/index.html#cuda-support-for-wsl-2). diff --git a/tests/QA/060-environmental-variables.md b/tests/QA/060-environmental-variables.md index 2a411615a21..5113bdf7601 100644 --- a/tests/QA/060-environmental-variables.md +++ b/tests/QA/060-environmental-variables.md @@ -20,7 +20,7 @@ See https://github.com/nextcloud/all-in-one#how-to-trust-user-defined-certificat - [ ] When starting the mastercontainer with `--env NEXTCLOUD_STARTUP_APPS=deck`, the resulting Nextcloud should have only installed the deck app and not the other apps that get installed by default. Default are `deck twofactor_totp tasks calendar contacts notes`. - [ ] When starting the mastercontainer with `--env NEXTCLOUD_ADDITIONAL_APKS=zip`, the resulting Nextcloud container should have the zip package installed and not imagemagick. - [ ] When starting the mastercontainer with `--env NEXTCLOUD_ADDITIONAL_PHP_EXTENSIONS=inotify`, the resulting Nextcloud container should have the inotify extension installed and not the imagick extension. -- [ ] When starting the mastercontainer with `--env NEXTCLOUD_GPU_MODE=dri`, the resulting Nextcloud container should have the /dev/dri device mounted into the container. (Only works if a `/dev/dri` device is present on the host) +- [ ] When starting the mastercontainer with `--env NEXTCLOUD_ENABLE_DRI_DEVICE=true`, the resulting Nextcloud container should have the /dev/dri device mounted into the container. (Only works if a `/dev/dri` device is present on the host) - [ ] When starting the mastercontainer with `--env NEXTCLOUD_KEEP_DISABLED_APPS=true` it should keep apps in Nextcloud that are disabled in the AIO interface. For example if Collabora is disabled in the AIO interface and you install the richdocuments app in Nextcloud, a restart should not uninstall the richdocuments app in Nextcloud anymore. - [ ] When starting the mastercontainer with `--env AIO_COMMUNITY_CONTAINERS="fail2ban"`, it should add the fail2ban container to the container stack and show it in the AIO interface as well as start it, etc.