Skip to content

command: check for wsl mount path on windows - #5424

Merged
thaJeztah merged 1 commit into
docker:masterfrom
jsternberg:wsl-socket-path
Sep 12, 2024
Merged

command: check for wsl mount path on windows#5424
thaJeztah merged 1 commit into
docker:masterfrom
jsternberg:wsl-socket-path

Conversation

@jsternberg

Copy link
Copy Markdown
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

codecov-commenter commented Sep 10, 2024

Copy link
Copy Markdown

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 

Comment threadcli/command/telemetry_docker.go Outdated
@jsternberg
jsternbergforce-pushed the wsl-socket-path branch 4 times, most recently from 3045f17 to cb36c1dCompareSeptember 11, 2024 02:39
// Enforce that we are using forward slashes.
return "unix://" + filepath.ToSlash(socketPath)

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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?

@laurazardlaurazardSep 12, 2024

Copy link
Copy Markdown
Member

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
Copy Markdown
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

@laurazardlaurazard 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
Copy Markdown
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)

@laurazardlaurazard left a comment

Copy link
Copy Markdown
Member

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 😅

@laurazardlaurazard left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 🎉

@thaJeztahthaJeztah left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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 freeto 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

@jsternberg@codecov-commenter@laurazard@thaJeztah@crazy-max