mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Update default site build specification
This commit is contained in:
1 parent
69b49c7228
commit
6797986574
8 files changed
+47
-13
No files matched your search
@@ -1306,7 +1306,7 @@ return [
|
||||
'size' => 128,
|
||||
'signed' => false,
|
||||
'required' => false,
|
||||
'default' => APP_COMPUTE_SPECIFICATION_DEFAULT,
|
||||
'default' => APP_SITES_BUILD_SPECIFICATION_DEFAULT,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
|
||||
@@ -98,6 +98,7 @@ const APP_SOCIAL_YOUTUBE = 'https://www.youtube.com/c/appwrite?sub_confirmation=
|
||||
const APP_COMPUTE_CPUS_DEFAULT = 0.5;
|
||||
const APP_COMPUTE_MEMORY_DEFAULT = 512;
|
||||
const APP_COMPUTE_SPECIFICATION_DEFAULT = Specification::S_1VCPU_512MB;
|
||||
const APP_SITES_BUILD_SPECIFICATION_DEFAULT = Specification::S_2VCPU_2GB;
|
||||
const APP_COMPUTE_DEPLOYMENT_MAX_RETENTION = 100 * 365; // 100 years
|
||||
const APP_SDK_PLATFORM_SERVER = 'server';
|
||||
const APP_SDK_PLATFORM_CLIENT = 'client';
|
||||
|
||||
@@ -33,29 +33,34 @@ class Base extends Action
|
||||
* @param array $plan The billing plan configuration
|
||||
* @return string The appropriate default specification
|
||||
*/
|
||||
protected function getDefaultSpecification(array $plan): string
|
||||
protected function getDefaultSpecification(array $plan, string $planKey = 'runtimeSpecifications', string $fallback = APP_COMPUTE_SPECIFICATION_DEFAULT, bool $preferFallback = false): string
|
||||
{
|
||||
$specifications = Config::getParam('specifications', []);
|
||||
|
||||
if (empty($specifications)) {
|
||||
return APP_COMPUTE_SPECIFICATION_DEFAULT;
|
||||
return $fallback;
|
||||
}
|
||||
|
||||
$specificationValidator = new SpecificationValidator(
|
||||
$plan,
|
||||
$specifications,
|
||||
System::getEnv('_APP_COMPUTE_CPUS', 0),
|
||||
System::getEnv('_APP_COMPUTE_MEMORY', 0)
|
||||
System::getEnv('_APP_COMPUTE_MEMORY', 0),
|
||||
$planKey
|
||||
);
|
||||
$allowedSpecifications = $specificationValidator->getAllowedSpecifications();
|
||||
|
||||
if ($preferFallback && !array_key_exists($planKey, $plan) && \in_array($fallback, $allowedSpecifications)) {
|
||||
return $fallback;
|
||||
}
|
||||
|
||||
// If there is no plan use the highest specification
|
||||
if (empty($plan)) {
|
||||
return end($allowedSpecifications) ?? APP_COMPUTE_SPECIFICATION_DEFAULT;
|
||||
return end($allowedSpecifications) ?? $fallback;
|
||||
}
|
||||
|
||||
// Otherwise, use the lowest specification available in the plan
|
||||
return $allowedSpecifications[0] ?? APP_COMPUTE_SPECIFICATION_DEFAULT;
|
||||
return $allowedSpecifications[0] ?? $fallback;
|
||||
}
|
||||
|
||||
public function redeployVcsFunction(Request $request, Document $function, Document $project, Document $installation, Database $dbForProject, BuildPublisher $publisherForBuilds, Document $template, GitHub $github, bool $activate, array $platform = [], string $referenceType = 'branch', string $reference = ''): Document
|
||||
|
||||
@@ -14,12 +14,15 @@ class Specification extends Validator
|
||||
|
||||
private int $maxMemory;
|
||||
|
||||
public function __construct(array $plan, array $specifications, float $maxCpus, int $maxMemory)
|
||||
private string $planKey;
|
||||
|
||||
public function __construct(array $plan, array $specifications, float $maxCpus, int $maxMemory, string $planKey = 'runtimeSpecifications')
|
||||
{
|
||||
$this->plan = $plan;
|
||||
$this->specifications = $specifications;
|
||||
$this->maxCpus = $maxCpus;
|
||||
$this->maxMemory = $maxMemory;
|
||||
$this->planKey = $planKey;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,8 +38,8 @@ class Specification extends Validator
|
||||
|
||||
foreach ($this->specifications as $size => $values) {
|
||||
if ((empty($this->maxCpus) || $values['cpus'] <= $this->maxCpus) && (empty($this->maxMemory) || $values['memory'] <= $this->maxMemory)) {
|
||||
if (!empty($this->plan) && array_key_exists('runtimeSpecifications', $this->plan)) {
|
||||
if (!\in_array($size, $this->plan['runtimeSpecifications'])) {
|
||||
if (!empty($this->plan) && array_key_exists($this->planKey, $this->plan)) {
|
||||
if (!\in_array($size, $this->plan[$this->planKey])) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,11 +82,12 @@ class Create extends Base
|
||||
->param('providerRootDirectory', '', new Text(128, 0), 'Path to site code in the linked repo.', true)
|
||||
->param('providerBranches', [], new ArrayList(new Text(128), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of branch name patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all branches.', true)
|
||||
->param('providerPaths', [], new ArrayList(new Text(128), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of file path patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all file changes.', true)
|
||||
->param('buildSpecification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification(
|
||||
->param('buildSpecification', fn (array $plan) => $this->getDefaultSpecification($plan, 'buildSpecifications', APP_SITES_BUILD_SPECIFICATION_DEFAULT, true), fn (array $plan) => new Specification(
|
||||
$plan,
|
||||
Config::getParam('specifications', []),
|
||||
System::getEnv('_APP_COMPUTE_CPUS', 0),
|
||||
System::getEnv('_APP_COMPUTE_MEMORY', 0)
|
||||
System::getEnv('_APP_COMPUTE_MEMORY', 0),
|
||||
'buildSpecifications'
|
||||
), 'Build specification for the site deployments.', true, ['plan'])
|
||||
->param('runtimeSpecification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification(
|
||||
$plan,
|
||||
|
||||
@@ -86,11 +86,12 @@ class Update extends Base
|
||||
->param('providerRootDirectory', '', new Text(128, 0), 'Path to site code in the linked repo.', true)
|
||||
->param('providerBranches', null, new Nullable(new ArrayList(new Text(128), APP_LIMIT_ARRAY_PARAMS_SIZE)), 'List of branch name patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all branches.', true)
|
||||
->param('providerPaths', null, new Nullable(new ArrayList(new Text(128), APP_LIMIT_ARRAY_PARAMS_SIZE)), 'List of file path patterns to trigger automatic deployments. Supports wildcards. Leave empty to deploy on all file changes.', true)
|
||||
->param('buildSpecification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification(
|
||||
->param('buildSpecification', fn (array $plan) => $this->getDefaultSpecification($plan, 'buildSpecifications', APP_SITES_BUILD_SPECIFICATION_DEFAULT, true), fn (array $plan) => new Specification(
|
||||
$plan,
|
||||
Config::getParam('specifications', []),
|
||||
System::getEnv('_APP_COMPUTE_CPUS', 0),
|
||||
System::getEnv('_APP_COMPUTE_MEMORY', 0)
|
||||
System::getEnv('_APP_COMPUTE_MEMORY', 0),
|
||||
'buildSpecifications'
|
||||
), 'Build specification for the site deployments.', true, ['plan'])
|
||||
->param('runtimeSpecification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification(
|
||||
$plan,
|
||||
|
||||
@@ -100,6 +100,7 @@ class SitesCustomServerTest extends Scope
|
||||
$this->assertEquals(true, $dateValidator->isValid($site['body']['$createdAt']));
|
||||
$this->assertEquals(true, $dateValidator->isValid($site['body']['$updatedAt']));
|
||||
$this->assertEquals('node-22', $site['body']['buildRuntime']);
|
||||
$this->assertEquals(Specification::S_2VCPU_2GB, $site['body']['buildSpecification']);
|
||||
$this->assertEquals(null, $site['body']['fallbackFile']);
|
||||
$this->assertEquals('./', $site['body']['outputDirectory']);
|
||||
|
||||
|
||||
@@ -72,4 +72,26 @@ class SpecificationTest extends TestCase
|
||||
$this->assertContains(SpecificationConstants::S_05VCPU_512MB, $allowed);
|
||||
$this->assertContains(SpecificationConstants::S_1VCPU_512MB, $allowed);
|
||||
}
|
||||
|
||||
public function testGetAllowedSpecificationsWithBuildPlanLimits(): void
|
||||
{
|
||||
$plan = [
|
||||
'buildSpecifications' => [
|
||||
SpecificationConstants::S_1VCPU_1GB,
|
||||
SpecificationConstants::S_2VCPU_2GB,
|
||||
]
|
||||
];
|
||||
$validator = new Specification(
|
||||
plan: $plan,
|
||||
specifications: $this->specifications,
|
||||
maxCpus: 0,
|
||||
maxMemory: 0,
|
||||
planKey: 'buildSpecifications'
|
||||
);
|
||||
|
||||
$allowed = $validator->getAllowedSpecifications();
|
||||
$this->assertCount(2, $allowed);
|
||||
$this->assertContains(SpecificationConstants::S_1VCPU_1GB, $allowed);
|
||||
$this->assertContains(SpecificationConstants::S_2VCPU_2GB, $allowed);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user