From c95a35bb05f2e33c57c0778a2710e4c7159f3809 Mon Sep 17 00:00:00 2001 From: Thibault RICHARD Date: Tue, 30 Mar 2021 23:22:12 +0200 Subject: [PATCH 1/2] Tweak README.md --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0608278..0b3ccb1 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,9 @@ composer req bref/symfony-bridge ## Usage -You only need to one one small change To quickly setup Symfony to work with Bref. +You only need to do two small change to quickly setup Symfony to work with Bref. + +First change your `src/Kernel.php` like so : ```diff // src/Kernel.php @@ -33,6 +35,19 @@ use Symfony\Component\Routing\RouteCollectionBuilder; // ... ``` +Then make sure your `serverless.yaml` contains at least the following include/exclude rules + +```yaml +# ... +package: + exclude: + - var/** + include: + - var/cache/prod/** + - var/build/prod/** +#... +``` + Now you are up and running. ## Optimize first request From b30cb1e0a6d81c67a431ac1bf3f6a04d3b58ecc8 Mon Sep 17 00:00:00 2001 From: Thibault RICHARD Date: Wed, 31 Mar 2021 14:09:05 +0200 Subject: [PATCH 2/2] Throw exception if no buildDir in the deployed package --- src/BrefKernel.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/BrefKernel.php b/src/BrefKernel.php index 2c50821..5d3a954 100644 --- a/src/BrefKernel.php +++ b/src/BrefKernel.php @@ -13,6 +13,11 @@ public function isLambda(): bool return getenv('LAMBDA_TASK_ROOT') !== false; } + public function allowEmptyBuildDir() + { + return false; + } + /** * {@inheritDoc} */ @@ -25,6 +30,29 @@ public function getCacheDir() return parent::getCacheDir(); } + /** + * {@inheritdoc} + */ + public function getBuildDir(): string + { + $buildDir = $this->getProjectDir().'/var/build/'.$this->environment; + + if ($this->isLambda() && !is_dir($buildDir)) { + if (!$this->allowEmptyBuildDir()) { + throw new \Exception( + 'You must warm and deploy the build directory as part of your Lambda package + as this directory is readonly on Lambda. + You can alternatively define the function allowEmptyBuildDir() in your Kernel class + and return "true" if you still want to deploy without a warm build directory. + '); + } + + return $this->getCacheDir(); + } + + return $buildDir; + } + /** * {@inheritDoc} */