@@ -14,6 +14,10 @@ const {
1414 getUserCachePath
1515} = require ( './shared' ) ;
1616
17+ function quote_single ( quoteme ) {
18+ return quote ( [ quoteme ] ) ;
19+ }
20+
1721/**
1822 * Just generate the requirements file in the .serverless folder
1923 * @param {string } requirementsPath
@@ -100,7 +104,7 @@ function installRequirements(targetFolder, serverless, options) {
100104 ) ;
101105 serverless . cli . log ( `Using download cache directory ${ downloadCacheDir } ` ) ;
102106 fse . ensureDirSync ( downloadCacheDir ) ;
103- pipCmd . push ( '--cache-dir' , downloadCacheDir ) ;
107+ pipCmd . push ( '--cache-dir' , quote_single ( downloadCacheDir ) ) ;
104108 }
105109
106110 // Check if pip has Debian's --system option and set it if so
@@ -145,18 +149,23 @@ function installRequirements(targetFolder, serverless, options) {
145149 // Prepare bind path depending on os platform
146150 const bindPath = getBindPath ( serverless , targetFolder ) ;
147151
148- cmdOptions = [ 'run' , '--rm' , '-v' , `" ${ bindPath } :/var/task:z"` ] ;
152+ cmdOptions = [ 'run' , '--rm' , '-v' , quote_single ( ` ${ bindPath } :/var/task:z` ) ] ;
149153 if ( options . dockerSsh ) {
150154 // Mount necessary ssh files to work with private repos
151155 cmdOptions . push (
152156 '-v' ,
153- `" ${ process . env . HOME } /.ssh/id_rsa:/root/.ssh/id_rsa:z"`
157+ quote_single ( ` ${ process . env . HOME } /.ssh/id_rsa:/root/.ssh/id_rsa:z` )
154158 ) ;
155159 cmdOptions . push (
156160 '-v' ,
157- `"${ process . env . HOME } /.ssh/known_hosts:/root/.ssh/known_hosts:z"`
161+ quote_single (
162+ `${ process . env . HOME } /.ssh/known_hosts:/root/.ssh/known_hosts:z`
163+ )
164+ ) ;
165+ cmdOptions . push (
166+ '-v' ,
167+ quote_single ( `${ process . env . SSH_AUTH_SOCK } :/tmp/ssh_sock:z` )
158168 ) ;
159- cmdOptions . push ( '-v' , `"${ process . env . SSH_AUTH_SOCK } :/tmp/ssh_sock:z"` ) ;
160169 cmdOptions . push ( '-e' , 'SSH_AUTH_SOCK=/tmp/ssh_sock' ) ;
161170 }
162171
@@ -177,8 +186,11 @@ function installRequirements(targetFolder, serverless, options) {
177186 ) ;
178187 const windowsized = getBindPath ( serverless , downloadCacheDir ) ;
179188 // And now push it to a volume mount and to pip...
180- cmdOptions . push ( '-v' , `"${ windowsized } :${ dockerDownloadCacheDir } :z"` ) ;
181- pipCmd . push ( '--cache-dir' , dockerDownloadCacheDir ) ;
189+ cmdOptions . push (
190+ '-v' ,
191+ quote_single ( `${ windowsized } :${ dockerDownloadCacheDir } :z` )
192+ ) ;
193+ pipCmd . push ( '--cache-dir' , quote_single ( dockerDownloadCacheDir ) ) ;
182194 }
183195
184196 if ( process . platform === 'linux' ) {
@@ -189,7 +201,7 @@ function installRequirements(targetFolder, serverless, options) {
189201 commands . push ( quote ( [ 'chown' , '-R' , '0:0' , dockerDownloadCacheDir ] ) ) ;
190202 }
191203 // Install requirements with pip
192- commands . push ( quote ( pipCmd ) ) ;
204+ commands . push ( pipCmd . join ( ' ' ) ) ;
193205 // Set the ownership of the current folder to user
194206 commands . push (
195207 quote ( [
@@ -213,7 +225,7 @@ function installRequirements(targetFolder, serverless, options) {
213225 pipCmd = [ '/bin/bash' , '-c' , '"' + commands . join ( ' && ' ) + '"' ] ;
214226 } else {
215227 // Use same user so --cache-dir works
216- cmdOptions . push ( '-u' , getDockerUid ( bindPath ) ) ;
228+ cmdOptions . push ( '-u' , quote_single ( getDockerUid ( bindPath ) ) ) ;
217229 }
218230 cmdOptions . push ( dockerImage ) ;
219231 cmdOptions . push ( ...pipCmd ) ;
@@ -262,7 +274,7 @@ function dockerPathForWin(options, path) {
262274 if ( process . platform === 'win32' && options . dockerizePip ) {
263275 return path . replace ( / \\ / g, '/' ) ;
264276 }
265- return path ;
277+ return quote_single ( path ) ;
266278}
267279
268280/** create a filtered requirements.txt without anything from noDeploy
0 commit comments