Skip to content
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

command: check for wsl mount path on windows #5424

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

jsternberg
Copy link
Contributor

- What I did

This checks for the equivalent WSL mount path on windows. WSL will mount the windows drives at /mnt/c (or whichever drive is being used).

- How I did it

The code will now check to see if a file exists in /mnt/<drive>. If there is no drive in the path, it'll default to the C drive. If that file exists, it will use it. The check now also supports URLs of the format c:/path/to/file (note the forward slashes rather than backslashes).

- How to verify it

Integrate the change with buildx and run a build in a WSL container on Windows.

- Description for the changelog

* Properly report metrics when run in WSL environment on Windows

@codecov-commenter
Copy link

codecov-commenter commented Sep 10, 2024

Codecov Report

Attention: Patch coverage is 47.72727% with 23 lines in your changes missing coverage. Please review.

Project coverage is 59.75%. Comparing base (6372ec9) to head (38c3fef).
Report is 19 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5424      +/-   ##
==========================================
+ Coverage   59.73%   59.75%   +0.02%     
==========================================
  Files         345      345              
  Lines       23394    23428      +34     
==========================================
+ Hits        13974    13999      +25     
- Misses       8450     8455       +5     
- Partials      970      974       +4     

@jsternberg jsternberg force-pushed the wsl-socket-path branch 4 times, most recently from 3045f17 to cb36c1d Compare September 11, 2024 02:39
// Enforce that we are using forward slashes.
return "unix://" + filepath.ToSlash(socketPath)
Copy link
Member

Choose a reason for hiding this comment

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

Should this be an error (or warning -> ignore) instead? i.e., should we only accept unix:// and only accept forward-slashes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is mostly just to make sure the output is correct. I don't think this needs to be an error or warning. The reason why it's here and not somewhere else is it communicates that the requirement for forward slashes comes from the URL format. We could move this call into wslSocketPath and it would be fine, but we'd want to add a comment along the lines of "using forward slashes so this is compatible with a URL" so why not just have the code where we're constructing the URL?

Copy link
Member

@laurazard laurazard Sep 12, 2024

Choose a reason for hiding this comment

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

IIUC, the unix:// + here isn't to just add the prefix back in @thaJeztah, it's just re-adding the prefix we cut out when we parsed the URL/transformed the path.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, right; overlooked that part.

I guess we could've written back to u.Path, and returned u.String() 😅

Either way; it's probably ok for now; we can do follow-ups

@laurazard laurazard added this to the 27.3 milestone Sep 12, 2024
This checks for the equivalent WSL mount path on windows. WSL will mount
the windows drives at `/mnt/c` (or whichever drive is being used).

This is done by parsing a UNC path with forward slashes from the unix
socket URL.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
@laurazard
Copy link
Member

To reiterate (and make reviewing easier), the behavior is now:

  • If the filepath exists and running under WSL:
    • //./c:/my/file/path => /mnt/c/my/file/path
    • //./d:/my/file/path => /mnt/d/my/file/path
  • If the filepath does not exist:
    • //./c:/my/file/path => //./c:/my/file/path (no changes)
  • If not running under WSL:
    • //./c:/my/file/path => //./c:/my/file/path (no changes)

(cc @jsternberg)

Copy link
Member

@laurazard laurazard left a comment

Choose a reason for hiding this comment

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

LGTM 🎉 clicked the wrong button 😅

Copy link
Member

@laurazard laurazard left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

// Enforce that we are using forward slashes.
return "unix://" + filepath.ToSlash(socketPath)
Copy link
Member

Choose a reason for hiding this comment

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

Ah, right; overlooked that part.

I guess we could've written back to u.Path, and returned u.String() 😅

Either way; it's probably ok for now; we can do follow-ups

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

Successfully merging this pull request may close these issues.

5 participants