Implement toggle for deployment screenshotting for sites

This commit is contained in:
Matej Bačo
2025-12-31 15:11:42 +01:00
parent 07135956df
commit 5ed59fcf1b
7 changed files with 144 additions and 1 deletions
+11
View File
@@ -1222,6 +1222,17 @@ return [
'array' => false,
'filters' => [],
],
[
'$id' => ID::custom('deploymentScreenshots'),
'type' => Database::VAR_BOOLEAN,
'signed' => true,
'size' => 0,
'format' => '',
'filters' => [],
'required' => false,
'default' => true,
'array' => false,
],
],
'indexes' => [
[
@@ -916,7 +916,7 @@ class Builds extends Action
$logs = $deployment->getAttribute('buildLogs', '');
/** Screenshot site */
if ($resource->getCollection() === 'sites') {
if ($resource->getCollection() === 'sites' && $resource->getAttribute('deploymentScreenshots', true)) {
Console::log('Site screenshot started');
$date = \date('H:i:s');
@@ -78,6 +78,7 @@ class Create extends Base
->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the site.', true)
->param('providerSilentMode', false, new Boolean(), 'Is the VCS (Version Control System) connection in silent mode for the repo linked to the site? In silent mode, comments will not be made on commits and pull requests.', true)
->param('providerRootDirectory', '', new Text(128, 0), 'Path to site code in the linked repo.', true)
->param('deploymentScreenshots', true, new Boolean(), 'Whether to generate screenshots during deployment.', true)
->param('specification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification(
$plan,
Config::getParam('specifications', []),
@@ -110,6 +111,7 @@ class Create extends Base
string $providerBranch,
bool $providerSilentMode,
string $providerRootDirectory,
bool $deploymentScreenshots,
string $specification,
Response $response,
Database $dbForProject,
@@ -164,6 +166,7 @@ class Create extends Base
'specification' => $specification,
'buildRuntime' => $buildRuntime,
'adapter' => $adapter,
'deploymentScreenshots' => $deploymentScreenshots,
]));
// Git connect logic
@@ -82,6 +82,7 @@ class Update extends Base
->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the site.', true)
->param('providerSilentMode', false, new Boolean(), 'Is the VCS (Version Control System) connection in silent mode for the repo linked to the site? In silent mode, comments will not be made on commits and pull requests.', true)
->param('providerRootDirectory', '', new Text(128, 0), 'Path to site code in the linked repo.', true)
->param('deploymentScreenshots', true, new Boolean(), 'Whether to generate screenshots during deployment.', true)
->param('specification', fn (array $plan) => $this->getDefaultSpecification($plan), fn (array $plan) => new Specification(
$plan,
Config::getParam('specifications', []),
@@ -118,6 +119,7 @@ class Update extends Base
string $providerBranch,
bool $providerSilentMode,
string $providerRootDirectory,
bool $deploymentScreenshots,
string $specification,
Request $request,
Response $response,
@@ -268,6 +270,7 @@ class Update extends Base
'buildRuntime' => $buildRuntime,
'adapter' => $adapter,
'fallbackFile' => $fallbackFile,
'deploymentScreenshots' => $deploymentScreenshots,
])));
// Redeploy logic
@@ -185,6 +185,12 @@ class Site extends Model
'default' => null,
'example' => 'index.html',
])
->addRule('deploymentScreenshots', [
'type' => self::TYPE_BOOLEAN,
'description' => 'Whether to generate screenshots during deployment.',
'default' => true,
'example' => true,
])
;
}
@@ -141,4 +141,62 @@ class SitesConsoleClientTest extends Scope
$this->cleanupSite($siteId);
}
/**
* @group screenshots
*/
public function testSiteScreenshotDisabled(): void
{
$siteId = $this->setupSite([
'siteId' => ID::unique(),
'name' => 'Themed site',
'framework' => 'other',
'adapter' => 'static',
'buildRuntime' => 'static-1',
'outputDirectory' => './',
'buildCommand' => '',
'installCommand' => '',
'fallbackFile' => '',
'deploymentScreenshots' => false
]);
$this->assertNotEmpty($siteId);
$site = $this->getSite($siteId);
$this->assertEquals(200, $site['headers']['status-code']);
$this->assertFalse($site['body']['deploymentScreenshots']);
$domain = $this->setupSiteDomain($siteId);
$deploymentId = $this->setupDeployment($siteId, [
'code' => $this->packageSite('static-themed'),
'activate' => 'true'
]);
$this->assertNotEmpty($deploymentId);
$domain = $this->getSiteDomain($siteId);
$this->assertNotEmpty($domain);
$proxyClient = new Client();
$proxyClient->setEndpoint('http://' . $domain);
$response = $proxyClient->call(Client::METHOD_GET, '/');
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertStringContainsString("Themed website", $response['body']);
$this->assertStringContainsString("@media (prefers-color-scheme: dark)", $response['body']);
$deployment = $this->getDeployment($siteId, $deploymentId);
$this->assertEquals(200, $deployment['headers']['status-code']);
$this->assertEmpty($deployment['body']['screenshotLight']);
$this->assertEmpty($deployment['body']['screenshotDark']);
$site = $this->getSite($siteId);
$this->assertEquals(200, $site['headers']['status-code']);
$this->assertEmpty($site['body']['deploymentScreenshotLight']);
$this->assertEmpty($site['body']['deploymentScreenshotDark']);
$this->cleanupSite($siteId);
}
}
@@ -625,6 +625,68 @@ class SitesCustomServerTest extends Scope
$this->cleanupSite($siteId);
}
public function testSiteWithoutDeploymentScreenshot(): void
{
$site = $this->createSite([
'siteId' => ID::unique(),
'name' => 'Static site',
'framework' => 'astro',
'buildRuntime' => 'node-22',
'outputDirectory' => './dist',
'buildCommand' => 'npm run build',
'installCommand' => 'npm install',
'deploymentScreenshots' => true
]);
$this->assertEquals(201, $site['headers']['status-code']);
$this->assertTrue($site['body']['deploymentScreenshots']);
$siteId = $site['body']['$id'];
$this->assertNotEmpty($siteId);
$site = $this->getSite($siteId);
$this->assertEquals('200', $site['headers']['status-code']);
$this->assertTrue($site['body']['deploymentScreenshots']);
$site = $this->updateSite([
'name' => 'Static site',
'framework' => 'astro',
'buildRuntime' => 'node-22',
'outputDirectory' => './dist',
'buildCommand' => 'npm run build',
'installCommand' => 'npm install',
'deploymentScreenshots' => false, // Important change
'$id' => $siteId,
]);
$this->assertEquals('200', $site['headers']['status-code']);
$this->assertFalse($site['body']['deploymentScreenshots']);
$site = $this->getSite($siteId);
$this->assertEquals('200', $site['headers']['status-code']);
$this->assertFalse($site['body']['deploymentScreenshots']);
$site = $this->updateSite([
'name' => 'Static site',
'framework' => 'astro',
'buildRuntime' => 'node-22',
'outputDirectory' => './dist',
'buildCommand' => 'npm run build',
'installCommand' => 'npm install',
'deploymentScreenshots' => true, // Important change
'$id' => $siteId,
]);
$this->assertEquals('200', $site['headers']['status-code']);
$this->assertTrue($site['body']['deploymentScreenshots']);
$site = $this->getSite($siteId);
$this->assertEquals('200', $site['headers']['status-code']);
$this->assertTrue($site['body']['deploymentScreenshots']);
$this->cleanupSite($siteId);
}
public function testListSites(): void
{
/**