@@ -27,15 +27,19 @@ function quote_single(quoteme) {
27
27
* @param {Object } options
28
28
* @return {undefined }
29
29
*/
30
- function installRequirementsFile (
30
+ function generateRequirementsFile (
31
31
requirementsPath ,
32
32
targetFile ,
33
33
serverless ,
34
34
servicePath ,
35
35
options
36
36
) {
37
37
if ( options . usePipenv && fse . existsSync ( path . join ( servicePath , 'Pipfile' ) ) ) {
38
- generateRequirementsFile (
38
+ filterRequirementsFile (
39
+ /*
40
+ TODO: this is supposed to generate a requirements.txt from Pipfile,
41
+ but source and target are basicalle the same
42
+ */
39
43
path . join ( servicePath , '.serverless/requirements.txt' ) ,
40
44
targetFile ,
41
45
options
@@ -44,7 +48,7 @@ function installRequirementsFile(
44
48
`Parsed requirements.txt from Pipfile in ${ targetFile } ...`
45
49
) ;
46
50
} else {
47
- generateRequirementsFile ( requirementsPath , targetFile , options ) ;
51
+ filterRequirementsFile ( requirementsPath , targetFile , options ) ;
48
52
serverless . cli . log (
49
53
`Generated requirements from ${ requirementsPath } in ${ targetFile } ...`
50
54
) ;
@@ -196,6 +200,13 @@ function installRequirements(targetFolder, serverless, options) {
196
200
pipCmd . push ( '--cache-dir' , quote_single ( dockerDownloadCacheDir ) ) ;
197
201
}
198
202
203
+ if ( options . dockerEnv ) {
204
+ // Add environment variables to docker run cmd
205
+ options . dockerEnv . forEach ( function ( item ) {
206
+ cmdOptions . push ( '-e' , item ) ;
207
+ } ) ;
208
+ }
209
+
199
210
if ( process . platform === 'linux' ) {
200
211
// Use same user so requirements folder is not root and so --cache-dir works
201
212
var commands = [ ] ;
@@ -293,7 +304,7 @@ function dockerPathForWin(options, path) {
293
304
* @param {string } target requirements where results are written
294
305
* @param {Object } options
295
306
*/
296
- function generateRequirementsFile ( source , target , options ) {
307
+ function filterRequirementsFile ( source , target , options ) {
297
308
const noDeploy = new Set ( options . noDeploy || [ ] ) ;
298
309
const requirements = fse
299
310
. readFileSync ( source , { encoding : 'utf-8' } )
@@ -374,11 +385,26 @@ function installRequirementsIfNeeded(
374
385
// Our source requirements, under our service path, and our module path (if specified)
375
386
const fileName = path . join ( servicePath , modulePath , options . fileName ) ;
376
387
377
- // First, generate the requirements file to our local .serverless folder
378
- fse . ensureDirSync ( path . join ( servicePath , '.serverless' ) ) ;
379
- const slsReqsTxt = path . join ( servicePath , '.serverless' , 'requirements.txt' ) ;
388
+ // Skip requirements generation, if requirements file doesn't exist
389
+ if ( ! fse . existsSync ( fileName ) ) {
390
+ return false ;
391
+ }
380
392
381
- installRequirementsFile (
393
+ let requirementsTxtDirectory ;
394
+ // Copy our requirements to another filename in .serverless (incase of individually packaged)
395
+ if ( modulePath && modulePath != '.' ) {
396
+ requirementsTxtDirectory = path . join (
397
+ servicePath ,
398
+ '.serverless' ,
399
+ modulePath
400
+ ) ;
401
+ } else {
402
+ requirementsTxtDirectory = path . join ( servicePath , '.serverless' ) ;
403
+ }
404
+ fse . ensureDirSync ( requirementsTxtDirectory ) ;
405
+ const slsReqsTxt = path . join ( requirementsTxtDirectory , 'requirements.txt' ) ;
406
+
407
+ generateRequirementsFile (
382
408
fileName ,
383
409
slsReqsTxt ,
384
410
serverless ,
@@ -394,28 +420,13 @@ function installRequirementsIfNeeded(
394
420
return false ;
395
421
}
396
422
397
- // Copy our requirements to another filename in .serverless (incase of individually packaged)
398
- if ( modulePath && modulePath != '.' ) {
399
- fse . existsSync ( path . join ( servicePath , '.serverless' , modulePath ) ) ;
400
- const destinationFile = path . join (
401
- servicePath ,
402
- '.serverless' ,
403
- modulePath ,
404
- 'requirements.txt'
405
- ) ;
406
- serverless . cli . log (
407
- `Copying from ${ slsReqsTxt } into ${ destinationFile } ...`
408
- ) ;
409
- fse . copySync ( slsReqsTxt , destinationFile ) ;
410
- }
411
-
412
423
// Then generate our MD5 Sum of this requirements file to determine where it should "go" to and/or pull cache from
413
424
const reqChecksum = md5Path ( slsReqsTxt ) ;
414
425
415
426
// Then figure out where this cache should be, if we're caching, if we're in a module, etc
416
427
const workingReqsFolder = getRequirementsWorkingPath (
417
428
reqChecksum ,
418
- servicePath ,
429
+ requirementsTxtDirectory ,
419
430
options
420
431
) ;
421
432
0 commit comments