Skip to content

Commit

Permalink
ssh: fix regression when layer is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
abiosoft committed Oct 4, 2023
1 parent 1c890c5 commit 4744827
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
10 changes: 4 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,13 @@ func (c colimaApp) SSH(layer bool, args ...string) error {
return c.guest.RunInteractive(args...)
}

cmdArgs := resp.Output

if len(args) > 0 {
args = append([]string{"-q", "-t", "-F", resp.File, "--"}, args...)
args = append([]string{"-q", "-t", config.CurrentProfile().ID, "--"}, args...)
} else if workDir != "" {
args = []string{"-q", "-t", "-F", resp.File, resp.IPAddress, "--", "cd " + workDir + " 2> /dev/null; \"$SHELL\" --login"}
args = []string{"-q", "-t", config.CurrentProfile().ID, "--", "cd " + workDir + " 2> /dev/null; \"$SHELL\" --login"}
}

args = append(util.ShellSplit(cmdArgs), args...)
args = append([]string{"-F", resp.File.Colima}, args...)
return cli.CommandInteractive("ssh", args...).Run()
}

Expand Down Expand Up @@ -498,7 +496,7 @@ func generateSSHConfig(modifySSHConfig bool) error {
fmt.Fprintln(&buf, resp.Output)
}

sshFileColima := filepath.Join(filepath.Dir(config.Dir()), "ssh_config")
sshFileColima := config.SSHConfigFile()
if err := os.WriteFile(sshFileColima, buf.Bytes(), 0644); err != nil {
return fmt.Errorf("error writing ssh_config file: %w", err)
}
Expand Down
3 changes: 3 additions & 0 deletions config/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,6 @@ func WrapperDir() string { return wrapperDir.Dir() }
const ConfigFileName = "colima.yaml"

func configFile() string { return filepath.Join(configDir.Dir(), ConfigFileName) }

// SSHConfigFile returns the path to generated ssh config.
func SSHConfigFile() string { return filepath.Join(filepath.Dir(configDir.Dir()), "ssh_config") }
8 changes: 6 additions & 2 deletions environment/vm/lima/limautil/limautil.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ func ShowSSH(profileID string, layer bool) (resp struct {
Output string
IPAddress string
Layer bool
File string
File struct {
Lima string
Colima string
}
}, err error) {
ssh := sshConfig(profileID)
sshConf, err := ssh.Contents()
Expand All @@ -110,7 +113,8 @@ func ShowSSH(profileID string, layer bool) (resp struct {
resp.Output = replaceSSHConfig(sshConf, profileID, ip, port)
resp.IPAddress = ip
resp.Layer = port > 0
resp.File = ssh.File()
resp.File.Lima = ssh.File()
resp.File.Colima = config.SSHConfigFile()
return resp, nil
}

Expand Down

0 comments on commit 4744827

Please sign in to comment.