mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Implement CPU and Memory runtime controls
This commit is contained in:
+1
-1
@@ -29,7 +29,7 @@ ENV VITE_APPWRITE_GROWTH_ENDPOINT=$VITE_APPWRITE_GROWTH_ENDPOINT
|
||||
RUN npm ci
|
||||
RUN npm run build
|
||||
|
||||
FROM appwrite/base:0.9.0 as final
|
||||
FROM appwrite/base:0.9.1 as final
|
||||
|
||||
LABEL maintainer="team@appwrite.io"
|
||||
|
||||
|
||||
@@ -3054,6 +3054,28 @@ $projectCollections = array_merge([
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'array' => false,
|
||||
'$id' => ID::custom('memory'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'format' => '',
|
||||
'size' => 512,
|
||||
'signed' => false,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'array' => false,
|
||||
'$id' => ID::custom('cpus'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'format' => '',
|
||||
'size' => 1,
|
||||
'signed' => false,
|
||||
'required' => true,
|
||||
'default' => null,
|
||||
'filters' => [],
|
||||
]
|
||||
],
|
||||
'indexes' => [
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -160,6 +160,8 @@ App::post('/v1/functions')
|
||||
->param('templateOwner', '', new Text(128, 0), 'The name of the owner of the template.', true)
|
||||
->param('templateRootDirectory', '', new Text(128, 0), 'Path to function code in the template repo.', true)
|
||||
->param('templateBranch', '', new Text(128, 0), 'Production branch for the repo linked to the function template.', true)
|
||||
->param('memory', 512, new WhiteList([512, 1024, 2048, 4096, 8192, 16384]), 'Memory in MB allocated for the function.', true)
|
||||
->param('cpus', 1, new WhiteList([1, 2, 4, 8, 16]), 'CPU Cores allocated for the function.', true)
|
||||
->inject('request')
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
@@ -169,7 +171,7 @@ App::post('/v1/functions')
|
||||
->inject('queueForBuilds')
|
||||
->inject('dbForConsole')
|
||||
->inject('gitHub')
|
||||
->action(function (string $functionId, string $name, string $runtime, array $execute, array $events, string $schedule, int $timeout, bool $enabled, bool $logging, string $entrypoint, string $commands, string $installationId, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $templateRepository, string $templateOwner, string $templateRootDirectory, string $templateBranch, Request $request, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) use ($redeployVcs) {
|
||||
->action(function (string $functionId, string $name, string $runtime, array $execute, array $events, string $schedule, int $timeout, bool $enabled, bool $logging, string $entrypoint, string $commands, string $installationId, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $templateRepository, string $templateOwner, string $templateRootDirectory, string $templateBranch, int $memory, int $cpus, Request $request, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) use ($redeployVcs) {
|
||||
$functionId = ($functionId == 'unique()') ? ID::unique() : $functionId;
|
||||
|
||||
$allowList = \array_filter(\explode(',', System::getEnv('_APP_FUNCTIONS_RUNTIMES', '')));
|
||||
@@ -229,6 +231,8 @@ App::post('/v1/functions')
|
||||
'providerBranch' => $providerBranch,
|
||||
'providerRootDirectory' => $providerRootDirectory,
|
||||
'providerSilentMode' => $providerSilentMode,
|
||||
'memory' => $memory,
|
||||
'cpus' => $cpus
|
||||
]));
|
||||
|
||||
$schedule = Authorization::skip(
|
||||
@@ -687,6 +691,8 @@ App::put('/v1/functions/:functionId')
|
||||
->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the function', true)
|
||||
->param('providerSilentMode', false, new Boolean(), 'Is the VCS (Version Control System) connection in silent mode for the repo linked to the function? In silent mode, comments will not be made on commits and pull requests.', true)
|
||||
->param('providerRootDirectory', '', new Text(128, 0), 'Path to function code in the linked repo.', true)
|
||||
->param('memory', 512, new WhiteList([512, 1024, 2048, 4096, 8192, 16384]), 'Memory in MB allocated for the function.', true)
|
||||
->param('cpus', 1, new WhiteList([1, 2, 4, 8, 16]), 'CPU Cores allocated for the function.', true)
|
||||
->inject('request')
|
||||
->inject('response')
|
||||
->inject('dbForProject')
|
||||
@@ -695,8 +701,10 @@ App::put('/v1/functions/:functionId')
|
||||
->inject('queueForBuilds')
|
||||
->inject('dbForConsole')
|
||||
->inject('gitHub')
|
||||
->action(function (string $functionId, string $name, string $runtime, array $execute, array $events, string $schedule, int $timeout, bool $enabled, bool $logging, string $entrypoint, string $commands, string $installationId, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) use ($redeployVcs) {
|
||||
->action(function (string $functionId, string $name, string $runtime, array $execute, array $events, string $schedule, int $timeout, bool $enabled, bool $logging, string $entrypoint, string $commands, string $installationId, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, int $memory, int $cpus, Request $request, Response $response, Database $dbForProject, Document $project, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github) use ($redeployVcs) {
|
||||
// TODO: If only branch changes, re-deploy
|
||||
var_dump($memory);
|
||||
var_dump($cpus);
|
||||
|
||||
$function = $dbForProject->getDocument('functions', $functionId);
|
||||
|
||||
@@ -790,7 +798,9 @@ App::put('/v1/functions/:functionId')
|
||||
$function->getAttribute('entrypoint') !== $entrypoint ||
|
||||
$function->getAttribute('commands') !== $commands ||
|
||||
$function->getAttribute('providerRootDirectory') !== $providerRootDirectory ||
|
||||
$function->getAttribute('runtime') !== $runtime
|
||||
$function->getAttribute('runtime') !== $runtime ||
|
||||
$function->getAttribute('memory') !== $memory ||
|
||||
$function->getAttribute('cpus') !== $cpus
|
||||
) {
|
||||
$live = false;
|
||||
}
|
||||
@@ -816,6 +826,8 @@ App::put('/v1/functions/:functionId')
|
||||
'providerRootDirectory' => $providerRootDirectory,
|
||||
'providerSilentMode' => $providerSilentMode,
|
||||
'search' => implode(' ', [$functionId, $name, $runtime]),
|
||||
'memory' => $memory,
|
||||
'cpus' => $cpus,
|
||||
])));
|
||||
|
||||
// Redeploy logic
|
||||
@@ -1723,6 +1735,8 @@ App::post('/v1/functions/:functionId/executions')
|
||||
path: $path,
|
||||
method: $method,
|
||||
headers: $headers,
|
||||
cpus: $function->getAttribute('cpus', 1),
|
||||
memory: $function->getAttribute('memory', 512),
|
||||
runtimeEntrypoint: $command,
|
||||
requestTimeout: 30
|
||||
);
|
||||
|
||||
@@ -270,6 +270,8 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
|
||||
path: $path,
|
||||
method: $method,
|
||||
headers: $headers,
|
||||
cpus: $function->getAttribute('cpus', 1),
|
||||
memory: $function->getAttribute('memory', 512),
|
||||
runtimeEntrypoint: $command,
|
||||
requestTimeout: 30
|
||||
);
|
||||
|
||||
Generated
+25
-25
@@ -1427,16 +1427,16 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/abuse",
|
||||
"version": "0.37.0",
|
||||
"version": "0.37.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/abuse.git",
|
||||
"reference": "2de5c12886cbd516e511e559afdd9e615d871062"
|
||||
"reference": "4dfcff4754c7804d1a70039792c0f2d59a5cc981"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/2de5c12886cbd516e511e559afdd9e615d871062",
|
||||
"reference": "2de5c12886cbd516e511e559afdd9e615d871062",
|
||||
"url": "https://api.github.com/repos/utopia-php/abuse/zipball/4dfcff4754c7804d1a70039792c0f2d59a5cc981",
|
||||
"reference": "4dfcff4754c7804d1a70039792c0f2d59a5cc981",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -1470,9 +1470,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/abuse/issues",
|
||||
"source": "https://github.com/utopia-php/abuse/tree/0.37.0"
|
||||
"source": "https://github.com/utopia-php/abuse/tree/0.37.1"
|
||||
},
|
||||
"time": "2024-03-06T21:20:27+00:00"
|
||||
"time": "2024-06-05T18:03:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/analytics",
|
||||
@@ -1522,16 +1522,16 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/audit",
|
||||
"version": "0.39.0",
|
||||
"version": "0.39.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/audit.git",
|
||||
"reference": "f0bc15012e05cc0b9dde012ab27d25f193768a2c"
|
||||
"reference": "7ea91e0ceea7b94293612fea94022b73315677c2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/audit/zipball/f0bc15012e05cc0b9dde012ab27d25f193768a2c",
|
||||
"reference": "f0bc15012e05cc0b9dde012ab27d25f193768a2c",
|
||||
"url": "https://api.github.com/repos/utopia-php/audit/zipball/7ea91e0ceea7b94293612fea94022b73315677c2",
|
||||
"reference": "7ea91e0ceea7b94293612fea94022b73315677c2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -1563,9 +1563,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/audit/issues",
|
||||
"source": "https://github.com/utopia-php/audit/tree/0.39.0"
|
||||
"source": "https://github.com/utopia-php/audit/tree/0.39.1"
|
||||
},
|
||||
"time": "2024-03-06T21:20:37+00:00"
|
||||
"time": "2024-06-05T19:28:22+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/cache",
|
||||
@@ -1719,16 +1719,16 @@
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/database",
|
||||
"version": "0.49.10",
|
||||
"version": "0.49.11",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/utopia-php/database.git",
|
||||
"reference": "216209121bc97a2010f67a39c561fafe1e936bec"
|
||||
"reference": "4f4b35d99ecdee971c3042279bb1ac8264825030"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/216209121bc97a2010f67a39c561fafe1e936bec",
|
||||
"reference": "216209121bc97a2010f67a39c561fafe1e936bec",
|
||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/4f4b35d99ecdee971c3042279bb1ac8264825030",
|
||||
"reference": "4f4b35d99ecdee971c3042279bb1ac8264825030",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -1769,9 +1769,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/utopia-php/database/issues",
|
||||
"source": "https://github.com/utopia-php/database/tree/0.49.10"
|
||||
"source": "https://github.com/utopia-php/database/tree/0.49.11"
|
||||
},
|
||||
"time": "2024-05-20T02:14:20+00:00"
|
||||
"time": "2024-05-30T12:40:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "utopia-php/domains",
|
||||
@@ -3824,16 +3824,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpstan/phpdoc-parser",
|
||||
"version": "1.29.0",
|
||||
"version": "1.29.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpstan/phpdoc-parser.git",
|
||||
"reference": "536889f2b340489d328f5ffb7b02bb6b183ddedc"
|
||||
"reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/536889f2b340489d328f5ffb7b02bb6b183ddedc",
|
||||
"reference": "536889f2b340489d328f5ffb7b02bb6b183ddedc",
|
||||
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/fcaefacf2d5c417e928405b71b400d4ce10daaf4",
|
||||
"reference": "fcaefacf2d5c417e928405b71b400d4ce10daaf4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -3865,9 +3865,9 @@
|
||||
"description": "PHPDoc parser with support for nullable, intersection and generic types",
|
||||
"support": {
|
||||
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
|
||||
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.29.0"
|
||||
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.29.1"
|
||||
},
|
||||
"time": "2024-05-06T12:04:23+00:00"
|
||||
"time": "2024-05-31T08:52:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpunit/php-code-coverage",
|
||||
@@ -5613,5 +5613,5 @@
|
||||
"platform-overrides": {
|
||||
"php": "8.3"
|
||||
},
|
||||
"plugin-api-version": "2.2.0"
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
|
||||
@@ -410,6 +410,8 @@ class Builds extends Action
|
||||
source: $source,
|
||||
image: $runtime['image'],
|
||||
version: $version,
|
||||
cpus: $function->getAttribute('cpus', 1),
|
||||
memory: $function->getAttribute('memory', 128),
|
||||
remove: true,
|
||||
entrypoint: $deployment->getAttribute('entrypoint'),
|
||||
destination: APP_STORAGE_BUILDS . "/app-{$project->getId()}",
|
||||
|
||||
@@ -469,6 +469,8 @@ class Functions extends Action
|
||||
path: $path,
|
||||
method: $method,
|
||||
headers: $headers,
|
||||
cpus: $function->getAttribute('cpus', 1),
|
||||
memory: $function->getAttribute('memory', 512),
|
||||
runtimeEntrypoint: $command
|
||||
);
|
||||
|
||||
|
||||
@@ -145,6 +145,18 @@ class Func extends Model
|
||||
'default' => false,
|
||||
'example' => false,
|
||||
])
|
||||
->addRule('memory', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Function execution memory limit in MB.',
|
||||
'default' => 512,
|
||||
'example' => 1024,
|
||||
])
|
||||
->addRule('cpus', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'Function execution cores.',
|
||||
'default' => 1,
|
||||
'example' => 2,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ class Executor
|
||||
string $source,
|
||||
string $image,
|
||||
string $version,
|
||||
int $cpus = 1,
|
||||
int $memory = 512,
|
||||
bool $remove = false,
|
||||
string $entrypoint = '',
|
||||
string $destination = '',
|
||||
@@ -83,8 +85,8 @@ class Executor
|
||||
'variables' => $variables,
|
||||
'remove' => $remove,
|
||||
'command' => $command,
|
||||
'cpus' => $this->cpus,
|
||||
'memory' => $this->memory,
|
||||
'cpus' => $cpus,
|
||||
'memory' => $memory,
|
||||
'version' => $version,
|
||||
'timeout' => $timeout,
|
||||
];
|
||||
@@ -177,6 +179,8 @@ class Executor
|
||||
string $path,
|
||||
string $method,
|
||||
array $headers,
|
||||
int $cpus,
|
||||
int $memory,
|
||||
string $runtimeEntrypoint = null,
|
||||
int $requestTimeout = null
|
||||
) {
|
||||
@@ -197,8 +201,8 @@ class Executor
|
||||
'image' => $image,
|
||||
'source' => $source,
|
||||
'entrypoint' => $entrypoint,
|
||||
'cpus' => $this->cpus,
|
||||
'memory' => $this->memory,
|
||||
'cpus' => $cpus,
|
||||
'memory' => $memory,
|
||||
'version' => $version,
|
||||
'runtimeEntrypoint' => $runtimeEntrypoint,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user