From 375efea91470c3d3340efb0b28c0a2c055f728ba Mon Sep 17 00:00:00 2001 From: Oleksandr Piskun Date: Fri, 16 Oct 2026 07:42:01 +0000 Subject: [PATCH] fix(deploy): round the memory and CPU limits to whole numbers Signed-off-by: Oleksandr Piskun --- lib/DeployActions/DockerActions.php | 2 +- lib/Service/AppAPICommonService.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/DeployActions/DockerActions.php b/lib/DeployActions/DockerActions.php index 0f6b588e6..38dc62c1e 100644 --- a/lib/DeployActions/DockerActions.php +++ b/lib/DeployActions/DockerActions.php @@ -1150,7 +1150,7 @@ public function buildDeployParams(DaemonConfig $daemonConfig, array $appInfo): a 'devices' => $devices, 'deviceRequests' => $deviceRequests, 'mounts' => $appInfo['external-app']['mounts'] ?? [], - 'resourceLimits' => $deployConfig['resourceLimits'] ?? [] + 'resourceLimits' => AppAPICommonService::buildResourceLimits($deployConfig) ]; return [ diff --git a/lib/Service/AppAPICommonService.php b/lib/Service/AppAPICommonService.php index 487454357..9644db186 100644 --- a/lib/Service/AppAPICommonService.php +++ b/lib/Service/AppAPICommonService.php @@ -56,4 +56,22 @@ public function buildExAppHost(array $deployConfig): string { } return '127.0.0.1'; # fallback to loop-back adapter } + + /** + * Docker takes the memory and CPU limits as whole numbers, but the admin settings compute them from decimal + * input (`Number(cpus) * 1000000000`), which can store a value such as 1070000000.0000001. + */ + public static function buildResourceLimits(array $deployConfig): array { + $resourceLimits = $deployConfig['resourceLimits'] ?? []; + if (!is_array($resourceLimits)) { + return []; + } + foreach (['memory', 'nanoCPUs'] as $limit) { + $value = $resourceLimits[$limit] ?? null; + if (is_float($value) && abs($value) < PHP_INT_MAX) { + $resourceLimits[$limit] = (int)round($value); + } + } + return $resourceLimits; + } }