(ctx devspacecontext.Context, name, arch string, sshConfig *latest.SSH, selector targetselector.TargetSelector, parent *tomb.Tomb)
| 54 | } |
| 55 | |
| 56 | func startSSH(ctx devspacecontext.Context, name, arch string, sshConfig *latest.SSH, selector targetselector.TargetSelector, parent *tomb.Tomb) error { |
| 57 | if ctx.IsDone() { |
| 58 | return nil |
| 59 | } |
| 60 | |
| 61 | // configure ssh host |
| 62 | sshHost := name + "." + ctx.Config().Config().Name + ".devspace" |
| 63 | if sshConfig.LocalHostname != "" { |
| 64 | sshHost = sshConfig.LocalHostname |
| 65 | } |
| 66 | |
| 67 | // try to find host port |
| 68 | homeDir, err := homedir.Dir() |
| 69 | if err != nil { |
| 70 | return errors.Wrap(err, "get home dir") |
| 71 | } |
| 72 | |
| 73 | // get port |
| 74 | port := sshConfig.LocalPort |
| 75 | if port == 0 { |
| 76 | sshDevSpaceConfigPath := filepath.Join(homeDir, ".ssh", "config") |
| 77 | if sshConfig.UseInclude { |
| 78 | sshDevSpaceConfigPath = filepath.Join(homeDir, ".ssh", "devspace_config") |
| 79 | } |
| 80 | hosts, err := ParseDevSpaceHosts(sshDevSpaceConfigPath) |
| 81 | if err != nil { |
| 82 | ctx.Log().Debugf("error parsing %s: %v", sshDevSpaceConfigPath, err) |
| 83 | } else { |
| 84 | for _, h := range hosts { |
| 85 | if h.Host == sshHost { |
| 86 | port = h.Port |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | if port == 0 { |
| 92 | port, err = GetInstance(ctx.Log()).LockPort() |
| 93 | if err != nil { |
| 94 | return errors.Wrap(err, "find port") |
| 95 | } |
| 96 | |
| 97 | // update ssh config |
| 98 | err = configureSSHConfig(sshHost, strconv.Itoa(port), sshConfig.UseInclude, ctx.Log()) |
| 99 | if err != nil { |
| 100 | return errors.Wrap(err, "update ssh config") |
| 101 | } |
| 102 | } |
| 103 | } else { |
| 104 | err = GetInstance(ctx.Log()).LockSpecificPort(port) |
| 105 | if err != nil { |
| 106 | return errors.Wrap(err, "find port") |
| 107 | } |
| 108 | |
| 109 | // update ssh config |
| 110 | err = configureSSHConfig(sshHost, strconv.Itoa(port), sshConfig.UseInclude, ctx.Log()) |
| 111 | if err != nil { |
| 112 | return errors.Wrap(err, "update ssh config") |
| 113 | } |
no test coverage detected