Skip to content

Commit 59dcb77

Browse files
committed
First pass at using zipped libs to deal with aws size limits. fixes #3
1 parent 222fa63 commit 59dcb77

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

index.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const _ = require('lodash');
66
const path = require('path');
77
const fse = require('fs-extra');
88
const child_process = require('child_process');
9+
const {EasyZip} = require('easy-zip');
910

1011
BbPromise.promisifyAll(fse);
1112

@@ -18,7 +19,7 @@ class ServerlessPythonRequirements {
1819
path.join(this.serverless.config.servicePath, 'requirements.py'));
1920
};
2021

21-
packRequirements() {
22+
installRequirements() {
2223
if (!fse.existsSync(path.join(this.serverless.config.servicePath, 'requirements.txt'))) {
2324
return BbPromise.resolve();
2425
}
@@ -52,8 +53,32 @@ class ServerlessPythonRequirements {
5253
});
5354
};
5455

56+
packRequirements() {
57+
return this.installRequirements().then(() => {
58+
return new BbPromise((resolve, reject) => {
59+
if (this.serverless.service.custom && this.serverless.service.custom.zipImport) {
60+
const zip = new EasyZip();
61+
zip.zipFolder('.requirements', (err) => {
62+
if (err) {
63+
reject();
64+
return;
65+
}
66+
zip.writeToFile('.requirements.zip');
67+
fse.remove('.requirements', (err) => err?reject():resolve());
68+
}, {rootFolder: '.'});
69+
} else {
70+
resolve();
71+
}
72+
});
73+
});
74+
}
75+
5576
cleanup() {
56-
const artifacts = ['requirements.py', '.requirements'];
77+
const artifacts = ['requirements.py'];
78+
if (this.serverless.service.custom && this.serverless.service.custom.zipImport)
79+
artifacts.push('.requirements.zip')
80+
else
81+
artifacts.push('.requirements')
5782

5883
return BbPromise.all(_.map(artifacts, (artifact) =>
5984
fse.removeAsync(path.join(this.serverless.config.servicePath, artifact))));;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"devDependencies": {},
4141
"dependencies": {
4242
"bluebird": "^3.0.6",
43+
"easy-zip": "github:owenchong/easy-zip",
4344
"fs-extra": "^0.26.7",
4445
"lodash": "^4.13.1"
4546
}

requirements.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33

44

55
requirements = os.path.join(
6-
os.path.split(__file__)[0],
7-
'.requirements',
8-
)
6+
os.path.split(__file__)[0], '.requirements')
7+
zip_requirements = os.path.join(
8+
os.path.split(__file__)[0], '.requirements.zip')
99

10-
if requirements not in sys.path:
10+
if requirements not in sys.path:
1111
sys.path.append(requirements)
12+
13+
if zip_requirements not in sys.path:
14+
sys.path.append(zip_requirements)

0 commit comments

Comments
 (0)