Merge pull request #67 from github/jg/output-formats
add back . indicators & update ConnectToTunnel
This commit is contained in:
commit
6dd0bf8e5e
2 changed files with 17 additions and 7 deletions
|
|
@ -65,14 +65,16 @@ func SSH(sshProfile, codespaceName string, sshServerPort int) error {
|
|||
|
||||
log.Println("Preparing SSH...")
|
||||
if sshProfile == "" {
|
||||
containerID, err := getContainerID(ctx, terminal)
|
||||
containerID, err := getContainerID(ctx, log, terminal)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting container id: %v", err)
|
||||
}
|
||||
|
||||
if err := setupSSH(ctx, terminal, containerID, codespace.RepositoryName); err != nil {
|
||||
if err := setupSSH(ctx, log, terminal, containerID, codespace.RepositoryName); err != nil {
|
||||
return fmt.Errorf("error creating ssh server: %v", err)
|
||||
}
|
||||
|
||||
log.Print("\n")
|
||||
}
|
||||
|
||||
tunnelPort, tunnelClosed, err := codespaces.MakeSSHTunnel(ctx, lsclient, sshServerPort)
|
||||
|
|
@ -86,7 +88,7 @@ func SSH(sshProfile, codespaceName string, sshServerPort int) error {
|
|||
}
|
||||
|
||||
usingCustomPort := tunnelPort == sshServerPort
|
||||
connClosed := codespaces.ConnectToTunnel(ctx, tunnelPort, connectDestination, usingCustomPort)
|
||||
connClosed := codespaces.ConnectToTunnel(ctx, log, tunnelPort, connectDestination, usingCustomPort)
|
||||
|
||||
log.Println("Ready...")
|
||||
select {
|
||||
|
|
@ -103,24 +105,30 @@ func SSH(sshProfile, codespaceName string, sshServerPort int) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func getContainerID(ctx context.Context, terminal *liveshare.Terminal) (string, error) {
|
||||
func getContainerID(ctx context.Context, logger *output.Logger, terminal *liveshare.Terminal) (string, error) {
|
||||
logger.Print(".")
|
||||
|
||||
cmd := terminal.NewCommand(
|
||||
"/",
|
||||
"/usr/bin/docker ps -aq --filter label=Type=codespaces --filter status=running",
|
||||
)
|
||||
|
||||
stream, err := cmd.Run(ctx)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error running command: %v", err)
|
||||
}
|
||||
|
||||
logger.Print(".")
|
||||
scanner := bufio.NewScanner(stream)
|
||||
scanner.Scan()
|
||||
|
||||
logger.Print(".")
|
||||
containerID := scanner.Text()
|
||||
if err := scanner.Err(); err != nil {
|
||||
return "", fmt.Errorf("error scanning stream: %v", err)
|
||||
}
|
||||
|
||||
logger.Print(".")
|
||||
if err := stream.Close(); err != nil {
|
||||
return "", fmt.Errorf("error closing stream: %v", err)
|
||||
}
|
||||
|
|
@ -128,9 +136,10 @@ func getContainerID(ctx context.Context, terminal *liveshare.Terminal) (string,
|
|||
return containerID, nil
|
||||
}
|
||||
|
||||
func setupSSH(ctx context.Context, terminal *liveshare.Terminal, containerID, repositoryName string) error {
|
||||
func setupSSH(ctx context.Context, logger *output.Logger, terminal *liveshare.Terminal, containerID, repositoryName string) error {
|
||||
setupBashProfileCmd := fmt.Sprintf(`echo "cd /workspaces/%v; export $(cat /workspaces/.codespaces/shared/.env | xargs); exec /bin/zsh;" > /home/codespace/.bash_profile`, repositoryName)
|
||||
|
||||
logger.Print(".")
|
||||
compositeCommand := []string{setupBashProfileCmd}
|
||||
cmd := terminal.NewCommand(
|
||||
"/",
|
||||
|
|
@ -141,6 +150,7 @@ func setupSSH(ctx context.Context, terminal *liveshare.Terminal, containerID, re
|
|||
return fmt.Errorf("error running command: %v", err)
|
||||
}
|
||||
|
||||
logger.Print(".")
|
||||
if err := stream.Close(); err != nil {
|
||||
return fmt.Errorf("error closing stream: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,12 +56,12 @@ func makeSSHArgs(port int, dst, cmd string) ([]string, []string) {
|
|||
return cmdArgs, connArgs
|
||||
}
|
||||
|
||||
func ConnectToTunnel(ctx context.Context, port int, destination string, usingCustomPort bool) <-chan error {
|
||||
func ConnectToTunnel(ctx context.Context, log logger, port int, destination string, usingCustomPort bool) <-chan error {
|
||||
connClosed := make(chan error)
|
||||
args, connArgs := makeSSHArgs(port, destination, "")
|
||||
|
||||
if usingCustomPort {
|
||||
fmt.Println("Connection Details: ssh " + destination + " " + strings.Join(connArgs, " "))
|
||||
log.Println("Connection Details: ssh " + destination + " " + strings.Join(connArgs, " "))
|
||||
}
|
||||
|
||||
cmd := exec.CommandContext(ctx, "ssh", args...)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue