From 1fda4590ede18a284de548f4674360d3a1b19448 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Thu, 27 Aug 2026 15:31:37 +0200 Subject: [PATCH 1/2] Write deployment packages to the system temp dir instead of .bref/ Every deploy of a bref.php application wrote its package to .bref/package-.zip in the project and never removed older ones, growing by ~43 MB per deploy. Worse, a project that also has a serverless.yml would package .bref/ into its Lambda zip and fail on the 250 MB unzipped size limit with an error that points nowhere near the cause. Packages are now written to the system temp directory and deleted once uploaded. Deploys also remove the packages that previous CLI versions left behind in .bref/ (and the directory itself once empty). Fixes CLOUD-56 Claude-Session: https://claude.ai/code/session_01T2dpFaYbbPFQaUWUrmqQuX --- src/Commands/Deploy.php | 76 ++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/src/Commands/Deploy.php b/src/Commands/Deploy.php index 0ce8a5e..5e17e69 100644 --- a/src/Commands/Deploy.php +++ b/src/Commands/Deploy.php @@ -269,6 +269,8 @@ private function uploadArtifacts(array $config, array $packageUrls): void IO::spin('packaging'); + $this->cleanupLegacyPackages(); + $archivePaths = []; foreach ($packageUrls as $id => $url) { $package = $config['packages'][$id] ?? null; @@ -290,26 +292,32 @@ private function uploadArtifacts(array $config, array $packageUrls): void ->intercept(new SetRequestTimeout(10, 10, $timeout, 60)) ->build(); - $promises = []; - foreach ($archivePaths as $id => $archivePath) { - $url = $packageUrls[$id]; - - IO::verbose(sprintf( - 'Uploading %s (%d MB)', - $archivePath, - round(((float) filesize($archivePath)) / 1024. / 1024., 1) - )); - - $request = new Request($url, 'PUT', StreamedContent::fromFile($archivePath)); - $promises[] = async(fn() => $client->request($request)); - } - try { - await($promises); - } catch (TimeoutException) { - throw new Exception("Timeout while uploading packages after $timeout seconds. This is likely due to a slow network connection"); - } catch (Exception $e) { - throw new Exception('Error while uploading packages: ' . $e->getMessage(), 0, $e); + $promises = []; + foreach ($archivePaths as $id => $archivePath) { + $url = $packageUrls[$id]; + + IO::verbose(sprintf( + 'Uploading %s (%d MB)', + $archivePath, + round(((float) filesize($archivePath)) / 1024. / 1024., 1) + )); + + $request = new Request($url, 'PUT', StreamedContent::fromFile($archivePath)); + $promises[] = async(fn() => $client->request($request)); + } + + try { + await($promises); + } catch (TimeoutException) { + throw new Exception("Timeout while uploading packages after $timeout seconds. This is likely due to a slow network connection"); + } catch (Exception $e) { + throw new Exception('Error while uploading packages: ' . $e->getMessage(), 0, $e); + } + } finally { + foreach ($archivePaths as $archivePath) { + @unlink($archivePath); + } } } @@ -318,10 +326,6 @@ private function uploadArtifacts(array $config, array $packageUrls): void */ private function packageArtifact(string $id, string $path, array $patterns): string { - if (! is_dir('.bref') && ! mkdir('.bref') && ! is_dir('.bref')) { - throw new Exception(sprintf('Directory "%s" could not be created', '.bref')); - } - // Turn the package patterns into regexes $patternRegexes = []; foreach ($patterns as $pattern) { @@ -335,7 +339,13 @@ private function packageArtifact(string $id, string $path, array $patterns): str $patternRegexes[$regex] = $include; } - $archivePath = ".bref/package-$id.zip"; + // The archive is written outside the project so that it cannot end up inside another + // deployment package (e.g. a `serverless.yml` deployment of the same project), and it + // is deleted after the upload + $archivePath = tempnam(sys_get_temp_dir(), "bref-package-$id-"); + if ($archivePath === false) { + throw new Exception('Could not create a temporary file to package the application'); + } $zip = new ZipArchive; $zip->open($archivePath, ZipArchive::CREATE | ZipArchive::OVERWRITE); @@ -346,6 +356,24 @@ private function packageArtifact(string $id, string $path, array $patterns): str return $archivePath; } + /** + * Older CLI versions wrote deployment packages to `.bref/` in the project and never + * removed them, accumulating tens of MB per deployment (see CLOUD-56). + */ + private function cleanupLegacyPackages(): void + { + $legacyPackages = glob('.bref/package-*.zip'); + if (empty($legacyPackages)) return; + + IO::verbose('Removing deployment packages left in `.bref/` by previous versions of the CLI'); + foreach ($legacyPackages as $legacyPackage) { + @unlink($legacyPackage); + } + // Remove the directory as well, unless it contains anything else (rmdir refuses + // to remove a non-empty directory) + @rmdir('.bref'); + } + /** * @param array $patternRegexes */ From e7b16e64db94c7dc3ead670c6d55a095f0cff9c4 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Thu, 27 Aug 2026 23:11:45 +0200 Subject: [PATCH 2/2] Drop the legacy .bref/ package cleanup bref.php deployments are completely internal, nobody is using them yet, so there are no user projects with accumulated packages to clean up. Claude-Session: https://claude.ai/code/session_01T2dpFaYbbPFQaUWUrmqQuX --- src/Commands/Deploy.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/Commands/Deploy.php b/src/Commands/Deploy.php index 5e17e69..cabf84d 100644 --- a/src/Commands/Deploy.php +++ b/src/Commands/Deploy.php @@ -269,8 +269,6 @@ private function uploadArtifacts(array $config, array $packageUrls): void IO::spin('packaging'); - $this->cleanupLegacyPackages(); - $archivePaths = []; foreach ($packageUrls as $id => $url) { $package = $config['packages'][$id] ?? null; @@ -356,24 +354,6 @@ private function packageArtifact(string $id, string $path, array $patterns): str return $archivePath; } - /** - * Older CLI versions wrote deployment packages to `.bref/` in the project and never - * removed them, accumulating tens of MB per deployment (see CLOUD-56). - */ - private function cleanupLegacyPackages(): void - { - $legacyPackages = glob('.bref/package-*.zip'); - if (empty($legacyPackages)) return; - - IO::verbose('Removing deployment packages left in `.bref/` by previous versions of the CLI'); - foreach ($legacyPackages as $legacyPackage) { - @unlink($legacyPackage); - } - // Remove the directory as well, unless it contains anything else (rmdir refuses - // to remove a non-empty directory) - @rmdir('.bref'); - } - /** * @param array $patternRegexes */