Skip to content

Commit 36c84a7

Browse files
authored
Merge pull request #110 from heri16/patch-3
Fix Windows support for dockerizePip
2 parents c2038c2 + 32df7d6 commit 36c84a7

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/pip.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,29 @@ function installRequirements() {
5050

5151
this.serverless.cli.log(`Docker Image: ${this.options.dockerImage}`);
5252

53+
// Check docker server os type from 'docker version'
54+
let volPath;
55+
options = [
56+
'version', '--format', '{{with .Server}}{{.Os}}{{end}}'
57+
];
58+
const ps = spawnSync(cmd, options, {'timeout': 2000, 'encoding': 'utf-8'});
59+
if (ps.error) {
60+
if (ps.error.code === 'ENOENT') {
61+
throw new Error('docker not found! Please install it.');
62+
}
63+
throw new Error(ps.error);
64+
}
65+
if (ps.status !== 0) {
66+
throw new Error(ps.stderr);
67+
} else if (ps.stdout.trim() === 'windows') {
68+
volPath = this.servicePath.replace(/\\/g, '/').replace(/^\/mnt\//, '/');
69+
} else {
70+
volPath = this.servicePath;
71+
}
72+
5373
options = [
5474
'run', '--rm',
55-
'-v', `${this.servicePath}:/var/task:z`,
75+
'-v', `${volPath}:/var/task:z`,
5676
];
5777
if (process.platform === 'linux')
5878
options.push('-u', `${process.getuid()}:${process.getgid()}`);

0 commit comments

Comments
 (0)