From 490e62e06c759419d6aeaa4e180a81fd5fa7ae88 Mon Sep 17 00:00:00 2001 From: Glenn 'devalias' Grant Date: Thu, 25 May 2023 10:48:04 +1000 Subject: [PATCH] use supported version of pnpm in docker build container based on node runtime fixes https://github.com/aws/aws-cdk/issues/25710 --- .../aws-lambda-nodejs/lib/Dockerfile | 3 ++- .../aws-lambda-nodejs/lib/bundling.ts | 25 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/aws-cdk-lib/aws-lambda-nodejs/lib/Dockerfile b/packages/aws-cdk-lib/aws-lambda-nodejs/lib/Dockerfile index b5c3280ab8af9..da6a8d2e3a421 100644 --- a/packages/aws-cdk-lib/aws-lambda-nodejs/lib/Dockerfile +++ b/packages/aws-cdk-lib/aws-lambda-nodejs/lib/Dockerfile @@ -7,7 +7,8 @@ FROM $IMAGE RUN npm install --global yarn@1.22.5 # Install pnpm -RUN npm install --global pnpm@7.30.5 +ARG PNPM_VERSION=0 +RUN npm install --global pnpm@$PNPM_VERSION # Install typescript RUN npm install --global typescript diff --git a/packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts b/packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts index 632858703bbfb..bf3b6e044f41e 100644 --- a/packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts +++ b/packages/aws-cdk-lib/aws-lambda-nodejs/lib/bundling.ts @@ -131,13 +131,34 @@ export class Bundling implements cdk.BundlingOptions { // Docker bundling const shouldBuildImage = props.forceDockerBundling || !Bundling.esbuildInstallation; + // If runtime isn't passed use regional default, lowest common denominator is node14 + const imageRuntime = props.runtime ?? Runtime.NODEJS_14_X + // Use supported version of pnpm based on the chosen runtime + const imagePnpmVersion = ((runtime) => { + switch (runtime) { + case Runtime.NODEJS_4_3: + return '^1.27.0-1' + case Runtime.NODEJS_6_10: + return '^2.24.0-0' + case Runtime.NODEJS_8_10: + return '^3.8.1' + case Runtime.NODEJS_10_X: + return '^5.18.10' + case Runtime.NODEJS_12_X: + return '^6.35.1' + case Runtime.NODEJS_14_X: + return '^7.32.5' + default: + return '^8.5.1' + } + })(imageRuntime) this.image = shouldBuildImage ? props.dockerImage ?? cdk.DockerImage.fromBuild(path.join(__dirname, '../lib'), { buildArgs: { ...props.buildArgs ?? {}, - // If runtime isn't passed use regional default, lowest common denominator is node14 - IMAGE: (props.runtime ?? Runtime.NODEJS_14_X).bundlingImage.image, + IMAGE: imageRuntime.bundlingImage.image, ESBUILD_VERSION: props.esbuildVersion ?? ESBUILD_MAJOR_VERSION, + PNPM_VERSION: imagePnpmVersion, }, platform: props.architecture.dockerPlatform, })