1
1
const fse = require ( 'fs-extra' ) ;
2
2
const path = require ( 'path' ) ;
3
3
const { spawnSync} = require ( 'child_process' ) ;
4
+ const isWsl = require ( 'is-wsl' ) ;
4
5
5
6
/**
6
7
* pip install the requirements to the .serverless/requirements directory
@@ -50,10 +51,10 @@ function installRequirements() {
50
51
51
52
this . serverless . cli . log ( `Docker Image: ${ this . options . dockerImage } ` ) ;
52
53
53
- // Check docker server os type from 'docker version'
54
- let volPath ;
54
+ // Determine bindPath semantics from 'docker version'
55
+ let bindPath ;
55
56
options = [
56
- 'version' , '--format' , '{{with .Server }}{{.Os}}{{end}}'
57
+ 'version' , '--format' , '{{with .Client }}{{.Os}}{{end}}'
57
58
] ;
58
59
const ps = spawnSync ( cmd , options , { 'timeout' : 2000 , 'encoding' : 'utf-8' } ) ;
59
60
if ( ps . error ) {
@@ -64,15 +65,27 @@ function installRequirements() {
64
65
}
65
66
if ( ps . status !== 0 ) {
66
67
throw new Error ( ps . stderr ) ;
67
- } else if ( ps . stdout . trim ( ) === 'windows' ) {
68
- volPath = this . servicePath . replace ( / \\ / g, '/' ) . replace ( / ^ \/ m n t \/ / , '/' ) ;
68
+ }
69
+
70
+ const cliPlatform = ps . stdout . trim ( ) ;
71
+
72
+ if ( process . platform === 'win32' ) {
73
+ bindPath = this . servicePath . replace ( / \\ ( [ ^ \s ] ) / g, '/$1' ) ;
74
+ if ( cliPlatform === 'windows' ) {
75
+ bindPath = bindPath . replace ( / ^ \/ ( \w ) \/ / i, '$1:/' ) ;
76
+ }
77
+ } else if ( isWsl ) {
78
+ bindPath = this . servicePath . replace ( / ^ \/ m n t \/ / , '/' ) ;
79
+ if ( cliPlatform === 'windows' ) {
80
+ bindPath = bindPath . replace ( / ^ \/ ( \w ) \/ / i, '$1:/' ) ;
81
+ }
69
82
} else {
70
- volPath = this . servicePath ;
83
+ bindPath = this . servicePath ;
71
84
}
72
85
73
86
options = [
74
87
'run' , '--rm' ,
75
- '-v' , `${ volPath } :/var/task:z` ,
88
+ '-v' , `${ bindPath } :/var/task:z` ,
76
89
] ;
77
90
if ( process . platform === 'linux' )
78
91
options . push ( '-u' , `${ process . getuid ( ) } :${ process . getgid ( ) } ` ) ;
0 commit comments