Skip to content

Commit bf3b6a0

Browse files
Merge branch 'master' into master
2 parents 417db63 + b5b5475 commit bf3b6a0

File tree

5 files changed

+52
-28
lines changed

5 files changed

+52
-28
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1717

1818

1919
### Removed
20+
21+
22+
## [0.2.4] - 2017-10-24
23+
### Added
24+
- Normalized path for building on windows courtesy @wsteimel77
25+
26+
## [0.2.5] - 2017-11-11
27+
- Bug fix for #21 courtesy @JFox

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ When `serverless deploy` is run, the plugin will:
8383
The Serverless framework will then pickup each zip file and upload it to your provider.
8484

8585
Here's a simple `serverless.yml` configuration for this plugin, assuming the project structure above
86+
one of the functions we add `-${opt:stage}` to the name in order to append the stage to the function name
8687

8788
```
8889
service: your-awesome-project
8990
91+
package:
92+
individually: true
93+
9094
plugins:
9195
- serverless-package-python-functions
9296
@@ -102,7 +106,7 @@ custom:
102106
103107
functions:
104108
function1:
105-
name: function1
109+
name: function1-${opt:stage}
106110
handler: lambda.handler
107111
package:
108112
include:
@@ -135,6 +139,9 @@ At the function level, you:
135139
- Use `include` to specify what function-level files you want to include in your artifact. Simply specifying the path to the function's folder will include every file in the folder in the function's zip artifact
136140
- Use `artifact` to tell Serverless where to find the zip artifact. The plugin creates the zip artifact for the function at `buildDir`/`name`.zip, so using `${self:custom.pkgPyFuncs.buildDir}/[function-name-here].zip` is advised.
137141

142+
At the package level, you may need to:
143+
- Specify the `individually` parameter as `true` to ensure that zip artifacts are generated properly. You may need this if you are getting file not found errors about your zip artifact.
144+
138145
Now, you may be wondering, doesn't the [Serverless documentation say](https://serverless.com/framework/docs/providers/aws/guide/packaging#artifact):
139146
> Serverless won't zip your service if [artifact] is configured and therefore exclude and include will be ignored. Either you use artifact or include / exclude.
140147

index.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const Fse = require('fs-extra');
66
const Path = require('path');
77
const ChildProcess = require('child_process');
88
const zipper = require('zip-local');
9+
const upath = require('upath');
910

1011
BbPromise.promisifyAll(Fse);
1112

@@ -23,15 +24,16 @@ class PkgPyFuncs {
2324
if ( !config ) {
2425
this.error("No serverless-package-python-functions configuration detected. Please see documentation")
2526
}
26-
config.requirementsFile ? this.requirementsFile = config.requirementsFile : this.requirementsFile = 'requirements.txt'
27+
this.requirementsFile = config.requirementsFile || 'requirements.txt'
2728
config.buildDir ? this.buildDir = config.buildDir : this.error("No buildDir configuration specified")
28-
config.globalRequirements ? this.globalRequirements = config.globalRequirements : this.globalRequirements = null
29-
config.globalIncludes ? this.globalIncludes = config.globalIncludes : this.globalIncludes = null
29+
this.globalRequirements = config.globalRequirements || []
30+
this.globalIncludes = config.globalIncludes || []
3031
config.cleanup === undefined ? this.cleanup = true : this.cleanup = config.cleanup
3132
this.useDocker = config.useDocker || false
3233
this.dockerImage = config.dockerImage || `lambci/lambda:build-${this.serverless.service.provider.runtime}`
3334
this.containerName = config.containerName || 'serverless-package-python-functions'
3435
this.mountSSH = config.mountSSH || false
36+
this.dockerServicePath = '/var/task'
3537
}
3638

3739
clean(){
@@ -78,13 +80,15 @@ class PkgPyFuncs {
7880
}
7981

8082
let cmd = 'pip'
81-
let args = ['install','--upgrade','-t', buildPath, '-r', requirementsPath]
83+
let args = ['install','--upgrade','-t', upath.normalize(buildPath), '-r']
8284
if ( this.useDocker === true ){
8385
cmd = 'docker'
84-
args = ['exec',this.containerName, 'pip', ...args]
86+
args = ['exec', this.containerName, 'pip', ...args]
87+
requirementsPath = `${this.dockerServicePath}/${requirementsPath}`
8588
}
8689

87-
return this.runProcess(cmd,args)
90+
args = [...args, upath.normalize(requirementsPath)]
91+
return this.runProcess(cmd, args)
8892
}
8993

9094
checkDocker(){
@@ -99,7 +103,7 @@ class PkgPyFuncs {
99103
}
100104

101105
if (ret.stderr.length != 0){
102-
throw new this.serverless.classes.Error(`[serverless-package-python-functions] ${ret.stderr.toString()}`)
106+
this.log(ret.stderr.toString())
103107
}
104108

105109
const out = ret.stdout.toString()
@@ -113,14 +117,13 @@ class PkgPyFuncs {
113117
if ( out === this.containerName ){
114118
this.log('Container already exists. Reusing.')
115119
} else {
116-
let args = ['run', '--rm', '-dt', '-v', `${process.cwd()}:/var/task`]
117-
120+
let args = ['run', '--rm', '-dt', '-v', `${process.cwd()}:${this.dockerServicePath}`]
121+
118122
if (this.mountSSH) {
119123
args = args.concat(['-v', `${process.env.HOME}/.ssh:/root/.ssh`])
120124
}
121-
125+
122126
args = args.concat(['--name',this.containerName, this.dockerImage, 'bash'])
123-
124127
this.runProcess('docker', args)
125128
this.log('Container created')
126129
}
@@ -153,7 +156,7 @@ class PkgPyFuncs {
153156
// Create package directory and package files
154157
Fse.ensureDirSync(buildPath)
155158
// Copy includes
156-
let includes = target.includes
159+
let includes = target.includes || []
157160
if (this.globalIncludes){
158161
includes = _.concat(includes, this.globalIncludes)
159162
}

package-lock.json

Lines changed: 18 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-package-python-functions",
3-
"version": "0.2.0",
3+
"version": "0.2.5",
44
"description": "Serverless Framework plugin to package python functions and their requirements",
55
"main": "index.js",
66
"scripts": {},
@@ -9,7 +9,8 @@
99
"dependencies": {
1010
"bluebird": "^3.5.0",
1111
"fs-extra": "^3.0.0",
12-
"lodash": "^4.17.4",
12+
"lodash": "^4.17.11",
13+
"upath": "^1.1.0",
1314
"zip-local": "^0.3.4"
1415
},
1516
"repository": {

0 commit comments

Comments
 (0)