Skip to content

ci: add WSL2 CI #1883

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
Oct 9, 2023
Merged

ci: add WSL2 CI #1883

merged 1 commit into from
Oct 9, 2023

Conversation

pendo324
Copy link
Contributor

@pendo324 pendo324 commented Oct 4, 2023

Picking up where #1826 left off

According to these docs, Windows runners should have Git for Windows pre-installed, meaning tar.exe and gzip.exe should be in the path already.

Let's see if just changing the rootfs from zstd to gz compression gets us any further, and iterate from there.

Closes #1781.

@AkihiroSuda AkihiroSuda added this to the v0.18.0 milestone Oct 4, 2023
@pendo324
Copy link
Contributor Author

pendo324 commented Oct 4, 2023

See a weird Forbidden (403). error, from wsl --update I think? Going to retry it in a few minutes to see if its a network issue

@pendo324
Copy link
Contributor Author

pendo324 commented Oct 4, 2023

Well, I found out why the error wasn't being logged, fixed in 88ce268.

The wsl command (or subcommand wslpath command) was returning an error that implemented ExitCode(), which caused the final logrus.Fatal to never get executed.

I also added some quotes to wrap the input of the temp file path when calling wslpath.

Now it seems like the output of wslpath is just... wrong for some reason, outputting:

time="2023-10-04T23:45:50Z" level=info msg="[hostagent] limaBootFilePathOnLinux: \"C:UsersRUNNER~1AppDataLocalTemplima-wsl2-boot-36860512[26](https://github.com/lima-vm/lima/actions/runs/6412733028/job/17410508491?pr=1883#step:8:27).sh\"\n"

From my local testing, double backslashes seem to work. Adding a change to convert \ to \\

@balajiv113
Copy link
Member

In WSL2, all folders are shared under C drive ??

I could see script is under C:/Users/RUNNER~1/AppData/Local/Temp/ and userhome under C:\\\\Users\\\\runneradmin\\\\.lima\\\\wsl2

@pendo324
Copy link
Contributor Author

pendo324 commented Oct 6, 2023

In WSL2, all folders are shared under C drive ??

I could see script is under C:/Users/RUNNER~1/AppData/Local/Temp/ and userhome under C:\\\\Users\\\\runneradmin\\\\.lima\\\\wsl2

Yeah, the entire C drive is shared by default.

I'm pretty sure the files exist, but the wslpath call isn't returning the right output. I'm going to try to debug it on my local windows machine as to not waste resources. Just running the expected command (wsl.exe -d <distro> wslpath -u "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\lima-wsl2-boot-2835403810.sh") does work and outputs a valid WSL path for me on my machine in a PowerShell terminal, so I'm not sure why its not working here.

@balajiv113
Copy link
Member

If this still doesn't work, we can compute the wslpath ourself (/mnt prefix and slashes changed accordingly)
There might already be a go library as well to do this.

I hope this should surely work without these glitches

@jandubois
Copy link
Member

I don't understand why this is necessary:

bootFileWSLPath := strconv.Quote(limaBootFilePathOnWindows)

Isn't exec.Command() already taking care of the quoting? So you would now pass in a double quoted string?

we can compute the wslpath ourself.

You can't really, in general, as even the mount prefix is configurable.

@pendo324
Copy link
Contributor Author

pendo324 commented Oct 6, 2023

I don't understand why this is necessary:

bootFileWSLPath := strconv.Quote(limaBootFilePathOnWindows)

Isn't exec.Command() already taking care of the quoting? So you would now pass in a double quoted string?

I used it to convert the slashes from \ to \\ and add the quote around the path string, in case it has a space in it. It seems like wslpath expects \\ path separators, at least on certain versions of WSL.

From my testing, the command only works as intended when going through bash -c. I'd be lying if I said I understood exactly why this is the case 🤷‍♂️, but it seems to at least output a reasonable path now, so yay (if anyone has an explanation, I'm very interested).

Seems like WSL still might have an issue with the ~ in the path from the looks of it. Seems like that's from an "8.3" or "short" filename, looking in to how to convert that to the "long" filename to see if that helps

