From ebb906cd3561fc28d7c5d8ac133d0eab6eb26cb5 Mon Sep 17 00:00:00 2001 From: Mathias Grimm Date: Thu, 13 Nov 2025 12:29:17 -0300 Subject: [PATCH 1/2] Ensuring compressed application size (Zip size) is withing limits Before this PR we only checked for the decompressed application size (250 MB) but there's also a limit to the Zip file of 50 MB as per https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html. - Validating compressed file size - Small refactoring on `App\BuildProcess\CompressApplication` to avoid duplication when introducing the new validation. - Fixing invalid doc links --- src/BuildProcess/CompressApplication.php | 46 +++++++++++++++++-- src/BuildProcess/ValidateManifest.php | 6 +-- .../EnvironmentVariableLimitReached.php | 2 +- .../FunctionExceedsMaximumAllowedSize.php | 2 +- 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/BuildProcess/CompressApplication.php b/src/BuildProcess/CompressApplication.php index 2c7dd4e8..3a9dc213 100644 --- a/src/BuildProcess/CompressApplication.php +++ b/src/BuildProcess/CompressApplication.php @@ -31,13 +31,13 @@ public function __invoke() if (PHP_OS == 'Darwin') { $this->compressApplicationOnMac(); - + $this->ensureCompressedApplicationSizeIsWithinSizeLimits($this->getCompressedApplicationSizeInBytes()); return $this->ensureArchiveIsWithinSizeLimits($appSizeInBytes); } $archive = new ZipArchive(); - $archive->open($this->buildPath.'/app.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE); + $archive->open($this->getCompressedApplicationPath(), ZipArchive::CREATE | ZipArchive::OVERWRITE); foreach (BuiltApplicationFiles::get($this->appPath) as $file) { $relativePathName = str_replace('\\', '/', $file->getRelativePathname()); @@ -53,9 +53,31 @@ public function __invoke() $archive->close(); + $this->ensureCompressedApplicationSizeIsWithinSizeLimits($this->getCompressedApplicationSizeInBytes()); + $this->ensureArchiveIsWithinSizeLimits($appSizeInBytes); } + /** + * Get the full path of the compressed application (zip file) + * + * @return string + */ + protected function getCompressedApplicationPath() + { + return $this->buildPath.'/app.zip'; + } + + /** + * Get the size of the zip file in bytes + * + * @return int + */ + protected function getCompressedApplicationSizeInBytes() + { + return filesize($this->getCompressedApplicationPath()); + } + /** * Utilize the "zip" utility to compress the application. * @@ -63,7 +85,7 @@ public function __invoke() */ protected function compressApplicationOnMac() { - (new Process(['zip', '-r', $this->buildPath.'/app.zip', '.'], $this->appPath))->mustRun(); + (new Process(['zip', '-r', $this->getCompressedApplicationPath(), '.'], $this->appPath))->mustRun(); } /** @@ -80,7 +102,7 @@ protected function getPermissions($file) } /** - * Ensure the application archive is within supported size limits. + * Ensure the uncompressed application archive is within supported size limits. * * @param float $bytes * @return void @@ -95,6 +117,22 @@ protected function ensureArchiveIsWithinSizeLimits($bytes) } } + /** + * Ensure the compressed application is within supported size limits. + * + * @param float $bytes + * @return void + */ + protected function ensureCompressedApplicationSizeIsWithinSizeLimits($bytes) + { + $size = ceil($bytes / 1048576); + + if ($size > 50) { + Helpers::line(); + Helpers::abort('Compressed application is greater than 50MB. Your compressed application is '.$size.'MB.'); + } + } + /** * Get the size of the given directory. * diff --git a/src/BuildProcess/ValidateManifest.php b/src/BuildProcess/ValidateManifest.php index 976de699..4745522d 100644 --- a/src/BuildProcess/ValidateManifest.php +++ b/src/BuildProcess/ValidateManifest.php @@ -32,7 +32,7 @@ protected function warnAboutDeprecations() Helpers::warn( '- The "separate-vendor" option is deprecated.' .' Please use Docker based deployments instead:' - .' https://docs.vapor.build/1.0/projects/environments.html#runtime' + .' https://docs.vapor.build/projects/environments#docker-runtimes' ); } @@ -45,14 +45,14 @@ protected function warnAboutDeprecations() ])) { Helpers::warn( 'The runtimes "php-7.3", "php-7.4", "php-7.4:al2", "php-7.4:imagick", and "php-8.0" are deprecated and will no longer be supported or receiving any updates.' - .' For a full list of supported runtimes, please see: https://docs.vapor.build/1.0/projects/environments.html#runtime' + .' For a full list of supported runtimes, please see: https://docs.vapor.build/projects/environments#runtime' ); } if (Manifest::runtime($this->environment) === 'php-8.0:al2') { Helpers::warn( 'The runtime "php-8.0:al2" is now deprecated and it is no longer possible to deploy new environments using this runtime. Support will be removed for existing runtimes on February 26, 2024.' - .' For a full list of supported runtimes, please see: https://docs.vapor.build/1.0/projects/environments.html#runtime' + .' For a full list of supported runtimes, please see: https://docs.vapor.build/projects/environments#runtime' ); } diff --git a/src/Solutions/EnvironmentVariableLimitReached.php b/src/Solutions/EnvironmentVariableLimitReached.php index f4d716cf..b5033461 100644 --- a/src/Solutions/EnvironmentVariableLimitReached.php +++ b/src/Solutions/EnvironmentVariableLimitReached.php @@ -44,7 +44,7 @@ public function applicable() public function all() { return [ - 'Use encrypted environment files in place of or in addition to environment variables: https://docs.vapor.build/1.0/projects/environments.html#encrypted-environment-files', + 'Use encrypted environment files in place of or in addition to environment variables: https://docs.vapor.build/projects/environments#encrypted-environment-files', ]; } } diff --git a/src/Solutions/FunctionExceedsMaximumAllowedSize.php b/src/Solutions/FunctionExceedsMaximumAllowedSize.php index 1dd4863b..ee78a436 100644 --- a/src/Solutions/FunctionExceedsMaximumAllowedSize.php +++ b/src/Solutions/FunctionExceedsMaximumAllowedSize.php @@ -49,7 +49,7 @@ public function all() .' Docker based deployments allow you to package and deploy applications up to 10GB in size.' .' When migrating an existing environment to a Docker runtime, please keep in mind that you won\'t be able to revert that environment to the default Vapor Lambda runtime later.' .' For that reason, you may want to create an environment for testing the Docker runtime first.' - .' https://docs.vapor.build/1.0/projects/environments.html#building-custom-docker-images', + .' https://docs.vapor.build/projects/environments#docker-runtimes', ]; } } From 557a14279e26c59cfedd55982d20cb8dae472fbe Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 13 Nov 2025 15:29:30 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI --- src/BuildProcess/CompressApplication.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/BuildProcess/CompressApplication.php b/src/BuildProcess/CompressApplication.php index 3a9dc213..8620650b 100644 --- a/src/BuildProcess/CompressApplication.php +++ b/src/BuildProcess/CompressApplication.php @@ -32,6 +32,7 @@ public function __invoke() if (PHP_OS == 'Darwin') { $this->compressApplicationOnMac(); $this->ensureCompressedApplicationSizeIsWithinSizeLimits($this->getCompressedApplicationSizeInBytes()); + return $this->ensureArchiveIsWithinSizeLimits($appSizeInBytes); } @@ -59,7 +60,7 @@ public function __invoke() } /** - * Get the full path of the compressed application (zip file) + * Get the full path of the compressed application (zip file). * * @return string */ @@ -69,7 +70,7 @@ protected function getCompressedApplicationPath() } /** - * Get the size of the zip file in bytes + * Get the size of the zip file in bytes. * * @return int */