Skip to content

Commit

Permalink
[v2] Replace sidecar-browsershot.layer-config with `sidecar-browser…
Browse files Browse the repository at this point in the history
…shot.layers`-config (#103)

* Replace `layer`-config with `layers`-config

* Update Comments

* Fix phpstan error
  • Loading branch information
stefanzweifel authored Dec 29, 2023
1 parent de048ce commit 8b7de6d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
19 changes: 14 additions & 5 deletions config/sidecar-browsershot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
];
2 changes: 1 addition & 1 deletion src/BrowsershotLambda.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
15 changes: 12 additions & 3 deletions src/Functions/BrowsershotFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand Down Expand Up @@ -111,15 +117,18 @@ public function architecture()
return Architecture::X86_64;
}

/**
* @inheritDoc
*/
public function warmingConfig()
{
return WarmingConfig::instances(config('sidecar-browsershot.warming'));
}

public function layers()
{
if ($layer = config('sidecar-browsershot.layer')) {
return [$layer];
if ($layers = config('sidecar-browsershot.layers')) {
return $layers;
}

$region = config('sidecar.aws_region');
Expand Down

0 comments on commit 8b7de6d

Please sign in to comment.