The short file name in question is the user directory:
C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\lima-wsl2-boot-3366004968.sh, which does at least get "properly" converted to /mnt/c/Users/RUNNER~1/AppData/Local/Temp/lima-wsl2-boot-3366004968.sh by wslpath now when checking the run logs.

@jandubois
Copy link
Member

looking in to how to convert that to the "long" filename

I think the short names should just work, even from WSL.

You can convert them with PowerShell, but that has a high startup cost. But if you only do it once, then it doesn't matter:

C:\>powershell "(Get-Item -LiteralPath 'C:\PROGRA~1').FullName"
C:\Program Files

@jandubois
Copy link
Member

I'd be lying if I said I understood exactly why this is the case

The problem is that Windows doesn't have the concept of passing *argv[] to a new process; all you get is a single char*. So every app (or runtime) implements their own commandline parsing and argument quoting rules. It is all a big mess.

command.exec() has to smash the arguments together on its own, quoting them in a way that most programs will be able to parse again. But it is all based on heuristics.

@pendo324
Copy link
Contributor Author

pendo324 commented Oct 7, 2023

We have liftoff :)

@pendo324
Copy link
Contributor Author

pendo324 commented Oct 7, 2023

looking in to how to convert that to the "long" filename

I think the short names should just work, even from WSL.

You can convert them with PowerShell, but that has a high startup cost. But if you only do it once, then it doesn't matter:

C:\>powershell "(Get-Item -LiteralPath 'C:\PROGRA~1').FullName"
C:\Program Files

Yeah you're right, the short path actually does work with wslpath. I added the code to convert to a regular "long path", using syscalls instead of PowerShell, but I'll probably remove it before merging unless there's a good reason to keep it

@AkihiroSuda
Copy link
Member

Seems green now 💚

Please rebase, add back macOS CI, and ping me when this is ready to merge

@AkihiroSuda AkihiroSuda marked this pull request as draft October 7, 2023 23:16
@pendo324 pendo324 force-pushed the wsl2-ci branch 2 times, most recently from 1359538 to 914a5ac Compare October 9, 2023 17:49
@pendo324
Copy link
Contributor Author

pendo324 commented Oct 9, 2023

@AkihiroSuda, I think it's good now. Let me know if you want me to make any more changes

# otherwise `wsl --list --verbose` (called from Lima) fails:
# https://github.com/lima-vm/lima/pull/1826#issuecomment-1729993334
# The distro image itself is not consumed by Lima.
# ------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

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

I’d like to see this resolved. Can be another PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll keep looking into this separately. Maybe there's something we can do with conditionally calling wsl --import / wsl --install based on the status returned from wsl --list -v

@@ -378,6 +380,7 @@ func (a *HostAgent) Run(ctx context.Context) error {
}()
return a.driver.RunGUI()
}
logrus.Infof("Running startRoutinesAndWait")
Copy link
Member

Choose a reason for hiding this comment

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

Should be Debugf, or just removed

// WSL instance SSH address isn't known until after VM start
if *a.y.VMType == limayaml.WSL2 {
sshAddr, err := store.GetSSHAddress(a.instName)
logrus.Infof("sshAddress: %s", sshAddr)
Copy link
Member

Choose a reason for hiding this comment

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

Debugf or remove

@@ -316,9 +316,11 @@ func (a *HostAgent) Run(ctx context.Context) error {
return err
}

logrus.Infof("After driver.Start()")
Copy link
Member

Choose a reason for hiding this comment

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

Debugf or remove

Signed-off-by: Akihiro Suda <[email protected]>
Signed-off-by: Justin Alvarez <[email protected]>

Co-authored-by: Akihiro Suda <[email protected]>
@AkihiroSuda AkihiroSuda marked this pull request as ready for review October 9, 2023 21:30
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks 💚

@AkihiroSuda AkihiroSuda merged commit 7493e1d into lima-vm:master Oct 9, 2023
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.

CI: test WSL2
4 participants