Skip to content

Fix --cache-dir with Docker #145

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 10 commits into from
Mar 20, 2018
13 changes: 5 additions & 8 deletions lib/pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const path = require('path');
const get = require('lodash.get');
const set = require('lodash.set');
const {spawnSync} = require('child_process');
const {quote} = require('shell-quote');
const values = require('lodash.values');
const {buildImage, getBindPath} = require('./docker');

Expand Down Expand Up @@ -87,19 +86,17 @@ function installRequirements(requirementsPath, targetFolder, serverless, service
cmdOptions.push('-e', 'SSH_AUTH_SOCK=/tmp/ssh_sock');
}
if (process.platform === 'linux') {
// Set the ownership of the .serverless/requirements folder to current user
pipCmd = quote(pipCmd);
const chownCmd = quote([
'chown', '-R', `${process.getuid()}:${process.getgid()}`,
targetRequirementsFolder,
]);
pipCmd = ['/bin/bash', '-c', '"' + pipCmd + ' && ' + chownCmd + '"'];
// Use same user so requirements folder is not root and so --cache-dir works
cmdOptions.push('-u', `${process.getuid()}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cgrimal, AFAICT you added the chown stuff. Could you test this alternative?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW tests passed on Linux with all Docker tests enabled. There was no problem deleting the .serverless folder.

// const stripCmd = quote([
// 'find', targetRequirementsFolder,
// '-name', '"*.so"',
// '-exec', 'strip', '{}', '\;',
// ]);
// pipCmd = ['/bin/bash', '-c', '"' + pipCmd + ' && ' + stripCmd + ' && ' + chownCmd + '"'];
} else if (process.platform === 'win32') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change this to an empty else (or add macOS/darwin)? and I'll have some one with a mac test it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Circle.CI configured to test on Mac OS X too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, AFAIK circle doesn't offer free mac os builds.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be open to moving to Travis.CI? Mac builds are free there and I think they have a working Docker setup too.

// Use same user so --cache-dir works
cmdOptions.push('-u', '1000'); // TODO is this always the case?
}
cmdOptions.push(dockerImage);
cmdOptions.push(...pipCmd);
Expand Down