Skip to content

Fix Windows support for dockerizePip #110

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
Dec 14, 2017
Merged

Conversation

heri16
Copy link
Contributor

@heri16 heri16 commented Dec 14, 2017

Fix docker volume bind path format, in order to support Docker for Windows when using sls/nodejs/docker from Powershell or from Windows Subsystem for Linux (WSL).

Issue #105

Fix docker volume bind path format, in order to support `Docker for Windows` when using sls/nodejs/docker from Powershell or from Windows Subsystem for Linux (WSL).
@dschep dschep merged commit 36c84a7 into serverless:master Dec 14, 2017
@dschep
Copy link
Contributor

dschep commented Dec 14, 2017

Thanks!!! I've also added your notes from #105 to the README.

@heri16
Copy link
Contributor Author

heri16 commented Dec 15, 2017

@dschep . I've just relooked into the issue and discovered that on many Windows on Docker configurations, the Docker Server version returns "linux" as the os type". I think we would need an explicit option flag to properly fix this, with additional documentation explaining when the flag is required.

@dschep
Copy link
Contributor

dschep commented Dec 15, 2017

Doh! Thank for that update. That's unfortunate, but not surprising in hindsight 😞

Any reason to not just check process.platform like I do to detect Linux?

@heri16
Copy link
Contributor Author

heri16 commented Dec 15, 2017

process.platform returns "linux" under windows WSL. This is because windows 10 is emulating the Linux kernel syscalls to run a Linux version of nodejs.

Under Windows WSL, a user might have both a Linux version of nodejs, and also a windows version of node.exe under the system $PATH. Heck, I even managed to run both docker Linux client and docker windows client from under the same terminal. This makes the detection code more tricky than expected, as we cannot depend purely on process.platform.

I think I might be able to fix this using this snippet: https://github.com/sindresorhus/is-wsl/blob/master/index.js

Possible solution:

  • If detected we are on a Linux platform running under WSL emulation, /mnt/ prefix would need to be removed from servicePath ( /mnt/e/folder becomes /e/folder). Then check if docker client version is:

    • Linux: then we already have the bind path as /e/folder is conforming to the CLI semantics of the linux version of docker client.
    • Windows: then we need to convert the bind path to e:/folder, to conform to the CLI semantics of the windows version of docker client.
  • If detected we are on the windows platform, likely with a windows version of docker client, then all backslashes in the servicePath needs to be converted to forward slash, according to the CLI semantics of the windows version of docker client. (E:\folder becomes E:/folder). If something like MINGW git-bash.exe is used, then servicePath would need to be converted from /e/folder into e:/folder.

Syscall-based Emulation can be a tricky thing to wrap our heads around.

@dschep
Copy link
Contributor

dschep commented Dec 15, 2017

That sounds fine to me. If you want to tackle it, feel free to add is-wsl to the dependencies.

@nickweavers
Copy link

nickweavers commented Dec 17, 2017

Hi @dschep.

var http = require("http");
var os = require("os");
var fs = require("fs")

console.log('os release: ' + os.release());
console.log('os type: ' +  os.type());  
console.log('os platform: ' + os.platform());  
console.log('os tmpdir: ' + os.tmpdir());
console.log("fs.readFileSync('/proc/version', 'utf8'): " + fs.readFileSync('/proc/version', 'utf8'));

On wsl (Ubuntu 16.04) gives me:

os release: 4.4.0-43-Microsoft
os type: Linux
os platform: linux
os tmpdir: /tmp
fs.readFileSync('/proc/version', 'utf8'): Linux version 4.4.0-43-Microsoft ([email protected]) (gcc version 5.4.0 (GCC) ) #1-Microsoft Wed Dec 31 14:42:53 PST 2014

and under native Ubuntu 14.04 LTS test server I see:
os release: 3.13.0-98-generic

os type: Linux
os platform: linux
os tmpdir: /tmp
fs.readFileSync('/proc/version', 'utf8'): Linux version 3.13.0-98-generic (buildd@lgw01-45) (gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3) ) #145-Ubuntu SMP Sat Oct 8 20:13:07 UTC 2016

So @heri16's discovery of Sindre Sorhus' is-wsl certainly looks like a good find.
Can I help with any testing in my setup?

Thanks,
Nick

@nickweavers
Copy link

Interesting video here: https://channel9.msdn.com/Blogs/Seth-Juarez/Windows-Subsystem-for-Linux-Process-Architecture (at around 4 mins 30 secs they explain Pico processes).
So, the different Linux distro's are now handled as Pico processes, each having a signed/vetted "driver". In the case of that pico process being a Linux distro, maybe "driver" has something stable that gets exposed and made visible via env , os or fs for us to identify that it is a distro running on wsl.

@nickweavers
Copy link

Hi @heri6,
I'd like to try your update but I'm not knowledgeable enough yet in npm to know how to download it from github and install.

I tried this:

$npm i --save-dev UnitedIncome/serverless-python-requirements#pull/116/head
npm ERR! code 1
npm ERR! Command failed: /usr/bin/git checkout pull/116/head
npm ERR! error: pathspec 'pull/116/head' did not match any file(s) known to git.
npm ERR!

Can you advise?
Thanks

@nickweavers
Copy link

$npm i --save-dev UnitedIncome/serverless-python-requirements/116/head
npm ERR! code ENOLOCAL
npm ERR! Could not install from "UnitedIncome/serverless-python-requirements/116/head" as it does not contain a package.json file.

@dschep
Copy link
Contributor

dschep commented Dec 18, 2017

@nickweavers see the installation note I put on #116

@nickweavers
Copy link

@dschep - got it, left results feedback after using your instructions. many thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants