@@ -8,7 +8,7 @@ const path = require('path');
8
8
* @param {string[] } options
9
9
* @return {Object }
10
10
*/
11
- async function dockerCommand ( options ) {
11
+ async function dockerCommand ( options , pluginInstance ) {
12
12
const cmd = 'docker' ;
13
13
try {
14
14
return await spawn ( cmd , options , { encoding : 'utf-8' } ) ;
@@ -17,7 +17,10 @@ async function dockerCommand(options) {
17
17
e . stderrBuffer &&
18
18
e . stderrBuffer . toString ( ) . includes ( 'command not found' )
19
19
) {
20
- throw new Error ( 'docker not found! Please install it.' ) ;
20
+ throw new pluginInstance . serverless . classes . Error (
21
+ 'docker not found! Please install it.' ,
22
+ 'PYTHON_REQUIREMENTS_DOCKER_NOT_FOUND'
23
+ ) ;
21
24
}
22
25
throw e ;
23
26
}
@@ -29,19 +32,22 @@ async function dockerCommand(options) {
29
32
* @param {string[] } extraArgs
30
33
* @return {string } The name of the built docker image.
31
34
*/
32
- async function buildImage ( dockerFile , extraArgs ) {
35
+ async function buildImage ( dockerFile , extraArgs , pluginInstance ) {
33
36
const imageName = 'sls-py-reqs-custom' ;
34
37
const options = [ 'build' , '-f' , dockerFile , '-t' , imageName ] ;
35
38
36
39
if ( Array . isArray ( extraArgs ) ) {
37
40
options . push ( ...extraArgs ) ;
38
41
} else {
39
- throw new Error ( 'dockerRunCmdExtraArgs option must be an array' ) ;
42
+ throw new pluginInstance . serverless . classes . Error (
43
+ 'dockerRunCmdExtraArgs option must be an array' ,
44
+ 'PYTHON_REQUIREMENTS_INVALID_DOCKER_EXTRA_ARGS'
45
+ ) ;
40
46
}
41
47
42
48
options . push ( '.' ) ;
43
49
44
- await dockerCommand ( options ) ;
50
+ await dockerCommand ( options , pluginInstance ) ;
45
51
return imageName ;
46
52
}
47
53
@@ -50,7 +56,7 @@ async function buildImage(dockerFile, extraArgs) {
50
56
* @param {string } servicePath
51
57
* @return {string } file name
52
58
*/
53
- function findTestFile ( servicePath ) {
59
+ function findTestFile ( servicePath , pluginInstance ) {
54
60
if ( fse . pathExistsSync ( path . join ( servicePath , 'serverless.yml' ) ) ) {
55
61
return 'serverless.yml' ;
56
62
}
@@ -63,8 +69,9 @@ function findTestFile(servicePath) {
63
69
if ( fse . pathExistsSync ( path . join ( servicePath , 'requirements.txt' ) ) ) {
64
70
return 'requirements.txt' ;
65
71
}
66
- throw new Error (
67
- 'Unable to find serverless.{yml|yaml|json} or requirements.txt for getBindPath()'
72
+ throw new pluginInstance . serverless . classes . Error (
73
+ 'Unable to find serverless.{yml|yaml|json} or requirements.txt for getBindPath()' ,
74
+ 'PYTHON_REQUIREMENTS_MISSING_GET_BIND_PATH_FILE'
68
75
) ;
69
76
}
70
77
@@ -73,7 +80,8 @@ function findTestFile(servicePath) {
73
80
* @param {string } bindPath
74
81
* @return {boolean }
75
82
*/
76
- async function tryBindPath ( bindPath , testFile , { serverless, log } ) {
83
+ async function tryBindPath ( bindPath , testFile , pluginInstance ) {
84
+ const { serverless, log } = pluginInstance ;
77
85
const debug = process . env . SLS_DEBUG ;
78
86
const options = [
79
87
'run' ,
@@ -92,7 +100,7 @@ async function tryBindPath(bindPath, testFile, { serverless, log }) {
92
100
serverless . cli . log ( `Trying bindPath ${ bindPath } (${ options } )` ) ;
93
101
}
94
102
}
95
- const ps = await dockerCommand ( options ) ;
103
+ const ps = await dockerCommand ( options , pluginInstance ) ;
96
104
if ( debug ) {
97
105
if ( log ) {
98
106
log . debug ( ps . stdoutBuffer . trim ( ) ) ;
@@ -126,7 +134,7 @@ async function getBindPath(servicePath, pluginInstance) {
126
134
}
127
135
128
136
// test docker is available
129
- await dockerCommand ( [ 'version' ] ) ;
137
+ await dockerCommand ( [ 'version' ] , pluginInstance ) ;
130
138
131
139
// find good bind path for Windows
132
140
let bindPaths = [ ] ;
@@ -159,7 +167,7 @@ async function getBindPath(servicePath, pluginInstance) {
159
167
bindPaths . push ( `/mnt/${ drive . toUpperCase ( ) } /${ path } ` ) ;
160
168
bindPaths . push ( `${ drive . toUpperCase ( ) } :/${ path } ` ) ;
161
169
162
- const testFile = findTestFile ( servicePath ) ;
170
+ const testFile = findTestFile ( servicePath , pluginInstance ) ;
163
171
164
172
for ( let i = 0 ; i < bindPaths . length ; i ++ ) {
165
173
const bindPath = bindPaths [ i ] ;
@@ -176,7 +184,7 @@ async function getBindPath(servicePath, pluginInstance) {
176
184
* @param {string } bindPath
177
185
* @return {boolean }
178
186
*/
179
- async function getDockerUid ( bindPath ) {
187
+ async function getDockerUid ( bindPath , pluginInstance ) {
180
188
const options = [
181
189
'run' ,
182
190
'--rm' ,
@@ -188,7 +196,7 @@ async function getDockerUid(bindPath) {
188
196
'%u' ,
189
197
'/bin/sh' ,
190
198
] ;
191
- const ps = await dockerCommand ( options ) ;
199
+ const ps = await dockerCommand ( options , pluginInstance ) ;
192
200
return ps . stdoutBuffer . trim ( ) ;
193
201
}
194
202
0 commit comments