Merge pull request #9863 from appwrite/feat-add-configurable-resource-size

Add configurable deployment and build size
This commit is contained in:
Matej Bačo 2025-05-22 15:28:40 +02:00 committed by GitHub
commit 4adea70684
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 39 additions and 9 deletions

View file

@ -240,6 +240,7 @@ Server::setResource('timelimit', function (\Redis $redis) {
Server::setResource('log', fn () => new Log());
Server::setResource('publisher', function (Group $pools) {
return new BrokerPool(publisher: $pools->get('publisher'));
}, ['pools']);

View file

@ -86,6 +86,7 @@ class Create extends Action
->inject('deviceForFunctions')
->inject('deviceForLocal')
->inject('queueForBuilds')
->inject('plan')
->callback([$this, 'action']);
}
@ -102,7 +103,8 @@ class Create extends Action
Document $project,
Device $deviceForFunctions,
Device $deviceForLocal,
Build $queueForBuilds
Build $queueForBuilds,
array $plan
) {
$activate = \strval($activate) === 'true' || \strval($activate) === '1';
@ -135,8 +137,14 @@ class Create extends Action
throw new Exception(Exception::STORAGE_FILE_EMPTY, 'No file sent');
}
$functionSizeLimit = (int) System::getEnv('_APP_COMPUTE_SIZE_LIMIT', '30000000');
if (isset($plan['deploymentSize'])) {
$functionSizeLimit = $plan['deploymentSize'] * 1000 * 1000;
}
$fileExt = new FileExt([FileExt::TYPE_GZIP]);
$fileSizeValidator = new FileSize(System::getEnv('_APP_COMPUTE_SIZE_LIMIT', '30000000'));
$fileSizeValidator = new FileSize($functionSizeLimit);
$upload = new Upload();
// Make sure we handle a single file and multiple files the same way

View file

@ -73,6 +73,7 @@ class Builds extends Action
->inject('deviceForFiles')
->inject('log')
->inject('executor')
->inject('plan')
->callback([$this, 'action']);
}
@ -92,6 +93,7 @@ class Builds extends Action
* @param Device $deviceForFiles
* @param Log $log
* @param Executor $executor
* @param array $plan
* @return void
* @throws \Utopia\Database\Exception
*/
@ -111,7 +113,8 @@ class Builds extends Action
callable $isResourceBlocked,
Device $deviceForFiles,
Log $log,
Executor $executor
Executor $executor,
array $plan
): void {
$payload = $message->getPayload() ?? [];
@ -150,7 +153,8 @@ class Builds extends Action
$template,
$isResourceBlocked,
$log,
$executor
$executor,
$plan
);
break;
@ -177,6 +181,7 @@ class Builds extends Action
* @param Document $template
* @param Log $log
* @param Executor $executor
* @param array $plan
* @return void
* @throws \Utopia\Database\Exception
*
@ -200,7 +205,8 @@ class Builds extends Action
Document $template,
callable $isResourceBlocked,
Log $log,
Executor $executor
Executor $executor,
array $plan
): void {
$resourceKey = match ($resource->getCollection()) {
'functions' => 'functionId',
@ -476,8 +482,12 @@ class Builds extends Action
$directorySize = $localDevice->getDirectorySize($tmpDirectory);
$sizeLimit = (int)System::getEnv('_APP_COMPUTE_SIZE_LIMIT', '30000000');
if (isset($plan['deploymentSize'])) {
$sizeLimit = (int) $plan['deploymentSize'] * 1000 * 1000;
}
if ($directorySize > $sizeLimit) {
throw new \Exception('Repository directory size should be less than ' . number_format($sizeLimit / 1048576, 2) . ' MBs.');
throw new \Exception('Repository directory size should be less than ' . number_format($sizeLimit / (1000 * 1000), 2) . ' MBs.');
}
Console::execute('find ' . \escapeshellarg($tmpDirectory) . ' -type d -name ".git" -exec rm -rf {} +', '', $stdout, $stderr);
@ -803,8 +813,11 @@ class Builds extends Action
$durationEnd = \microtime(true);
$buildSizeLimit = (int)System::getEnv('_APP_COMPUTE_BUILD_SIZE_LIMIT', '2000000000');
if (isset($plan['buildSize'])) {
$buildSizeLimit = $plan['buildSize'] * 1000 * 1000;
}
if ($response['size'] > $buildSizeLimit) {
throw new \Exception('Build size should be less than ' . number_format($buildSizeLimit / 1048576, 2) . ' MBs.');
throw new \Exception('Build size should be less than ' . number_format($buildSizeLimit / (1000 * 1000), 2) . ' MBs.');
}
/** Update the build document */

View file

@ -85,6 +85,7 @@ class Create extends Action
->inject('deviceForSites')
->inject('deviceForLocal')
->inject('queueForBuilds')
->inject('plan')
->callback([$this, 'action']);
}
@ -103,7 +104,8 @@ class Create extends Action
Event $queueForEvents,
Device $deviceForSites,
Device $deviceForLocal,
Build $queueForBuilds
Build $queueForBuilds,
array $plan
) {
$activate = \strval($activate) === 'true' || \strval($activate) === '1';
@ -136,8 +138,14 @@ class Create extends Action
throw new Exception(Exception::STORAGE_FILE_EMPTY, 'No file sent');
}
$siteSizeLimit = (int) System::getEnv('_APP_COMPUTE_SIZE_LIMIT', '30000000');
if (isset($plan['deploymentSize'])) {
$siteSizeLimit = $plan['deploymentSize'] * 1000 * 1000;
}
$fileExt = new FileExt([FileExt::TYPE_GZIP]);
$fileSizeValidator = new FileSize(System::getEnv('_APP_COMPUTE_SIZE_LIMIT', '30000000'));
$fileSizeValidator = new FileSize($siteSizeLimit);
$upload = new Upload();
// Make sure we handle a single file and multiple files the same way