@@ -14,7 +14,6 @@ BbPromise.promisifyAll(Fse);
14
14
class PkgPyFuncs {
15
15
16
16
fetchConfig ( ) {
17
-
18
17
if ( ! this . serverless . service . custom ) {
19
18
this . error ( "No serverless custom configurations are defined" )
20
19
}
@@ -36,6 +35,14 @@ class PkgPyFuncs {
36
35
this . dockerServicePath = '/var/task'
37
36
}
38
37
38
+ autoconfigArtifacts ( ) {
39
+ _ . map ( this . serverless . service . functions , ( func_config , func_name ) => {
40
+ let autoArtifact = `${ this . buildDir } /${ func_name } .zip`
41
+ func_config . package . artifact = func_config . package . artifact || autoArtifact
42
+ this . serverless . service . functions [ func_name ] = func_config
43
+ } )
44
+ }
45
+
39
46
clean ( ) {
40
47
if ( ! this . cleanup ) {
41
48
this . log ( 'Cleanup is set to "false". Build directory and Docker container (if used) will be retained' )
@@ -58,15 +65,17 @@ class PkgPyFuncs {
58
65
} ) ;
59
66
60
67
const info = _ . map ( functions , ( target ) => {
68
+
69
+
61
70
return {
62
71
name : target . name ,
63
- includes : target . package . include
72
+ includes : target . package . include ,
73
+ artifact : target . package . artifact
64
74
}
65
75
} )
66
76
return info
67
77
}
68
78
69
-
70
79
installRequirements ( buildPath , requirementsPath ) {
71
80
72
81
if ( ! Fse . pathExistsSync ( requirementsPath ) ) {
@@ -118,11 +127,11 @@ class PkgPyFuncs {
118
127
this . log ( 'Container already exists. Reusing.' )
119
128
} else {
120
129
let args = [ 'run' , '--rm' , '-dt' , '-v' , `${ process . cwd ( ) } :${ this . dockerServicePath } ` ]
121
-
130
+
122
131
if ( this . mountSSH ) {
123
132
args = args . concat ( [ '-v' , `${ process . env . HOME } /.ssh:/root/.ssh` ] )
124
133
}
125
-
134
+
126
135
args = args . concat ( [ '--name' , this . containerName , this . dockerImage , 'bash' ] )
127
136
this . runProcess ( 'docker' , args )
128
137
this . log ( 'Container created' )
@@ -171,14 +180,20 @@ class PkgPyFuncs {
171
180
zipper . sync . zip ( buildPath ) . compress ( ) . save ( `${ buildPath } .zip` )
172
181
}
173
182
183
+
184
+
174
185
constructor ( serverless , options ) {
175
186
this . serverless = serverless ;
176
187
this . options = options ;
177
188
this . log = ( msg ) => { this . serverless . cli . log ( `[serverless-package-python-functions] ${ msg } ` ) }
178
189
this . error = ( msg ) => { throw new Error ( `[serverless-package-python-functions] ${ msg } ` ) }
190
+
191
+
192
+
179
193
this . hooks = {
180
194
'before:package:createDeploymentArtifacts' : ( ) => BbPromise . bind ( this )
181
195
. then ( this . fetchConfig )
196
+ . then ( this . autoconfigArtifacts )
182
197
. then ( ( ) => { Fse . ensureDirAsync ( this . buildDir ) } )
183
198
. then ( this . setupDocker )
184
199
. then ( this . selectAll )
0 commit comments