From 2aea99d345ca69d3bee2b73a3216221069720d77 Mon Sep 17 00:00:00 2001 From: Tomasz Czubocha Date: Tue, 7 Jan 2025 16:12:38 +0100 Subject: [PATCH] fix: correctly resolve layer package artifact and docker image paths (#12972) --- lib/plugins/aws/deploy/lib/upload-artifacts.js | 1 + lib/plugins/aws/package/compile/layers.js | 1 + lib/plugins/aws/provider.js | 6 +++--- lib/plugins/aws/utils/get-lambda-layer-artifact-path.js | 5 +++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/plugins/aws/deploy/lib/upload-artifacts.js b/lib/plugins/aws/deploy/lib/upload-artifacts.js index 18f25d60a..cf36d9e42 100644 --- a/lib/plugins/aws/deploy/lib/upload-artifacts.js +++ b/lib/plugins/aws/deploy/lib/upload-artifacts.js @@ -169,6 +169,7 @@ export default { } return getLambdaLayerArtifactPath( this.packagePath, + this.serverless.serviceDir, name, this.provider.serverless.service, this.provider.naming, diff --git a/lib/plugins/aws/package/compile/layers.js b/lib/plugins/aws/package/compile/layers.js index bf0147720..ce26072a5 100644 --- a/lib/plugins/aws/package/compile/layers.js +++ b/lib/plugins/aws/package/compile/layers.js @@ -60,6 +60,7 @@ class AwsCompileLayers { let layerLogicalId = this.provider.naming.getLambdaLayerLogicalId(layerName) const layerArtifactPath = getLambdaLayerArtifactPath( this.packagePath, + this.serverless.serviceDir, layerName, this.provider.serverless.service, this.provider.naming, diff --git a/lib/plugins/aws/provider.js b/lib/plugins/aws/provider.js index 16dff0516..3fcbcf24c 100644 --- a/lib/plugins/aws/provider.js +++ b/lib/plugins/aws/provider.js @@ -2424,11 +2424,11 @@ Object.defineProperties( await this.ensureDockerIsAvailable() let isDockerfileAvailable = false - const pathToDockerfile = path.resolve( + const absoluteImagePath = path.resolve( this.serverless.serviceDir, imagePath, - imageFilename, ) + const pathToDockerfile = path.resolve(absoluteImagePath, imageFilename) try { const stats = await fsp.stat(pathToDockerfile) @@ -2470,7 +2470,7 @@ Object.defineProperties( ...buildArgsArr, ...cacheFromArr, ...buildOptions, - imagePath, + absoluteImagePath, ] // These are optional arguments, so we only append to the arguments diff --git a/lib/plugins/aws/utils/get-lambda-layer-artifact-path.js b/lib/plugins/aws/utils/get-lambda-layer-artifact-path.js index f57c70eea..d7834e8bf 100644 --- a/lib/plugins/aws/utils/get-lambda-layer-artifact-path.js +++ b/lib/plugins/aws/utils/get-lambda-layer-artifact-path.js @@ -2,15 +2,16 @@ import path from 'path' /** * @param packagePath {string} + * @param serviceDir {string} * @param layerName {string} * @param service * @param naming * @returns {string} */ -export default (packagePath, layerName, service, naming) => { +export default (packagePath, serviceDir, layerName, service, naming) => { const layerObject = service.getLayer(layerName) if (layerObject.package && layerObject.package.artifact) { - return layerObject.package.artifact + return path.resolve(serviceDir, layerObject.package.artifact) } return path.join(packagePath, naming.getLayerArtifactName(layerName)) }