Skip to content

Commit

Permalink
feat: allow to use an existing sharp layer via arn (#96)
Browse files Browse the repository at this point in the history
* feat: allow to re-use the sharp layer

* feat: allow to re-use the sharp layer

* fix: rerun build command
  • Loading branch information
ansgarS authored Mar 23, 2023
1 parent 314f046 commit a437e86
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 8 deletions.
126 changes: 123 additions & 3 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ class NextjsSst extends Nextjs {
}
```

## Contribute

Hey there, we value every new contribution a lot 🙏🏼 thank you.

Here is a short HowTo before you get started:

1. Please make sure to create a bug first
2. Link the bug in your pull request
3. Run `yarn build` after you made your changes and before you open a pull request

## Breaking changes

- v2.0.0: SST wrapper changed, lambda/assets/distribution defaults now are in the `defaults` prop, refactored distribution settings into the new NextjsDistribution construct. If you are upgrading, you must temporarily remove the `customDomain` on your existing 1.x.x app before upgrading to >=2.x.x because the CloudFront distribution will get recreated due to refactoring, and the custom domain must be globally unique across all CloudFront distributions. Prepare for downtime.
5 changes: 2 additions & 3 deletions src/ImageOptimizationLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import * as fs from 'fs';
import * as path from 'path';
import { Duration } from 'aws-cdk-lib';
import { Policy, PolicyStatement } from 'aws-cdk-lib/aws-iam';
import { FunctionOptions } from 'aws-cdk-lib/aws-lambda';
import { FunctionOptions, ILayerVersion } from 'aws-cdk-lib/aws-lambda';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import { IBucket } from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
import { LAMBDA_RUNTIME } from './constants';
import { NextjsBaseProps } from './NextjsBase';
import type { NextjsBuild } from './NextjsBuild';
import { NextjsLayer } from './NextjsLayer';
// import { config } from 'process';

export type RemotePattern = {
Expand All @@ -33,7 +32,7 @@ export interface ImageOptimizationProps extends NextjsBaseProps {
/**
* NextjsLayer - sharp runtime
*/
readonly nextLayer: NextjsLayer;
readonly nextLayer: ILayerVersion;
/**
* The `NextjsBuild` instance representing the built Nextjs application.
*/
Expand Down
6 changes: 4 additions & 2 deletions src/Nextjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as os from 'os';
import * as path from 'path';
import { RemovalPolicy } from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { FunctionOptions } from 'aws-cdk-lib/aws-lambda';
import { FunctionOptions, LayerVersion } from 'aws-cdk-lib/aws-lambda';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { Construct } from 'constructs';
import * as fs from 'fs-extra';
Expand Down Expand Up @@ -128,7 +128,9 @@ export class Nextjs extends Construct {
});

// layer
const nextLayer = new NextjsLayer(scope, 'NextjsLayer', {});
const nextLayer = props.sharpLayerArn?.length
? LayerVersion.fromLayerVersionArn(scope, 'NextjsLayer', props.sharpLayerArn)
: new NextjsLayer(scope, 'NextjsLayer', {});

// build nextjs app
this.nextBuild = new NextjsBuild(this, id, { ...props, tempBuildDir });
Expand Down
6 changes: 6 additions & 0 deletions src/NextjsBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export interface NextjsBaseProps {
* Less build output.
*/
readonly quiet?: boolean;

/**
* Optional arn for the sharp lambda layer.
* If omitted, the layer will be created.
*/
readonly sharpLayerArn?: string;
}

///// stuff below taken from https://github.com/serverless-stack/sst/blob/8d377e941467ced81d8cc31ee67d5a06550f04d4/packages/resources/src/BaseSite.ts
Expand Down

0 comments on commit a437e86

Please sign in to comment.