From 275ecc9f838a2966b5192878f0ccd4ae97357e03 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 2 Aug 2024 16:45:22 +0900 Subject: [PATCH] Fix specifications and make builds memory minimum 1024 --- .../Validator/RuntimeSpecification.php | 2 +- src/Appwrite/Platform/Workers/Builds.php | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Functions/Validator/RuntimeSpecification.php b/src/Appwrite/Functions/Validator/RuntimeSpecification.php index e8886d6057..ee071376c5 100644 --- a/src/Appwrite/Functions/Validator/RuntimeSpecification.php +++ b/src/Appwrite/Functions/Validator/RuntimeSpecification.php @@ -26,7 +26,7 @@ class RuntimeSpecification extends Validator { $specifications = Config::getParam('runtime-specifications', []); - $allowedSpecficiations = []; + $allowedSpecifications = []; foreach ($specifications as $size => $values) { if ($values['cpus'] <= System::getEnv('_APP_FUNCTIONS_CPUS', 1) && $values['memory'] <= System::getEnv('_APP_FUNCTIONS_MEMORY', 512)) { diff --git a/src/Appwrite/Platform/Workers/Builds.php b/src/Appwrite/Platform/Workers/Builds.php index a41d2990d3..7f7dd9d221 100644 --- a/src/Appwrite/Platform/Workers/Builds.php +++ b/src/Appwrite/Platform/Workers/Builds.php @@ -387,6 +387,13 @@ class Builds extends Action $vars[$var->getAttribute('key')] = $var->getAttribute('value', ''); } + $cpus = $spec['cpus'] ?? 1; + $memory = max($spec['memory'] ?? 1024, 1024); + + if ($memory < 1024) { + $memory = 1024; + } + // Appwrite vars $vars = \array_merge($vars, [ 'APPWRITE_FUNCTION_ID' => $function->getId(), @@ -395,8 +402,8 @@ class Builds extends Action 'APPWRITE_FUNCTION_PROJECT_ID' => $project->getId(), 'APPWRITE_FUNCTION_RUNTIME_NAME' => $runtime['name'] ?? '', 'APPWRITE_FUNCTION_RUNTIME_VERSION' => $runtime['version'] ?? '', - 'APPWRITE_FUNCTION_CPUS' => $spec['cpus'] ?? 1, - 'APPWRITE_FUNCTION_MEMORY' => $spec['memory'] ?? 512 + 'APPWRITE_FUNCTION_CPUS' => $cpus, + 'APPWRITE_FUNCTION_MEMORY' => $memory ]); $command = $deployment->getAttribute('commands', ''); @@ -405,7 +412,7 @@ class Builds extends Action $err = null; Co::join([ - Co\go(function () use ($executor, &$response, $project, $deployment, $source, $function, $runtime, $vars, $command, $spec, &$err) { + Co\go(function () use ($executor, &$response, $project, $deployment, $source, $function, $runtime, $vars, $command, $cpus, $memory, &$err) { try { $version = $function->getAttribute('version', 'v2'); $command = $version === 'v2' ? 'tar -zxf /tmp/code.tar.gz -C /usr/code && cd /usr/local/src/ && ./build.sh' : 'tar -zxf /tmp/code.tar.gz -C /mnt/code && helpers/build.sh "' . \trim(\escapeshellarg($command), "\'") . '"'; @@ -416,8 +423,8 @@ class Builds extends Action source: $source, image: $runtime['image'], version: $version, - cpus: $spec['cpus'] ?? 1, - memory: $spec['memory'] ?? 512, + cpus: $cpus, + memory: $memory, remove: true, entrypoint: $deployment->getAttribute('entrypoint'), destination: APP_STORAGE_BUILDS . "/app-{$project->getId()}",