Skip to content

Commit b59fefa

Browse files
Output size of application before compression (#186)
* Output size of application before compression - Provides useful feedback for the developer which is otherwise difficult to access without downloading and uncompressing the artifact from Lambda - If I'm understanding correctly, the 250MB uncompressed limit includes the size of the custom Lambda runtime and any additional layers, so the check performed by ensureArchiveIsWithinSizeLimits may actually not be providing any useful value since the actual size of the uncompressed application plus the runtime and layers will be larger than the value being checked here - This change doesn't address that issue but does at least provide feedback to the developer so that they can understand what effect their changes are having on the uncompressed size of their application - Follows output format of subsequent step to keep output consistent in CLI - Passes in archive size to ensureArchiveIsWithinSizeLimits via parameter to avoid doing the work of calculating the size twice NOTES: - The AWS Lambda docs specify MB as the unit for the size limits (50MB Archive size limit and 250MB Uncompressed size limit) whereas I believe the MB calculation for the output and size check in this file are both calculating MiB - This may warrant another look if a way can be found to provide a more meaningful size check against the 250MB limit imposed by AWS * Update CompressApplication.php * Update CompressApplication.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 386d58f commit b59fefa

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/BuildProcess/CompressApplication.php

+10-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Laravel\VaporCli\BuiltApplicationFiles;
66
use Laravel\VaporCli\Helpers;
77
use Laravel\VaporCli\Manifest;
8+
use Laravel\VaporCli\Path;
89
use Symfony\Component\Process\Process;
910
use ZipArchive;
1011

@@ -23,12 +24,15 @@ public function __invoke()
2324
return;
2425
}
2526

26-
Helpers::step('<options=bold>Compressing Application</>');
27+
$appSizeInBytes = $this->getDirectorySize(Path::app());
28+
$appSizeInMegabytes = round($appSizeInBytes / 1048576, 2);
29+
30+
Helpers::step('<options=bold>Compressing Application</> ('.$appSizeInMegabytes.'MB)');
2731

2832
if (PHP_OS == 'Darwin') {
2933
$this->compressApplicationOnMac();
3034

31-
return $this->ensureArchiveIsWithinSizeLimits();
35+
return $this->ensureArchiveIsWithinSizeLimits($appSizeInBytes);
3236
}
3337

3438
$archive = new ZipArchive();
@@ -49,7 +53,7 @@ public function __invoke()
4953

5054
$archive->close();
5155

52-
$this->ensureArchiveIsWithinSizeLimits();
56+
$this->ensureArchiveIsWithinSizeLimits($appSizeInBytes);
5357
}
5458

5559
/**
@@ -78,11 +82,12 @@ protected function getPermissions($file)
7882
/**
7983
* Ensure the application archive is within supported size limits.
8084
*
85+
* @param float $bytes
8186
* @return void
8287
*/
83-
protected function ensureArchiveIsWithinSizeLimits()
88+
protected function ensureArchiveIsWithinSizeLimits($bytes)
8489
{
85-
$size = ceil($this->getDirectorySize($this->buildPath.'/app') / 1048576);
90+
$size = ceil($bytes / 1048576);
8691

8792
if ($size > 250) {
8893
Helpers::line();

0 commit comments

Comments
 (0)