Merge branch 'main' of https://github.com/github/ghcs
This commit is contained in:
commit
cbbfafee98
2 changed files with 34 additions and 16 deletions
|
|
@ -11,7 +11,6 @@ import (
|
|||
"github.com/github/ghcs/internal/codespaces"
|
||||
"github.com/github/go-liveshare"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func newLogsCmd() *cobra.Command {
|
||||
|
|
@ -85,12 +84,25 @@ func logs(ctx context.Context, tail bool, codespaceName string) error {
|
|||
ctx, localPort, dst, fmt.Sprintf("%s /workspaces/.codespaces/.persistedshare/creation.log", cmdType),
|
||||
)
|
||||
|
||||
group, ctx := errgroup.WithContext(ctx)
|
||||
group.Go(func() error {
|
||||
tunnelClosed := make(chan error, 1)
|
||||
go func() {
|
||||
fwd := liveshare.NewPortForwarder(session, "sshd", remoteSSHServerPort)
|
||||
err := fwd.ForwardToListener(ctx, listen) // error is non-nil
|
||||
tunnelClosed <- fwd.ForwardToListener(ctx, listen) // error is non-nil
|
||||
}()
|
||||
|
||||
cmdDone := make(chan error, 1)
|
||||
go func() {
|
||||
cmdDone <- cmd.Run()
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-tunnelClosed:
|
||||
return fmt.Errorf("connection closed: %v", err)
|
||||
})
|
||||
group.Go(cmd.Run)
|
||||
return group.Wait()
|
||||
case err := <-cmdDone:
|
||||
if err != nil {
|
||||
return fmt.Errorf("error retrieving logs: %v", err)
|
||||
}
|
||||
|
||||
return nil // success
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import (
|
|||
"github.com/github/ghcs/internal/codespaces"
|
||||
"github.com/github/go-liveshare"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func newSSHCmd() *cobra.Command {
|
||||
|
|
@ -99,19 +98,26 @@ func ssh(ctx context.Context, sshProfile, codespaceName string, localSSHServerPo
|
|||
}
|
||||
|
||||
log.Println("Ready...")
|
||||
group, ctx := errgroup.WithContext(ctx)
|
||||
group.Go(func() error {
|
||||
tunnelClosed := make(chan error, 1)
|
||||
go func() {
|
||||
fwd := liveshare.NewPortForwarder(session, "sshd", remoteSSHServerPort)
|
||||
err := fwd.ForwardToListener(ctx, listen) // always non-nil
|
||||
tunnelClosed <- fwd.ForwardToListener(ctx, listen) // always non-nil
|
||||
}()
|
||||
|
||||
shellClosed := make(chan error, 1)
|
||||
go func() {
|
||||
shellClosed <- codespaces.Shell(ctx, log, localSSHServerPort, connectDestination, usingCustomPort)
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-tunnelClosed:
|
||||
return fmt.Errorf("tunnel closed: %v", err)
|
||||
})
|
||||
group.Go(func() error {
|
||||
if err := codespaces.Shell(ctx, log, localSSHServerPort, connectDestination, usingCustomPort); err != nil {
|
||||
case err := <-shellClosed:
|
||||
if err != nil {
|
||||
return fmt.Errorf("shell closed: %v", err)
|
||||
}
|
||||
return nil // success
|
||||
})
|
||||
return group.Wait()
|
||||
}
|
||||
}
|
||||
|
||||
func getContainerID(ctx context.Context, logger *output.Logger, terminal *liveshare.Terminal) (string, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue