8000 Add configurable deployment and build size by vermakhushboo · Pull Request #9863 · appwrite/appwrite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add configurable deployment and build size #9863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@

Server::setResource('log', fn () => new Log());


Server::setResource('publisher', function (Group $pools) {
return new BrokerPool(publisher: $pools->get('publisher'));
}, ['pools']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function __construct()
->inject('deviceForFunctions')
->inject('deviceForLocal')
->inject('queueForBuilds')
->inject('plan')
->callback([$this, 'action']);
}

Expand All @@ -102,7 +103,8 @@ public function action(
Document $project,
Device $deviceForFunctions,
Device $deviceForLocal,
Build $queueForBuilds
Build $queueForBuilds,
array $plan
) {
$activate = \strval($activate) === 'true' || \strval($activate) === '1';

Expand Down Expand Up @@ -135,8 +137,14 @@ public function 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
Expand Down
23 changes: 18 additions & 5 deletions src/Appwrite/Platform/Modules/Functions/Workers/Builds.php
10000
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function __construct()
->inject('deviceForFiles')
->inject('log')
->inject('executor')
->inject('plan')
->callback([$this, 'action']);
}

Expand All @@ -92,6 +93,7 @@ public function __construct()
* @param Device $deviceForFiles
* @param Log $log
* @param Executor $executor
* @param array $plan
* @return void
* @throws \Utopia\Database\Exception
*/
Expand All @@ -111,7 +113,8 @@ public function action(
callable $isResourceBlocked,
Device $deviceForFiles,
Log $log,
Executor $executor
Executor $executor,
array $plan
): void {
$payload = $message->getPayload() ?? [];

Expand Down Expand Up @@ -150,7 +153,8 @@ public function action(
$template,
$isResourceBlocked,
$log,
$executor
$executor,
$plan
);
break;

Expand All @@ -177,6 +181,7 @@ public function action(
* @param Document $template
* @param Log $log
* @param Executor $executor
* @param array $plan
* @return void
* @throws \Utopia\Database\Exception
*
Expand All @@ -200,7 +205,8 @@ protected function buildDeployment(
Document $template,
callable $isResourceBlocked,
Log $log,
Executor $executor
Executor $executor,
array $plan
): void {
$resourceKey = match ($resource->getCollection()) {
'functions' => 'functionId',
Expand Down Expand Up @@ -476,8 +482,12 @@ protected function buildDeployment(
$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);
Expand Down Expand Up @@ -803,8 +813,11 @@ protected function buildDeployment(
$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 */
Expand Down
12 changes: 10 additions & 2 deletions src/Appwrite/Platform/Modules/Sites/Http/Deployments/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function __construct()
->inject('deviceForSites')
->inject('deviceForLocal')
->inject('queueForBuilds')
->inject('plan')
->callback([$this, 'action']);
}

Expand All @@ -103,7 +104,8 @@ public function action(
Event $queueForEvents,
Device $deviceForSites,
Device $deviceForLocal,
Build $queueForBuilds
Build $queueForBuilds,
array $plan
) {
$activate = \strval($activate) === 'true' || \strval($activate) === '1';

Expand Down Expand Up @@ -136,8 +138,14 @@ public function 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
Expand Down
0