diff --git a/app/app.go b/app/app.go index b2497661d..582c846ab 100644 --- a/app/app.go +++ b/app/app.go @@ -216,24 +216,25 @@ func (c colimaApp) SSH(layer bool, args ...string) error { return c.guest.RunInteractive(args...) } - cmdArgs, layer, err := lima.ShowSSH(config.CurrentProfile().ID, layer, "args") + resp, err := lima.ShowSSH(config.CurrentProfile().ID, layer, "args") if err != nil { return fmt.Errorf("error getting ssh config: %w", err) } - - if !layer { + if !resp.Layer { return c.guest.RunInteractive(args...) } + cmdArgs := resp.Output + wd, err := os.Getwd() if err != nil { log.Debug(fmt.Errorf("cannot get working dir: %w", err)) } if len(args) > 0 { - args = append([]string{"-q", "-t", "127.0.0.1", "--"}, args...) + args = append([]string{"-q", "-t", resp.IPAddress, "--"}, args...) } else if wd != "" { - args = []string{"-q", "-t", "127.0.0.1", "--", "cd " + wd + " 2> /dev/null; bash --login"} + args = []string{"-q", "-t", resp.IPAddress, "--", "cd " + wd + " 2> /dev/null; bash --login"} } args = append(strings.Fields(cmdArgs), args...) @@ -255,6 +256,9 @@ func (c colimaApp) Status() error { log.Println(config.CurrentProfile().DisplayName, "is running") log.Println("arch:", c.guest.Arch()) log.Println("runtime:", currentRuntime) + if conf, err := lima.InstanceConfig(); err == nil { + log.Println("mountType:", conf.MountType) + } if currentRuntime == docker.Name { log.Println("socket:", "unix://"+docker.HostSocketFile()) } diff --git a/cmd/ssh-config.go b/cmd/ssh-config.go index 03f6cf0ef..9c7bdb808 100644 --- a/cmd/ssh-config.go +++ b/cmd/ssh-config.go @@ -16,9 +16,9 @@ var sshConfigCmd = &cobra.Command{ Long: `Show configuration of the SSH connection to the VM.`, Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - out, _, err := lima.ShowSSH(config.CurrentProfile().ID, sshConfigCmdArgs.layer, sshConfigCmdArgs.format) + resp, err := lima.ShowSSH(config.CurrentProfile().ID, sshConfigCmdArgs.layer, sshConfigCmdArgs.format) if err == nil { - fmt.Println(out) + fmt.Println(resp.Output) } return err }, diff --git a/environment/container/docker/context.go b/environment/container/docker/context.go index 3710178ed..47f46edb2 100644 --- a/environment/container/docker/context.go +++ b/environment/container/docker/context.go @@ -1,7 +1,6 @@ package docker import ( - "fmt" "path/filepath" "github.com/abiosoft/colima/config" @@ -14,8 +13,7 @@ func LegacyDefaultHostSocketFile() string { } func (d dockerRuntime) isContextCreated() bool { - command := fmt.Sprintf(`docker context ls -q | grep "^%s$"`, config.CurrentProfile().ID) - return d.host.RunQuiet("sh", "-c", command) == nil + return d.host.RunQuiet("docker", "context", "inspect", config.CurrentProfile().ID) == nil } func (d dockerRuntime) setupContext() error { diff --git a/environment/container/kubernetes/k3s.go b/environment/container/kubernetes/k3s.go index f3ac27c1d..11f75bb2d 100644 --- a/environment/container/kubernetes/k3s.go +++ b/environment/container/kubernetes/k3s.go @@ -81,7 +81,7 @@ func installK3sCache( case containerd.Name: a.Stage("loading oci images") a.Add(func() error { - if err := guest.Run("sudo", "ctr", "-n", "k8s.io", "images", "import", downloadPathTar); err != nil { + if err := guest.Run("sudo", "ctr", "-n", "k8s.io", "images", "import", "--all-platforms", downloadPathTar); err != nil { log.Warnln(fmt.Errorf("error loading oci images: %w", err)) log.Warnln("startup may delay a bit as images will be pulled from oci registry") } diff --git a/environment/vm/lima/cmds.go b/environment/vm/lima/cmds.go index c944fc54b..556f83627 100644 --- a/environment/vm/lima/cmds.go +++ b/environment/vm/lima/cmds.go @@ -190,7 +190,8 @@ func getRuntime(conf config.Config) string { } // IPAddress returns the ip address for profile. -// It returns the PTP address if networking is enabled or falls back to 127.0.0.1 +// It returns the PTP address if networking is enabled or falls back to 127.0.0.1. +// It is guaranteed to return a value. // TODO: unnecessary round-trip is done to get instance details from Lima. func IPAddress(profileID string) string { // profile = toUserFriendlyName(profile) @@ -210,14 +211,18 @@ func IPAddress(profileID string) string { // ShowSSH runs the show-ssh command in Lima. // returns the ssh output, if in layer, and an error if any -func ShowSSH(profileID string, layer bool, format string) (string, bool, error) { +func ShowSSH(profileID string, layer bool, format string) (resp struct { + Output string + IPAddress string + Layer bool +}, err error) { var buf bytes.Buffer cmd := cli.Command("limactl", "show-ssh", "--format", format, profileID) cmd.Stdout = &buf cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { - return "", false, fmt.Errorf("error retrieving ssh config: %w", err) + return resp, fmt.Errorf("error retrieving ssh config: %w", err) } ip := IPAddress(profileID) @@ -239,10 +244,13 @@ func ShowSSH(profileID string, layer bool, format string) (string, bool, error) case "cmd", "args": out = replaceSSHCmd(out, profileID, ip, port) default: - return "", false, fmt.Errorf("unsupported format '%v'", format) + return resp, fmt.Errorf("unsupported format '%v'", format) } - return out, port > 0, nil + resp.Output = out + resp.IPAddress = ip + resp.Layer = port > 0 + return resp, nil } func replaceSSHCmd(cmd string, name string, ip string, port int) string {