mirror of
https://github.com/containers/podman.git
synced 2025-07-03 17:27:18 +08:00
Merge pull request #22062 from n1hility/wsl-5x-image-pull
Switch to 5.x WSL machine os stream using new automation
This commit is contained in:
@ -12,12 +12,12 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containers/podman/v5/pkg/machine"
|
||||
"github.com/containers/podman/v5/version"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
githubX86ReleaseURL = "https://github.com/containers/podman-wsl-fedora/releases/latest/download/rootfs.tar.xz"
|
||||
githubArmReleaseURL = "https://github.com/containers/podman-wsl-fedora-arm/releases/latest/download/rootfs.tar.xz"
|
||||
latestReleaseURL = "https://github.com/containers/podman-machine-wsl-os/releases/latest/download"
|
||||
)
|
||||
|
||||
type FedoraDownload struct {
|
||||
@ -46,23 +46,20 @@ func (f FedoraDownload) CleanCache() error {
|
||||
}
|
||||
|
||||
func GetFedoraDownloadForWSL() (*url.URL, string, string, int64, error) {
|
||||
var releaseURL string
|
||||
arch := machine.DetermineMachineArch()
|
||||
switch arch {
|
||||
case "arm64":
|
||||
releaseURL = githubArmReleaseURL
|
||||
case "amd64":
|
||||
releaseURL = githubX86ReleaseURL
|
||||
default:
|
||||
if arch != "amd64" && arch != "arm64" {
|
||||
return nil, "", "", -1, fmt.Errorf("CPU architecture %q is not supported", arch)
|
||||
}
|
||||
|
||||
downloadURL, err := url.Parse(releaseURL)
|
||||
releaseURL, err := url.Parse(latestReleaseURL)
|
||||
if err != nil {
|
||||
return nil, "", "", -1, fmt.Errorf("invalid URL generated from discovered Fedora file: %s: %w", releaseURL, err)
|
||||
return nil, "", "", -1, fmt.Errorf("could not parse release URL: %s: %w", releaseURL, err)
|
||||
}
|
||||
|
||||
resp, err := http.Head(releaseURL)
|
||||
rootFs := fmt.Sprintf("%d.%d-rootfs-%s.tar.zst", version.Version.Major, version.Version.Minor, arch)
|
||||
rootFsURL := appendToURL(releaseURL, rootFs)
|
||||
|
||||
resp, err := http.Head(rootFsURL.String())
|
||||
if err != nil {
|
||||
return nil, "", "", -1, fmt.Errorf("head request failed: %s: %w", releaseURL, err)
|
||||
}
|
||||
@ -70,12 +67,10 @@ func GetFedoraDownloadForWSL() (*url.URL, string, string, int64, error) {
|
||||
contentLen := resp.ContentLength
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, "", "", -1, fmt.Errorf("head request failed: %s: %w", releaseURL, err)
|
||||
return nil, "", "", -1, fmt.Errorf("head request failed: %s: %w", rootFsURL, err)
|
||||
}
|
||||
|
||||
verURL := *downloadURL
|
||||
verURL.Path = path.Join(path.Dir(downloadURL.Path), "version")
|
||||
|
||||
verURL := appendToURL(releaseURL, "version")
|
||||
resp, err = http.Get(verURL.String())
|
||||
if err != nil {
|
||||
return nil, "", "", -1, fmt.Errorf("get request failed: %s: %w", verURL.String(), err)
|
||||
@ -90,5 +85,11 @@ func GetFedoraDownloadForWSL() (*url.URL, string, string, int64, error) {
|
||||
if err != nil {
|
||||
return nil, "", "", -1, fmt.Errorf("failed reading: %s: %w", verURL.String(), err)
|
||||
}
|
||||
return downloadURL, strings.TrimSpace(string(b)), arch, contentLen, nil
|
||||
return rootFsURL, strings.TrimSpace(string(b)), arch, contentLen, nil
|
||||
}
|
||||
|
||||
func appendToURL(url *url.URL, elem string) *url.URL {
|
||||
newURL := *url
|
||||
newURL.Path = path.Join(url.Path, elem)
|
||||
return &newURL
|
||||
}
|
||||
|
@ -103,6 +103,14 @@ func provisionWSLDist(name string, imagePath string, prompt string) (string, err
|
||||
return "", fmt.Errorf("package permissions restore of shadow-utils on guest OS failed: %w", err)
|
||||
}
|
||||
|
||||
if err = wslInvoke(dist, "mkdir", "-p", "/usr/local/bin"); err != nil {
|
||||
return "", fmt.Errorf("could not create /usr/local/bin: %w", err)
|
||||
}
|
||||
|
||||
if err = wslInvoke(dist, "ln", "-f", "-s", gvForwarderPath, "/usr/local/bin/vm"); err != nil {
|
||||
return "", fmt.Errorf("could not setup compatibility link: %w", err)
|
||||
}
|
||||
|
||||
return dist, nil
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const gvForwarderPath = "/usr/libexec/podman/gvforwarder"
|
||||
|
||||
const startUserModeNet = `
|
||||
set -e
|
||||
STATE=/mnt/wsl/podman-usermodenet
|
||||
@ -30,10 +32,10 @@ fi
|
||||
if [[ ! $ROUTE =~ default\ via ]]; then
|
||||
exit 3
|
||||
fi
|
||||
nohup /usr/local/bin/vm -iface podman-usermode -stop-if-exist ignore -url "stdio:$GVPROXY?listen-stdio=accept" > /var/log/vm.log 2> /var/log/vm.err < /dev/null &
|
||||
nohup $GVFORWARDER -iface podman-usermode -stop-if-exist ignore -url "stdio:$GVPROXY?listen-stdio=accept" > /var/log/vm.log 2> /var/log/vm.err < /dev/null &
|
||||
echo $! > $STATE/vm.pid
|
||||
sleep 1
|
||||
ps -eo args | grep -q -m1 ^/usr/local/bin/vm || exit 42
|
||||
ps -eo args | grep -q -m1 ^$GVFORWARDER || exit 42
|
||||
`
|
||||
|
||||
const stopUserModeNet = `
|
||||
@ -162,7 +164,8 @@ func stopUserModeNetworking(mc *vmconfigs.MachineConfig) error {
|
||||
}
|
||||
|
||||
func isGvProxyVMRunning() bool {
|
||||
return wslInvoke(userModeDist, "bash", "-c", "ps -eo args | grep -q -m1 ^/usr/local/bin/vm || exit 42") == nil
|
||||
cmd := fmt.Sprintf("ps -eo args | grep -q -m1 ^%s || exit 42", gvForwarderPath)
|
||||
return wslInvoke(userModeDist, "bash", "-c", cmd) == nil
|
||||
}
|
||||
|
||||
func launchUserModeNetDist(exeFile string) error {
|
||||
@ -173,7 +176,7 @@ func launchUserModeNetDist(exeFile string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
cmdStr := fmt.Sprintf("GVPROXY=%q\n%s", exe, startUserModeNet)
|
||||
cmdStr := fmt.Sprintf("GVPROXY=%q\nGVFORWARDER=%q\n%s", exe, gvForwarderPath, startUserModeNet)
|
||||
if err := wslPipe(cmdStr, userModeDist, "bash"); err != nil {
|
||||
_ = terminateDist(userModeDist)
|
||||
|
||||
@ -202,8 +205,19 @@ func installUserModeDist(dist string, imagePath string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if exists {
|
||||
if err := wslInvoke(userModeDist, "test", "-f", gvForwarderPath); err != nil {
|
||||
fmt.Println("Replacing old user-mode distribution...")
|
||||
_ = terminateDist(userModeDist)
|
||||
if err := unregisterDist(userModeDist); err != nil {
|
||||
return err
|
||||
}
|
||||
exists = false
|
||||
}
|
||||
}
|
||||
|
||||
if !exists {
|
||||
if err := wslInvoke(dist, "test", "-f", "/usr/local/bin/vm"); err != nil {
|
||||
if err := wslInvoke(dist, "test", "-f", gvForwarderPath); err != nil {
|
||||
return fmt.Errorf("existing machine is too old, can't install user-mode networking dist until machine is reinstalled (using podman machine rm, then podman machine init)")
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user