diff --git a/app/config/variables.php b/app/config/variables.php index a828ceda61..bfdceee027 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -800,7 +800,7 @@ return [ ], [ 'name' => '_APP_FUNCTIONS_CPUS', - 'description' => 'The maximum number of CPU core a single cloud function is allowed to use. Please note that setting a value higher than available cores will result in a function error, which might result in an error. The default value is empty. When it\'s empty, CPU limit will be disabled.', + 'description' => 'The maximum number of CPU core a single cloud function is allowed to use. Please note that setting a value higher than available cores will result in a function error, which might result in an error. The default value is empty. When it\'s empty or 0, CPU limit will be disabled.', 'introduction' => '0.7.0', 'default' => '0', 'required' => false, @@ -809,7 +809,7 @@ return [ ], [ 'name' => '_APP_FUNCTIONS_MEMORY', - 'description' => 'The maximum amount of memory a single cloud function is allowed to use in megabytes. The default value is empty. When it\'s empty, memory limit will be disabled.', + 'description' => 'The maximum amount of memory a single cloud function is allowed to use in megabytes. The default value is empty. When it\'s empty or 0, memory limit will be disabled.', 'introduction' => '0.7.0', 'default' => '0', 'required' => false, diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 13db86cf4c..8092997b2e 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -186,8 +186,8 @@ App::post('/v1/functions') ->param('specification', APP_FUNCTION_SPECIFICATION_DEFAULT, fn (array $plan) => new RuntimeSpecification( $plan, Config::getParam('runtime-specifications', []), - App::getEnv('_APP_FUNCTIONS_CPUS', APP_FUNCTION_CPUS_DEFAULT), - App::getEnv('_APP_FUNCTIONS_MEMORY', APP_FUNCTION_MEMORY_DEFAULT) + System::getEnv('_APP_FUNCTIONS_CPUS', 0), + System::getEnv('_APP_FUNCTIONS_MEMORY', 0) ), 'Runtime specification for the function and builds.', true, ['plan']) ->inject('request') ->inject('response') @@ -569,8 +569,12 @@ App::get('/v1/functions/specifications') $spec['enabled'] = in_array($spec['slug'], $plan['runtimeSpecifications']); } + $maxCpus = System::getEnv('_APP_FUNCTIONS_CPUS', 0); + $maxMemory = System::getEnv('_APP_FUNCTIONS_MEMORY', 0); + // Only add specs that are within the limits set by environment variables - if ($spec['cpus'] <= System::getEnv('_APP_FUNCTIONS_CPUS', 1) && $spec['memory'] <= System::getEnv('_APP_FUNCTIONS_MEMORY', 512)) { + // Treat 0 as no limit + if ((empty($maxCpus) || $spec['cpus'] <= $maxCpus) && (empty($maxMemory) || $spec['memory'] <= $maxMemory)) { $runtimeSpecs[] = $spec; } } @@ -872,8 +876,8 @@ App::put('/v1/functions/:functionId') ->param('specification', APP_FUNCTION_SPECIFICATION_DEFAULT, fn (array $plan) => new RuntimeSpecification( $plan, Config::getParam('runtime-specifications', []), - App::getEnv('_APP_FUNCTIONS_CPUS', APP_FUNCTION_CPUS_DEFAULT), - App::getEnv('_APP_FUNCTIONS_MEMORY', APP_FUNCTION_MEMORY_DEFAULT) + System::getEnv('_APP_FUNCTIONS_CPUS', 0), + System::getEnv('_APP_FUNCTIONS_MEMORY', 0) ), 'Runtime specification for the function and builds.', true, ['plan']) ->inject('request') ->inject('response') diff --git a/src/Appwrite/Functions/Validator/RuntimeSpecification.php b/src/Appwrite/Functions/Validator/RuntimeSpecification.php index 22311838f6..b9185d832a 100644 --- a/src/Appwrite/Functions/Validator/RuntimeSpecification.php +++ b/src/Appwrite/Functions/Validator/RuntimeSpecification.php @@ -34,7 +34,7 @@ class RuntimeSpecification extends Validator $allowedSpecifications = []; foreach ($this->specifications as $size => $values) { - if ($values['cpus'] <= $this->maxCpus && $values['memory'] <= $this->maxMemory) { + if ((empty($this->maxCpus) || $values['cpus'] <= $this->maxCpus) && (empty($this->maxMemory) || $values['memory'] <= $this->maxMemory)) { if (!empty($this->plan) && array_key_exists('runtimeSpecifications', $this->plan)) { if (!\in_array($size, $this->plan['runtimeSpecifications'])) { continue;