Skip to content

Commit 6b32ff1

Browse files
committed
add a feature flag to abort on packaging errors
1 parent a00f90d commit 6b32ff1

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ The plugin configurations are simple:
133133
| useDocker | Boolean indicating whether to package pip dependencies using Docker. Set this to true if your project uses platform-specific compiled libraries like numpy. Requires a [Docker installation](https://www.docker.com/get-docker). | Yes. Defaults to `false` |
134134
| dockerImage | The Docker image to use to compile functions if `useDocker` is set to `true`. Must be specified as `repository:tag`. If the image doesn't exist on the system, it will be downloaded. The initial download may take some time. | Yes. Defaults to `lambci/lambda:build-${provider.runtime}` |
135135
| containerName | The desired name for the Docker container. | Yes. Defaults to `serverless-package-python-functions` |
136+
| usePackagingErrorAlerts | Boolean indicating whether you want to stop deployment when packaging errors are detected. Example errors include: `useDocker` is enabled but the Docker service is not running, pip finds dependency mismatches, virtual environment errrors, etc.. When an error is detected, this will prompt via commandline to continue or abort deploy. | Yes. Defaults to `false` |
136137

137138
At the function level, you:
138139
- Specify `name` to give your function a name. The plugin uses the function's name as the name of the zip artifact

index.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class PkgPyFuncs {
3333
this.dockerImage = config.dockerImage || `lambci/lambda:build-${this.serverless.service.provider.runtime}`
3434
this.containerName = config.containerName || 'serverless-package-python-functions'
3535
this.mountSSH = config.mountSSH || false
36+
this.usePackagingErrorAlerts = config.usePackagingErrorAlerts || false
3637
this.dockerServicePath = '/var/task'
3738
}
3839

@@ -117,18 +118,21 @@ class PkgPyFuncs {
117118
if (ret.stderr.length != 0){
118119
const errorText = ret.stderr.toString().trim()
119120
this.log(errorText) // prints stderr
120-
const countErrorNewLines = errorText.split('\n').length
121-
122-
if(countErrorNewLines < 2 && errorText.toLowerCase().includes('git clone')){
123-
// Ignore false positive due to pip git clone printing to stderr
124-
} else if(errorText.toLowerCase().includes('docker')){
125-
console.log('stdout:', out)
126-
this.error("Docker Error Detected")
127-
128-
} else {
129-
// Error is not false positive,
130-
console.log('___ERROR DETECTED, BEGIN STDOUT____\n', out)
131-
this.requestUserConfirmation()
121+
122+
if (this.usePackagingErrorAlerts){
123+
const countErrorNewLines = errorText.split('\n').length
124+
125+
if(countErrorNewLines < 2 && errorText.toLowerCase().includes('git clone')){
126+
// Ignore false positive due to pip git clone printing to stderr
127+
} else if(errorText.toLowerCase().includes('docker')){
128+
console.log('stdout:', out)
129+
this.error("Docker Error Detected")
130+
131+
} else {
132+
// Error is not false positive,
133+
console.log('___ERROR DETECTED, BEGIN STDOUT____\n', out)
134+
this.requestUserConfirmation()
135+
}
132136
}
133137

134138
}

0 commit comments

Comments
 (0)