Skip to content

Commit b617b07

Browse files
committed
chore: reading from .nvmrc file
1 parent b7b5e4a commit b617b07

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/aws-lambda/layer/bin/publish-layer.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,15 @@ SUPPORTED_RUNTIMES="nodejs18.x nodejs20.x nodejs22.x"
165165
# The Node.js version to use for building the Docker image.
166166
# This should be aligned with one of the supported runtimes above.
167167
# We're using a development version.
168-
NODE_VERSION_TO_BUILD="20"
168+
ROOT_DIR=$(git rev-parse --show-toplevel 2>/dev/null || echo "../../..")
169+
NVMRC_PATH="$ROOT_DIR/.nvmrc"
170+
if [[ -f "$NVMRC_PATH" ]]; then
171+
NODEJS_DEV_VERSION=$(cat "$NVMRC_PATH")
172+
echo "Using Node.js version $NODEJS_DEV_VERSION from .nvmrc for Docker build"
173+
else
174+
echo "Warning: .nvmrc file not found at $NVMRC_PATH, falling back to default Node.js version 20"
175+
NODEJS_DEV_VERSION=20
176+
fi
169177

170178
echo Will build Lambda layer with name \"$LAYER_NAME\".
171179

@@ -380,10 +388,10 @@ else
380388
fi
381389

382390
if [[ -z $SKIP_DOCKER_IMAGE ]]; then
383-
echo "Step 7/9: Building Docker image for Lambda layer targeting Node.js version $NODE_VERSION_TO_BUILD"
391+
echo "Step 7/9: Building Docker image for Lambda layer targeting Node.js version $NODEJS_DEV_VERSION"
384392

385393
# Build the Docker image for the specified Node.js version
386-
docker build --build-arg NODEJS_VERSION=$NODE_VERSION_TO_BUILD . -t "$DOCKER_IMAGE_NAME:$VERSION"
394+
docker build --build-arg NODEJS_VERSION=$NODEJS_DEV_VERSION . -t "$DOCKER_IMAGE_NAME:$VERSION"
387395

388396
# NOTE: serverless/ci/pipeline.yaml passes PACKAGE_VERSION=1 for 1.x branch
389397
if [[ $PACKAGE_VERSION == latest ]]; then

0 commit comments

Comments
 (0)