mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge pull request #9524 from appwrite/feat-deployment-total-size
Feat: totalSize attribute
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
reviews:
|
||||
auto_review:
|
||||
base_branches:
|
||||
- main
|
||||
- 1.6.x
|
||||
- 1.7.x
|
||||
- feat-sites # temporary until merged to 1.7.x
|
||||
@@ -1550,6 +1550,17 @@ return [
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('totalSize'),
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'format' => '',
|
||||
'size' => 0,
|
||||
'signed' => true,
|
||||
'required' => false,
|
||||
'default' => null,
|
||||
'array' => false,
|
||||
'filters' => [],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('status'),
|
||||
'type' => Database::VAR_STRING,
|
||||
@@ -1620,6 +1631,13 @@ return [
|
||||
'lengths' => [],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('_key_totalSize'),
|
||||
'type' => Database::INDEX_KEY,
|
||||
'attributes' => ['totalSize'],
|
||||
'lengths' => [],
|
||||
'orders' => [Database::ORDER_ASC],
|
||||
],
|
||||
[
|
||||
'$id' => ID::custom('_key_buildDuration'),
|
||||
'type' => Database::INDEX_KEY,
|
||||
|
||||
@@ -234,6 +234,7 @@ class Create extends Action
|
||||
'buildCommands' => $commands,
|
||||
'sourcePath' => $path,
|
||||
'sourceSize' => $fileSize,
|
||||
'totalSize' => $fileSize,
|
||||
'search' => implode(' ', [$deploymentId, $entrypoint]),
|
||||
'activate' => $activate,
|
||||
'sourceMetadata' => $metadata,
|
||||
@@ -264,6 +265,7 @@ class Create extends Action
|
||||
'buildCommands' => $commands,
|
||||
'sourcePath' => $path,
|
||||
'sourceSize' => $fileSize,
|
||||
'totalSize' => $fileSize,
|
||||
'sourceChunksTotal' => $chunks,
|
||||
'sourceChunksUploaded' => $chunksUploaded,
|
||||
'search' => implode(' ', [$deploymentId, $entrypoint]),
|
||||
|
||||
@@ -100,6 +100,7 @@ class Create extends Action
|
||||
'$internalId' => '',
|
||||
'$id' => $deploymentId,
|
||||
'sourcePath' => $destination,
|
||||
'totalSize' => $deployment->getAttribute('sourceSize', 0),
|
||||
'entrypoint' => $function->getAttribute('entrypoint'),
|
||||
'buildCommands' => $function->getAttribute('commands', ''),
|
||||
'search' => implode(' ', [$deploymentId, $function->getAttribute('entrypoint')]),
|
||||
|
||||
@@ -285,7 +285,8 @@ class Builds extends Action
|
||||
$directorySize = $device->getFileSize($source);
|
||||
$deployment
|
||||
->setAttribute('sourcePath', $source)
|
||||
->setAttribute('sourceSize', $directorySize);
|
||||
->setAttribute('sourceSize', $directorySize)
|
||||
->setAttribute('totalSize', $directorySize);
|
||||
$deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment);
|
||||
|
||||
$queueForRealtime
|
||||
@@ -436,7 +437,8 @@ class Builds extends Action
|
||||
|
||||
$deployment
|
||||
->setAttribute('sourcePath', $source)
|
||||
->setAttribute('sourceSize', $directorySize);
|
||||
->setAttribute('sourceSize', $directorySize)
|
||||
->setAttribute('totalSize', $directorySize);
|
||||
$deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment);
|
||||
|
||||
$queueForRealtime
|
||||
@@ -720,6 +722,7 @@ class Builds extends Action
|
||||
$deployment->setAttribute('status', 'ready');
|
||||
$deployment->setAttribute('buildPath', $response['path']);
|
||||
$deployment->setAttribute('buildSize', $response['size']);
|
||||
$deployment->setAttribute('totalSize', $deployment->getAttribute('buildSize', 0) + $deployment->getAttribute('sourceSize', 0));
|
||||
|
||||
$logs = '';
|
||||
foreach ($response['output'] as $log) {
|
||||
|
||||
@@ -243,6 +243,7 @@ class Create extends Action
|
||||
'buildOutput' => $outputDirectory,
|
||||
'sourcePath' => $path,
|
||||
'sourceSize' => $fileSize,
|
||||
'totalSize' => $fileSize,
|
||||
'search' => implode(' ', [$deploymentId]),
|
||||
'activate' => $activate,
|
||||
'sourceMetadata' => $metadata,
|
||||
@@ -300,6 +301,7 @@ class Create extends Action
|
||||
'buildOutput' => $outputDirectory,
|
||||
'sourcePath' => $path,
|
||||
'sourceSize' => $fileSize,
|
||||
'totalSize' => $fileSize,
|
||||
'sourceChunksTotal' => $chunks,
|
||||
'sourceChunksUploaded' => $chunksUploaded,
|
||||
'search' => implode(' ', [$deploymentId]),
|
||||
|
||||
@@ -111,6 +111,7 @@ class Create extends Action
|
||||
'$internalId' => '',
|
||||
'$id' => $deploymentId,
|
||||
'sourcePath' => $destination,
|
||||
'totalSize' => $deployment->getAttribute('sourceSize', 0),
|
||||
'buildCommands' => \implode(' && ', $commands),
|
||||
'buildOutput' => $site->getAttribute('outputDirectory', ''),
|
||||
'search' => implode(' ', [$deploymentId]),
|
||||
@@ -118,8 +119,8 @@ class Create extends Action
|
||||
'screenshotDark' => '',
|
||||
'buildStartAt' => null,
|
||||
'buildEndAt' => null,
|
||||
'buildDuration' => null,
|
||||
'buildSize' => null,
|
||||
'buildDuration' => 0,
|
||||
'buildSize' => 0,
|
||||
'status' => 'waiting',
|
||||
'buildPath' => '',
|
||||
'buildLogs' => '',
|
||||
|
||||
@@ -7,6 +7,7 @@ class Deployments extends Base
|
||||
public const ALLOWED_ATTRIBUTES = [
|
||||
'buildSize',
|
||||
'sourceSize',
|
||||
'totalSize',
|
||||
'buildDuration',
|
||||
'status',
|
||||
'activate',
|
||||
|
||||
@@ -64,6 +64,12 @@ class Deployment extends Model
|
||||
'default' => 0,
|
||||
'example' => 128,
|
||||
])
|
||||
->addRule('totalSize', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'The total size in bytes (source and build output).',
|
||||
'default' => 0,
|
||||
'example' => 128,
|
||||
])
|
||||
->addRule('buildId', [
|
||||
'type' => self::TYPE_STRING,
|
||||
'description' => 'The current build ID.',
|
||||
|
||||
@@ -408,6 +408,12 @@ class FunctionsCustomServerTest extends Scope
|
||||
$this->assertEquals(202, $deployment['headers']['status-code']);
|
||||
$this->assertNotEmpty($deployment['body']['$id']);
|
||||
|
||||
$deployment = $this->getDeployment($functionId, $deployment['body']['$id']);
|
||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||
$this->assertEquals(0, $deployment['body']['sourceSize']);
|
||||
$this->assertEquals(0, $deployment['body']['buildSize']);
|
||||
$this->assertEquals(0, $deployment['body']['totalSize']);
|
||||
|
||||
$deployments = $this->listDeployments($functionId);
|
||||
|
||||
$this->assertEquals(200, $deployments['headers']['status-code']);
|
||||
@@ -480,7 +486,14 @@ class FunctionsCustomServerTest extends Scope
|
||||
$this->assertStringContainsString("Total users: " . $totalUsers, $execution['body']['logs']);
|
||||
}, 10000, 500);
|
||||
|
||||
$function = $this->deleteFunction($functionId);
|
||||
$deployment = $this->getDeployment($functionId, $deployment['body']['$id']);
|
||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||
$this->assertGreaterThan(0, $deployment['body']['sourceSize']);
|
||||
$this->assertGreaterThan(0, $deployment['body']['buildSize']);
|
||||
$totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize'];
|
||||
$this->assertEquals($totalSize, $deployment['body']['totalSize']);
|
||||
|
||||
$function = $this->cleanupFunction($functionId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1634,11 +1647,14 @@ class FunctionsCustomServerTest extends Scope
|
||||
'entrypoint' => 'index.php',
|
||||
'timeout' => 15,
|
||||
]);
|
||||
$this->setupDeployment($functionId, [
|
||||
$this->assertNotEmpty($functionId);
|
||||
|
||||
$deploymentId = $this->setupDeployment($functionId, [
|
||||
'entrypoint' => 'index.php',
|
||||
'code' => $this->packageFunction('php-cookie'),
|
||||
'activate' => true
|
||||
]);
|
||||
$this->assertNotEmpty($deploymentId);
|
||||
|
||||
$cookie = 'cookieName=cookieValue; cookie2=value2; cookie3=value=3; cookie4=val:ue4; cookie5=value5';
|
||||
$execution = $this->createExecution($functionId, [
|
||||
@@ -1654,6 +1670,13 @@ class FunctionsCustomServerTest extends Scope
|
||||
$this->assertEquals($cookie, $execution['body']['responseBody']);
|
||||
$this->assertGreaterThan(0, $execution['body']['duration']);
|
||||
|
||||
$deployment = $this->getDeployment($functionId, $deploymentId);
|
||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||
$this->assertGreaterThan(0, $deployment['body']['sourceSize']);
|
||||
$this->assertGreaterThan(0, $deployment['body']['buildSize']);
|
||||
$totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize'];
|
||||
$this->assertEquals($totalSize, $deployment['body']['totalSize']);
|
||||
|
||||
$this->cleanupFunction($functionId);
|
||||
}
|
||||
|
||||
@@ -2029,13 +2052,34 @@ class FunctionsCustomServerTest extends Scope
|
||||
$this->assertEquals(200, $function['headers']['status-code']);
|
||||
$this->assertStringContainsString('maintenance.js', $function['body']['commands']);
|
||||
|
||||
$deploymentId2 = $this->setupDuplicateDeployment($functionId, $deploymentId1);
|
||||
$deployment = $this->createDuplicateDeployment($functionId, $deploymentId1);
|
||||
$this->assertEquals(202, $deployment['headers']['status-code']);
|
||||
|
||||
$deploymentId2 = $deployment['body']['$id'];
|
||||
$this->assertNotEmpty($deploymentId2);
|
||||
|
||||
$deployment = $this->getDeployment($functionId, $deploymentId2);
|
||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||
$this->assertGreaterThan(0, $deployment['body']['sourceSize']);
|
||||
$this->assertEquals(0, $deployment['body']['buildSize']);
|
||||
$this->assertEquals($deployment['body']['sourceSize'], $deployment['body']['totalSize']);
|
||||
|
||||
$this->assertEventually(function () use ($functionId, $deploymentId2) {
|
||||
$function = $this->getFunction($functionId);
|
||||
$this->assertEquals($deploymentId2, $function['body']['deploymentId']);
|
||||
}, 50000, 500);
|
||||
|
||||
$execution = $this->createExecution($functionId);
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
$this->assertStringContainsString('Maintenance', $execution['body']['responseBody']);
|
||||
|
||||
$deployment = $this->getDeployment($functionId, $deploymentId2);
|
||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||
$this->assertGreaterThan(0, $deployment['body']['sourceSize']);
|
||||
$this->assertGreaterThan(0, $deployment['body']['buildSize']);
|
||||
$totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize'];
|
||||
$this->assertEquals($totalSize, $deployment['body']['totalSize']);
|
||||
|
||||
$this->cleanupFunction($functionId);
|
||||
}
|
||||
|
||||
|
||||
@@ -360,6 +360,13 @@ class SitesCustomServerTest extends Scope
|
||||
$this->assertStringContainsString("Env variable is Appwrite", $response['body']);
|
||||
$this->assertStringNotContainsString("Variable not found", $response['body']);
|
||||
|
||||
$deployment = $this->getDeployment($siteId, $deploymentId);
|
||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||
$this->assertGreaterThan(0, $deployment['body']['sourceSize']);
|
||||
$this->assertGreaterThan(0, $deployment['body']['buildSize']);
|
||||
$totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize'];
|
||||
$this->assertEquals($totalSize, $deployment['body']['totalSize']);
|
||||
|
||||
$this->cleanupSite($siteId);
|
||||
}
|
||||
|
||||
@@ -1515,6 +1522,12 @@ class SitesCustomServerTest extends Scope
|
||||
$this->assertEquals(202, $deployment['headers']['status-code']);
|
||||
$this->assertNotEmpty($deployment['body']['$id']);
|
||||
|
||||
$deployment = $this->getDeployment($siteId, $deployment['body']['$id']);
|
||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||
$this->assertEquals(0, $deployment['body']['sourceSize']);
|
||||
$this->assertEquals(0, $deployment['body']['buildSize']);
|
||||
$this->assertEquals(0, $deployment['body']['totalSize']);
|
||||
|
||||
$this->assertEventually(function () use ($siteId) {
|
||||
$site = $this->getSite($siteId);
|
||||
$this->assertNotEmpty($site['body']['deploymentId']);
|
||||
@@ -1536,6 +1549,13 @@ class SitesCustomServerTest extends Scope
|
||||
$this->assertStringContainsString("Astro Blog", $response['body']);
|
||||
$this->assertStringContainsString("About Me", $response['body']);
|
||||
|
||||
$deployment = $this->getDeployment($siteId, $deployment['body']['$id']);
|
||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||
$this->assertGreaterThan(0, $deployment['body']['sourceSize']);
|
||||
$this->assertGreaterThan(0, $deployment['body']['buildSize']);
|
||||
$totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize'];
|
||||
$this->assertEquals($totalSize, $deployment['body']['totalSize']);
|
||||
|
||||
$this->cleanupSite($siteId);
|
||||
}
|
||||
|
||||
@@ -1985,12 +2005,33 @@ class SitesCustomServerTest extends Scope
|
||||
$this->assertEquals(200, $site['headers']['status-code']);
|
||||
$this->assertEquals('index.html', $site['body']['fallbackFile']);
|
||||
|
||||
$deploymentId2 = $this->setupDuplicateDeployment($siteId, $deploymentId1);
|
||||
$deployment = $this->createDuplicateDeployment($siteId, $deploymentId1);
|
||||
$this->assertEquals(202, $deployment['headers']['status-code']);
|
||||
|
||||
$deploymentId2 = $deployment['body']['$id'];
|
||||
$this->assertNotEmpty($deploymentId2);
|
||||
|
||||
$deployment = $this->getDeployment($siteId, $deploymentId2);
|
||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||
$this->assertGreaterThan(0, $deployment['body']['sourceSize']);
|
||||
$this->assertEquals(0, $deployment['body']['buildSize']);
|
||||
$this->assertEquals($deployment['body']['sourceSize'], $deployment['body']['totalSize']);
|
||||
|
||||
$this->assertEventually(function () use ($siteId, $deploymentId2) {
|
||||
$site = $this->getSite($siteId);
|
||||
$this->assertEquals($deploymentId2, $site['body']['deploymentId']);
|
||||
}, 50000, 500);
|
||||
|
||||
$response = $proxyClient->call(Client::METHOD_GET, '/not-found');
|
||||
$this->assertStringContainsString("Index page", $response['body']);
|
||||
|
||||
$deployment = $this->getDeployment($siteId, $deploymentId2);
|
||||
$this->assertEquals(200, $deployment['headers']['status-code']);
|
||||
$this->assertGreaterThan(0, $deployment['body']['sourceSize']);
|
||||
$this->assertGreaterThan(0, $deployment['body']['buildSize']);
|
||||
$totalSize = $deployment['body']['sourceSize'] + $deployment['body']['buildSize'];
|
||||
$this->assertEquals($totalSize, $deployment['body']['totalSize']);
|
||||
|
||||
$this->cleanupSite($siteId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user