Skip to content

Commit 1b61cf1

Browse files
committed
abort deploy for docker errors, ignore git clone to stderr, allow interaction to bypass other errors, add pip --quiet
1 parent f8dbbe7 commit 1b61cf1

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

index.js

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const Path = require('path');
77
const ChildProcess = require('child_process');
88
const zipper = require('zip-local');
99
const upath = require('upath');
10+
const readlineSync = require('readline-sync');
1011

1112
BbPromise.promisifyAll(Fse);
1213

@@ -89,7 +90,7 @@ class PkgPyFuncs {
8990
}
9091

9192
let cmd = 'pip'
92-
let args = ['install', '--upgrade','-t', upath.normalize(buildPath), '-r']
93+
let args = ['install', '-t', upath.normalize(buildPath), '-qq', '-r']
9394
if ( this.useDocker === true ){
9495
cmd = 'docker'
9596
args = ['exec', this.containerName, 'pip', ...args]
@@ -111,25 +112,51 @@ class PkgPyFuncs {
111112
throw new this.serverless.classes.Error(`[serverless-package-python-functions] ${ret.error.message}`)
112113
}
113114

115+
const out = ret.stdout.toString()
116+
114117
if (ret.stderr.length != 0){
115118
const errorText = ret.stderr.toString().trim()
116-
console.log(errorText)
117-
this.error(errorText)
118-
// if (errorText.toLowerCase().search('error') != -1){
119-
// this.log(errorText)
120-
// console.log(errorText)
121-
// this.error(errorText)
122-
// }
119+
const countErrorNewLines = errorText.split('\n').length
120+
121+
if(countErrorNewLines < 2 && errorText.toLowerCase().includes('git clone')){
122+
// Ignore false positive due to pip git clone printing to stderr
123+
console.log(errorText)
124+
} else if(errorText.toLowerCase().includes('docker')){
125+
console.log('stdout:', out)
126+
console.log('stderr: ', errorText)
127+
this.error("Docker Error Detected")
128+
129+
} else {
130+
// Error is not false positive,
131+
console.log('___ERROR DETECTED, BEGIN STDOUT____\n', out)
132+
console.log('---BEGIN STDERR---\n', errorText)
133+
this.requestUserConfirmation()
134+
}
135+
123136
}
124137

125-
const out = ret.stdout.toString()
126138
return out
127139
}
128140

141+
requestUserConfirmation(prompt="\n\n??? Do you wish to continue deployment with the stated errors? \n",
142+
yesText="Continuing Deployment!",
143+
noText='ABORTING DEPLOYMENT'
144+
){
145+
const response = readlineSync.question(prompt);
146+
if(response.toLowerCase().includes('y')) {
147+
console.log(yesText);
148+
return
149+
} else {
150+
console.log(noText)
151+
this.error('Aborting')
152+
return
153+
}
154+
}
129155

130156
setupContainer(){
131157
let out = this.runProcess('docker',['ps', '-a', '--filter',`name=${this.containerName}`,'--format','{{.Names}}'])
132158
out = out.replace(/^\s+|\s+$/g, '')
159+
console.log('SDLFKJSDL:KFJSDL:KFJ ', this.containerName)
133160

134161
if ( out === this.containerName ){
135162
this.log('Container already exists. Reusing.')

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"fs-extra": "^3.0.0",
1212
"lodash": "^4.17.11",
1313
"upath": "^1.1.0",
14+
"readline-sync": "^1.4.10",
1415
"zip-local": "^0.3.4"
1516
},
1617
"repository": {

0 commit comments

Comments
 (0)