mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
Merge pull request #9863 from appwrite/feat-add-configurable-resource-size
Add configurable deployment and build size
This commit is contained in:
commit
4adea70684
4 changed files with 39 additions and 9 deletions
|
|
@ -240,6 +240,7 @@ Server::setResource('timelimit', function (\Redis $redis) {
|
||||||
|
|
||||||
Server::setResource('log', fn () => new Log());
|
Server::setResource('log', fn () => new Log());
|
||||||
|
|
||||||
|
|
||||||
Server::setResource('publisher', function (Group $pools) {
|
Server::setResource('publisher', function (Group $pools) {
|
||||||
return new BrokerPool(publisher: $pools->get('publisher'));
|
return new BrokerPool(publisher: $pools->get('publisher'));
|
||||||
}, ['pools']);
|
}, ['pools']);
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ class Create extends Action
|
||||||
->inject('deviceForFunctions')
|
->inject('deviceForFunctions')
|
||||||
->inject('deviceForLocal')
|
->inject('deviceForLocal')
|
||||||
->inject('queueForBuilds')
|
->inject('queueForBuilds')
|
||||||
|
->inject('plan')
|
||||||
->callback([$this, 'action']);
|
->callback([$this, 'action']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,7 +103,8 @@ class Create extends Action
|
||||||
Document $project,
|
Document $project,
|
||||||
Device $deviceForFunctions,
|
Device $deviceForFunctions,
|
||||||
Device $deviceForLocal,
|
Device $deviceForLocal,
|
||||||
Build $queueForBuilds
|
Build $queueForBuilds,
|
||||||
|
array $plan
|
||||||
) {
|
) {
|
||||||
$activate = \strval($activate) === 'true' || \strval($activate) === '1';
|
$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');
|
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]);
|
$fileExt = new FileExt([FileExt::TYPE_GZIP]);
|
||||||
$fileSizeValidator = new FileSize(System::getEnv('_APP_COMPUTE_SIZE_LIMIT', '30000000'));
|
$fileSizeValidator = new FileSize($functionSizeLimit);
|
||||||
$upload = new Upload();
|
$upload = new Upload();
|
||||||
|
|
||||||
// Make sure we handle a single file and multiple files the same way
|
// Make sure we handle a single file and multiple files the same way
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ class Builds extends Action
|
||||||
->inject('deviceForFiles')
|
->inject('deviceForFiles')
|
||||||
->inject('log')
|
->inject('log')
|
||||||
->inject('executor')
|
->inject('executor')
|
||||||
|
->inject('plan')
|
||||||
->callback([$this, 'action']);
|
->callback([$this, 'action']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,6 +93,7 @@ class Builds extends Action
|
||||||
* @param Device $deviceForFiles
|
* @param Device $deviceForFiles
|
||||||
* @param Log $log
|
* @param Log $log
|
||||||
* @param Executor $executor
|
* @param Executor $executor
|
||||||
|
* @param array $plan
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \Utopia\Database\Exception
|
* @throws \Utopia\Database\Exception
|
||||||
*/
|
*/
|
||||||
|
|
@ -111,7 +113,8 @@ class Builds extends Action
|
||||||
callable $isResourceBlocked,
|
callable $isResourceBlocked,
|
||||||
Device $deviceForFiles,
|
Device $deviceForFiles,
|
||||||
Log $log,
|
Log $log,
|
||||||
Executor $executor
|
Executor $executor,
|
||||||
|
array $plan
|
||||||
): void {
|
): void {
|
||||||
$payload = $message->getPayload() ?? [];
|
$payload = $message->getPayload() ?? [];
|
||||||
|
|
||||||
|
|
@ -150,7 +153,8 @@ class Builds extends Action
|
||||||
$template,
|
$template,
|
||||||
$isResourceBlocked,
|
$isResourceBlocked,
|
||||||
$log,
|
$log,
|
||||||
$executor
|
$executor,
|
||||||
|
$plan
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -177,6 +181,7 @@ class Builds extends Action
|
||||||
* @param Document $template
|
* @param Document $template
|
||||||
* @param Log $log
|
* @param Log $log
|
||||||
* @param Executor $executor
|
* @param Executor $executor
|
||||||
|
* @param array $plan
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \Utopia\Database\Exception
|
* @throws \Utopia\Database\Exception
|
||||||
*
|
*
|
||||||
|
|
@ -200,7 +205,8 @@ class Builds extends Action
|
||||||
Document $template,
|
Document $template,
|
||||||
callable $isResourceBlocked,
|
callable $isResourceBlocked,
|
||||||
Log $log,
|
Log $log,
|
||||||
Executor $executor
|
Executor $executor,
|
||||||
|
array $plan
|
||||||
): void {
|
): void {
|
||||||
$resourceKey = match ($resource->getCollection()) {
|
$resourceKey = match ($resource->getCollection()) {
|
||||||
'functions' => 'functionId',
|
'functions' => 'functionId',
|
||||||
|
|
@ -476,8 +482,12 @@ class Builds extends Action
|
||||||
$directorySize = $localDevice->getDirectorySize($tmpDirectory);
|
$directorySize = $localDevice->getDirectorySize($tmpDirectory);
|
||||||
$sizeLimit = (int)System::getEnv('_APP_COMPUTE_SIZE_LIMIT', '30000000');
|
$sizeLimit = (int)System::getEnv('_APP_COMPUTE_SIZE_LIMIT', '30000000');
|
||||||
|
|
||||||
|
if (isset($plan['deploymentSize'])) {
|
||||||
|
$sizeLimit = (int) $plan['deploymentSize'] * 1000 * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
if ($directorySize > $sizeLimit) {
|
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);
|
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);
|
$durationEnd = \microtime(true);
|
||||||
|
|
||||||
$buildSizeLimit = (int)System::getEnv('_APP_COMPUTE_BUILD_SIZE_LIMIT', '2000000000');
|
$buildSizeLimit = (int)System::getEnv('_APP_COMPUTE_BUILD_SIZE_LIMIT', '2000000000');
|
||||||
|
if (isset($plan['buildSize'])) {
|
||||||
|
$buildSizeLimit = $plan['buildSize'] * 1000 * 1000;
|
||||||
|
}
|
||||||
if ($response['size'] > $buildSizeLimit) {
|
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 */
|
/** Update the build document */
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ class Create extends Action
|
||||||
->inject('deviceForSites')
|
->inject('deviceForSites')
|
||||||
->inject('deviceForLocal')
|
->inject('deviceForLocal')
|
||||||
->inject('queueForBuilds')
|
->inject('queueForBuilds')
|
||||||
|
->inject('plan')
|
||||||
->callback([$this, 'action']);
|
->callback([$this, 'action']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,7 +104,8 @@ class Create extends Action
|
||||||
Event $queueForEvents,
|
Event $queueForEvents,
|
||||||
Device $deviceForSites,
|
Device $deviceForSites,
|
||||||
Device $deviceForLocal,
|
Device $deviceForLocal,
|
||||||
Build $queueForBuilds
|
Build $queueForBuilds,
|
||||||
|
array $plan
|
||||||
) {
|
) {
|
||||||
$activate = \strval($activate) === 'true' || \strval($activate) === '1';
|
$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');
|
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]);
|
$fileExt = new FileExt([FileExt::TYPE_GZIP]);
|
||||||
$fileSizeValidator = new FileSize(System::getEnv('_APP_COMPUTE_SIZE_LIMIT', '30000000'));
|
$fileSizeValidator = new FileSize($siteSizeLimit);
|
||||||
$upload = new Upload();
|
$upload = new Upload();
|
||||||
|
|
||||||
// Make sure we handle a single file and multiple files the same way
|
// Make sure we handle a single file and multiple files the same way
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue