Fix specifications and make builds memory minimum 1024

This commit is contained in:
Bradley Schofield 2024-08-02 16:45:22 +09:00
parent aa21a1a200
commit 275ecc9f83
2 changed files with 13 additions and 6 deletions

View file

@ -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)) {

View file

@ -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()}",