jdecool/scaleway-runtimepublic Fork
⑂ 86f9b49
Commits
⬇ Clone ▾
git clone https://git.rickub.com/jdecool/scaleway-runtime.git
git clone ssh://git@rickub.com/jdecool/scaleway-runtime.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

feat(package): warn about Static Files too large for a Function ResponseUnverified

Jérémy DECOOL committed 2026-11-22T11:45:23+01:00 Browse files
86f9b49 parent: 72798f1
modified src/Packager.php +3 -0
@@ -148,6 +148,9 @@ final readonly class Packager
148148 // Keeps the executable bits, as for bin/console.
149149 $zip->setExternalAttributesName($name, \ZipArchive::OPSYS_UNIX, ($file->getPerms() & 0o777 | 0o100000) << 16);
150150 $codeSize += $file->getSize();
151+ if (str_starts_with($name, 'public/') && ($size = StaticFiles::responseSize($file->getPathname())) > StaticFiles::MAX_RESPONSE_SIZE) {
152+ $this->log(\sprintf('WARNING: %s takes %.1f MiB in a Function Response, over the %.0f MiB Scaleway accepts: the function will answer it with a 500, serve it from Object Storage', $name, $size / 1024 ** 2, StaticFiles::MAX_RESPONSE_SIZE / 1024 ** 2));
153+ }
151154 }
152155
153156 if (!$zip->close()) {
@@ -148,6 +148,9 @@ final readonly class Packager
148 // Keeps the executable bits, as for bin/console.148 // Keeps the executable bits, as for bin/console.
149 $zip->setExternalAttributesName($name, \ZipArchive::OPSYS_UNIX, ($file->getPerms() & 0o777 | 0o100000) << 16);149 $zip->setExternalAttributesName($name, \ZipArchive::OPSYS_UNIX, ($file->getPerms() & 0o777 | 0o100000) << 16);
150 $codeSize += $file->getSize();150 $codeSize += $file->getSize();
151+ if (str_starts_with($name, 'public/') && ($size = StaticFiles::responseSize($file->getPathname())) > StaticFiles::MAX_RESPONSE_SIZE) {
152+ $this->log(\sprintf('WARNING: %s takes %.1f MiB in a Function Response, over the %.0f MiB Scaleway accepts: the function will answer it with a 500, serve it from Object Storage', $name, $size / 1024 ** 2, StaticFiles::MAX_RESPONSE_SIZE / 1024 ** 2));
153+ }
151 }154 }
152 155
153 if (!$zip->close()) {156 if (!$zip->close()) {
modified tests/PackagerTest.php +17 -0
@@ -90,6 +90,23 @@ final class PackagerTest extends TestCase
9090 $zip->close();
9191 }
9292
93+ public function testWarnsAboutStaticFilesTooLargeForAFunctionResponse(): void
94+ {
95+ // Small enough as it is, but not once base64-encoded.
96+ $this->filesystem->dumpFile($this->appDir.'/public/video.bin', str_repeat("\xff", 5 * 1024 * 1024));
97+ $this->filesystem->dumpFile($this->appDir.'/public/app.css', 'body {}');
98+ $this->filesystem->dumpFile($this->appDir.'/src/large.bin', str_repeat("\xff", 5 * 1024 * 1024));
99+
100+ $this->package();
101+
102+ rewind($this->log);
103+ $log = (string) stream_get_contents($this->log);
104+ self::assertStringContainsString('WARNING: public/video.bin takes 6.7 MiB in a Function Response, over the 6 MiB Scaleway accepts', $log);
105+ self::assertStringNotContainsString('app.css', $log);
106+ self::assertStringNotContainsString('src/large.bin', $log);
107+ self::assertFileExists($this->dir.'/function.zip');
108+ }
109+
93110 public function testContentHashIsComposers(): void
94111 {
95112 $composer = json_decode((string) file_get_contents(__DIR__.'/Fixtures/PackagedApp/composer.json'), true);
@@ -90,6 +90,23 @@ final class PackagerTest extends TestCase
90 $zip->close();90 $zip->close();
91 }91 }
92 92
93+ public function testWarnsAboutStaticFilesTooLargeForAFunctionResponse(): void
94+ {
95+ // Small enough as it is, but not once base64-encoded.
96+ $this->filesystem->dumpFile($this->appDir.'/public/video.bin', str_repeat("\xff", 5 * 1024 * 1024));
97+ $this->filesystem->dumpFile($this->appDir.'/public/app.css', 'body {}');
98+ $this->filesystem->dumpFile($this->appDir.'/src/large.bin', str_repeat("\xff", 5 * 1024 * 1024));
99+
100+ $this->package();
101+
102+ rewind($this->log);
103+ $log = (string) stream_get_contents($this->log);
104+ self::assertStringContainsString('WARNING: public/video.bin takes 6.7 MiB in a Function Response, over the 6 MiB Scaleway accepts', $log);
105+ self::assertStringNotContainsString('app.css', $log);
106+ self::assertStringNotContainsString('src/large.bin', $log);
107+ self::assertFileExists($this->dir.'/function.zip');
108+ }
109+
93 public function testContentHashIsComposers(): void110 public function testContentHashIsComposers(): void
94 {111 {
95 $composer = json_decode((string) file_get_contents(__DIR__.'/Fixtures/PackagedApp/composer.json'), true);112 $composer = json_decode((string) file_get_contents(__DIR__.'/Fixtures/PackagedApp/composer.json'), true);