▾ modified src/Packager.php +3 -0 Viewed
@@ -148,6 +148,9 @@ final readonly class Packager 148 148 // Keeps the executable bits, as for bin/console. 149 149 $zip -> setExternalAttributesName ( $name , \ZipArchive :: OPSYS_UNIX , ( $file -> getPerms () & 0o777 | 0o100000 ) << 16 ); 150 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 156 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 Viewed
@@ -90,6 +90,23 @@ final class PackagerTest extends TestCase 90 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 110 public function testContentHashIsComposers () : void 94 111 { 95 112 $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 () : void 110 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 );