Skip to content

Bugfig, allowing all paths to have spaces #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions lib/pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const {
getUserCachePath
} = require('./shared');

function quote_single(quoteme) {
return quote([quoteme]);
}

/**
* Just generate the requirements file in the .serverless folder
* @param {string} requirementsPath
Expand Down Expand Up @@ -100,7 +104,7 @@ function installRequirements(targetFolder, serverless, options) {
);
serverless.cli.log(`Using download cache directory ${downloadCacheDir}`);
fse.ensureDirSync(downloadCacheDir);
pipCmd.push('--cache-dir', downloadCacheDir);
pipCmd.push('--cache-dir', quote_single(downloadCacheDir));
}

// Check if pip has Debian's --system option and set it if so
Expand Down Expand Up @@ -145,18 +149,23 @@ function installRequirements(targetFolder, serverless, options) {
// Prepare bind path depending on os platform
const bindPath = getBindPath(serverless, targetFolder);

cmdOptions = ['run', '--rm', '-v', `"${bindPath}:/var/task:z"`];
cmdOptions = ['run', '--rm', '-v', quote_single(`${bindPath}:/var/task:z`)];
if (options.dockerSsh) {
// Mount necessary ssh files to work with private repos
cmdOptions.push(
'-v',
`"${process.env.HOME}/.ssh/id_rsa:/root/.ssh/id_rsa:z"`
quote_single(`${process.env.HOME}/.ssh/id_rsa:/root/.ssh/id_rsa:z`)
);
cmdOptions.push(
'-v',
`"${process.env.HOME}/.ssh/known_hosts:/root/.ssh/known_hosts:z"`
quote_single(
`${process.env.HOME}/.ssh/known_hosts:/root/.ssh/known_hosts:z`
)
);
cmdOptions.push(
'-v',
quote_single(`${process.env.SSH_AUTH_SOCK}:/tmp/ssh_sock:z`)
);
cmdOptions.push('-v', `"${process.env.SSH_AUTH_SOCK}:/tmp/ssh_sock:z"`);
cmdOptions.push('-e', 'SSH_AUTH_SOCK=/tmp/ssh_sock');
}

Expand All @@ -177,8 +186,11 @@ function installRequirements(targetFolder, serverless, options) {
);
const windowsized = getBindPath(serverless, downloadCacheDir);
// And now push it to a volume mount and to pip...
cmdOptions.push('-v', `"${windowsized}:${dockerDownloadCacheDir}:z"`);
pipCmd.push('--cache-dir', dockerDownloadCacheDir);
cmdOptions.push(
'-v',
quote_single(`${windowsized}:${dockerDownloadCacheDir}:z`)
);
pipCmd.push('--cache-dir', quote_single(dockerDownloadCacheDir));
}

if (process.platform === 'linux') {
Expand All @@ -189,7 +201,7 @@ function installRequirements(targetFolder, serverless, options) {
commands.push(quote(['chown', '-R', '0:0', dockerDownloadCacheDir]));
}
// Install requirements with pip
commands.push(quote(pipCmd));
commands.push(pipCmd.join(' '));
// Set the ownership of the current folder to user
commands.push(
quote([
Expand All @@ -213,7 +225,7 @@ function installRequirements(targetFolder, serverless, options) {
pipCmd = ['/bin/bash', '-c', '"' + commands.join(' && ') + '"'];
} else {
// Use same user so --cache-dir works
cmdOptions.push('-u', getDockerUid(bindPath));
cmdOptions.push('-u', quote_single(getDockerUid(bindPath)));
}
cmdOptions.push(dockerImage);
cmdOptions.push(...pipCmd);
Expand Down Expand Up @@ -262,7 +274,7 @@ function dockerPathForWin(options, path) {
if (process.platform === 'win32' && options.dockerizePip) {
return path.replace(/\\/g, '/');
}
return path;
return quote_single(path);
}

/** create a filtered requirements.txt without anything from noDeploy
Expand Down