From 8b7de6dd12933d7151d368654e72e1f51c341e74 Mon Sep 17 00:00:00 2001 From: Stefan Zweifel Date: Fri, 29 Dec 2023 20:18:43 +0100 Subject: [PATCH] [v2] Replace `sidecar-browsershot.layer`-config with `sidecar-browsershot.layers`-config (#103) * Replace `layer`-config with `layers`-config * Update Comments * Fix phpstan error --- config/sidecar-browsershot.php | 19 ++++++++++++++----- src/BrowsershotLambda.php | 2 +- src/Functions/BrowsershotFunction.php | 15 ++++++++++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/config/sidecar-browsershot.php b/config/sidecar-browsershot.php index 7e234a7..50217b8 100644 --- a/config/sidecar-browsershot.php +++ b/config/sidecar-browsershot.php @@ -32,16 +32,25 @@ 'warming' => env('SIDECAR_BROWSERSHOT_WARMING_INSTANCES', 0), /** - * AWS Layer to use by Lambda. Defaults to "shelfio/chrome-aws-lambda-layer" in your AWS region. - * Must contain "chrome-aws-lambda". + * AWS Layers to use by the Lambda function. + * Defaults to "shelfio/chrome-aws-lambda-layer" and "sidecar-browsershot-layer" in your respective AWS region. + * + * If you customize this, you must include both "sidecar-browsershot-layer" and "shelfio/chrome-aws-lambda-layer" + * in your list, as the config overrides the default values. + * (See BrowsershotFunction@layers for more details) * * @see https://github.com/shelfio/chrome-aws-lambda-layer - * @deprecated + * @see https://github.com/stefanzweifel/sidecar-browsershot-layer */ - 'layer' => env('SIDECAR_BROWSERSHOT_LAYER'), + 'layers' => [ + // "arn:aws:lambda:us-east-1:821527532446:layer:sidecar-browsershot-layer:1", + // "arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:37", + ], /** - * Define the path to the custom font directory. + * Path to local directory containing fonts to be installed in the Lambda function. + * During deployment, BorwsershotLambda will scan this directory for + * any files and will bundle them into the Lambda function. */ 'fonts' => resource_path('sidecar-browsershot/fonts'), ]; diff --git a/src/BrowsershotLambda.php b/src/BrowsershotLambda.php index d985b56..3dea7ad 100644 --- a/src/BrowsershotLambda.php +++ b/src/BrowsershotLambda.php @@ -133,7 +133,7 @@ public function applyManipulationsOnS3(string $imagePath, string $disk = 's3'): */ public static function readHtmlFromS3(string $sourcePath, string $disk = 's3'): self { - return (new static()) + return (new BrowsershotLambda()) ->setOption('s3Source', [ 'path' => $sourcePath, 'region' => config('sidecar.aws_region'), diff --git a/src/Functions/BrowsershotFunction.php b/src/Functions/BrowsershotFunction.php index 0c8984a..128bc2e 100644 --- a/src/Functions/BrowsershotFunction.php +++ b/src/Functions/BrowsershotFunction.php @@ -55,7 +55,7 @@ protected function customFonts(): array } /** - * We get puppeteer out of the layer, which spatie doesn't allow + * We get puppeteer out of the layer, which Spatie doesn't allow * for. We'll just overwrite their browser.cjs to add it. * * @return string @@ -75,11 +75,17 @@ protected function modifiedBrowserJs() return "const puppet = require('puppeteer-core'); \n".$browser; } + /** + * @inheritDoc + */ public function runtime() { return 'nodejs18.x'; } + /** + * @inheritDoc + */ public function memory() { return config('sidecar-browsershot.memory'); @@ -111,6 +117,9 @@ public function architecture() return Architecture::X86_64; } + /** + * @inheritDoc + */ public function warmingConfig() { return WarmingConfig::instances(config('sidecar-browsershot.warming')); @@ -118,8 +127,8 @@ public function warmingConfig() public function layers() { - if ($layer = config('sidecar-browsershot.layer')) { - return [$layer]; + if ($layers = config('sidecar-browsershot.layers')) { + return $layers; } $region = config('sidecar.aws_region');