From a511e6b54a36f27907eca5d336b9a4f0f8cdf3b4 Mon Sep 17 00:00:00 2001 From: Nathaniel Rindlaub Date: Wed, 9 Sep 2020 16:33:25 -0700 Subject: [PATCH] Support recursively adding files to serverless package --- README.md | 11 +++++++++++ lib/pip.js | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 87acbbe3..1e4661ba 100644 --- a/README.md +++ b/README.md @@ -497,6 +497,17 @@ zipinfo .serverless/xxx.zip If you can't see the library, you might need to adjust your package include/exclude configuration in `serverless.yml`. +If you would like to recursively include a directory and all of its contents, +prepend `-r ` to the file list member: + +```yaml +custom: + pythonRequirements: + dockerExtraFiles: + - -r /path/to/additional/dependencies/ +``` + + ## Optimising packaging time If you wish to exclude most of the files in your project, and only include the source files of your lambdas and their dependencies you may well use an approach like this: diff --git a/lib/pip.js b/lib/pip.js index 7d1777a4..f3cf769c 100644 --- a/lib/pip.js +++ b/lib/pip.js @@ -262,7 +262,13 @@ function installRequirements(targetFolder, serverless, options) { } for (let path of options.dockerExtraFiles) { - pipCmds.push(['cp', path, '/var/task/']); + let cmd = ['cp', path, '/var/task/']; + // Copy recursively if -r option was specified + if (path.startsWith('-r ')) { + path = path.split(' ')[1]; + cmd = ['cp', '-r', path, '/var/task/'] + } + pipCmds.push(cmd); } if (process.platform === 'linux') {