Skip to content

Commit

Permalink
feat: Do not zip req for non-py functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stijn IJzermans committed Jan 9, 2024
1 parent a0d2e83 commit a7b8a11
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
5 changes: 5 additions & 0 deletions lib/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ function packRequirements() {
if (this.options.zip) {
if (this.serverless.service.package.individually) {
return BbPromise.resolve(this.targetFuncs)
.filter((func) => {
return (
func.runtime || this.serverless.service.provider.runtime
).match(/^python.*/);
})
.map((f) => {
if (!get(f, 'module')) {
set(f, ['module'], '.');
Expand Down
65 changes: 33 additions & 32 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1374,13 +1374,43 @@ test(
);

test(
'py3.9 does not try to build for node module when using mixed lambda type and individually w/docker',
'py3.9 can package with module runtime & architecture of function',
async (t) => {
process.chdir('tests/individually_mixed');
const path = npm(['pack', '../..']);
npm(['i', path]);

const stdout = sls(['package'], {
env: { dockerizePip: 'true' },
noThrow: true,
});
t.true(
stdout.includes('public.ecr.aws/sam/build-python3.9:latest-x86_64'),
'python3.9 image is used for function and is using x86_64 architecture'
);

const zipfiles_hello2 = await listZipFiles(
'.serverless/module2-sls-py-req-test-indiv-mixed-dev-hello2.zip'
);
t.true(
zipfiles_hello2.includes(`flask${sep}__init__.py`),
'flask is packaged in function hello2'
);
},
{
skip:
!canUseDocker() || process.platform === 'win32' || process.arch !== 'x64',
}
);

test(
'py3.9 builds succesfully when using mixed architecture and zipping',
async (t) => {
process.chdir('tests/individually_mixed');
const path = npm(['pack', '../..']);

npm(['i', path]);
sls(['package'], { env: { dockerizePip: 'true' } });
sls(['package'], { env: { dockerizePip: 'true', zip: 'true' } });

const zipfiles_hello = await listZipFiles('.serverless/hello1.zip');
t.true(
Expand All @@ -1405,7 +1435,7 @@ test(
);
t.false(
zipfiles_hello2.includes(`module1${sep}handler1.ts`),
'handler1.py is NOT incldued at module1 level in hello2'
'handler1.py is NOT included at module1 level in hello2'
);
t.false(
zipfiles_hello2.includes(`pyaml${sep}__init__.py`),
Expand All @@ -1425,35 +1455,6 @@ test(
{ skip: !canUseDocker() || process.platform === 'win32' }
);

test(
'py3.9 can package with module runtime & architecture python function and nodejs system',
async (t) => {
process.chdir('tests/individually_mixed');
const path = npm(['pack', '../..']);
npm(['i', path]);

const stdout = sls(['package'], {
env: { dockerizePip: 'true' },
noThrow: true,
});
t.true(
stdout.includes('public.ecr.aws/sam/build-python3.9:latest-x86_64'),
'python3.9 images is used for function and is using x86_64 architecture'
);

const zipfiles_hello2 = await listZipFiles(
'.serverless/module2-sls-py-req-test-indiv-mixed-dev-hello2.zip'
);
t.true(
zipfiles_hello2.includes(`flask${sep}__init__.py`),
'flask is packaged in function hello2'
);
},
{
skip:
!canUseDocker() || process.platform === 'win32' || process.arch !== 'x64',
}
);

test(
'py3.9 uses download cache by default option',
Expand Down
3 changes: 3 additions & 0 deletions tests/individually_mixed/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ package:
custom:
pythonRequirements:
dockerizePip: ${env:dockerizePip, self:custom.defaults.dockerizePip}
zip: ${env:zip, self:custom.defaults.zip}
defaults:
dockerizePip: false
zip: false

functions:
hello1:
handler: handler1.hello
architecture: x86_64
package:
patterns:
- '!**'
Expand Down

0 comments on commit a7b8a11

Please sign in to comment.