Skip to content

Commit

Permalink
feat: use a multi-stage build for dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
dangreaves committed Sep 19, 2024
1 parent 2fc2798 commit 23ff02c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/assets/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
FROM public.ecr.aws/docker/library/node:20

# https://github.com/awslabs/aws-lambda-web-adapter
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.4 /lambda-adapter /opt/extensions/lambda-adapter
FROM public.ecr.aws/docker/library/node:20 AS base

ENV PORT=8080

Expand All @@ -11,4 +8,9 @@ COPY . .

ENV NODE_ENV=production

CMD ["node", "__HANDLER_PATH__"]
CMD ["node", "__HANDLER_PATH__"]

FROM base AS lambda

# https://github.com/awslabs/aws-lambda-web-adapter
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.8.4 /lambda-adapter /opt/extensions/lambda-adapter
2 changes: 2 additions & 0 deletions src/cdk/GatsbySite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export class GatsbySite extends Construct {
memorySize: options.memorySize ?? isSsrEngine ? 1024 : 512,
logRetention: logs.RetentionDays.ONE_MONTH,
code: lambda.DockerImageCode.fromImageAsset(fn.functionDir, {
target: "lambda",
platform: ecrAssets.Platform.LINUX_AMD64,
}),
insightsVersion: lambda.LambdaInsightsVersion.VERSION_1_0_229_0,
Expand Down Expand Up @@ -240,6 +241,7 @@ export class GatsbySite extends Construct {
taskImageOptions: {
containerPort: 8080,
image: ecs.ContainerImage.fromAsset(fn.functionDir, {
target: "base",
platform: ecrAssets.Platform.LINUX_AMD64,
}),
logDriver: new ecs.AwsLogDriver({
Expand Down

0 comments on commit 23ff02c

Please sign in to comment.