Merge pull request #713 from mlaventure/windows-runtime

Windows Pty and CloseStdin
This commit is contained in:
Michael Crosby
2017-04-12 11:36:54 -07:00
committed by GitHub
13 changed files with 662 additions and 537 deletions

View File

@@ -5,11 +5,8 @@ import (
"encoding/json"
"fmt"
"os"
"os/signal"
"runtime"
"golang.org/x/sys/unix"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
@@ -196,39 +193,3 @@ var runCommand = cli.Command{
return nil
},
}
func handleConsoleResize(ctx gocontext.Context, service execution.ContainerServiceClient, id string, pid uint32, con console.Console) error {
// do an initial resize of the console
size, err := con.Size()
if err != nil {
return err
}
if _, err := service.Pty(ctx, &execution.PtyRequest{
ID: id,
Pid: pid,
Width: uint32(size.Width),
Height: uint32(size.Height),
}); err != nil {
return err
}
s := make(chan os.Signal, 16)
signal.Notify(s, unix.SIGWINCH)
go func() {
for range s {
size, err := con.Size()
if err != nil {
logrus.WithError(err).Error("get pty size")
continue
}
if _, err := service.Pty(ctx, &execution.PtyRequest{
ID: id,
Pid: pid,
Width: uint32(size.Width),
Height: uint32(size.Height),
}); err != nil {
logrus.WithError(err).Error("resize pty")
}
}
}()
return nil
}

View File

@@ -3,16 +3,22 @@
package main
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/signal"
"path/filepath"
"runtime"
"strconv"
"strings"
"golang.org/x/sys/unix"
"github.com/Sirupsen/logrus"
"github.com/containerd/containerd/api/services/execution"
"github.com/crosbymichael/console"
protobuf "github.com/gogo/protobuf/types"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
specs "github.com/opencontainers/runtime-spec/specs-go"
@@ -262,3 +268,39 @@ func newCreateRequest(context *cli.Context, imageConfig *ocispec.ImageConfig, id
return create, nil
}
func handleConsoleResize(ctx context.Context, service execution.ContainerServiceClient, id string, pid uint32, con console.Console) error {
// do an initial resize of the console
size, err := con.Size()
if err != nil {
return err
}
if _, err := service.Pty(ctx, &execution.PtyRequest{
ID: id,
Pid: pid,
Width: uint32(size.Width),
Height: uint32(size.Height),
}); err != nil {
return err
}
s := make(chan os.Signal, 16)
signal.Notify(s, unix.SIGWINCH)
go func() {
for range s {
size, err := con.Size()
if err != nil {
logrus.WithError(err).Error("get pty size")
continue
}
if _, err := service.Pty(ctx, &execution.PtyRequest{
ID: id,
Pid: pid,
Width: uint32(size.Width),
Height: uint32(size.Height),
}); err != nil {
logrus.WithError(err).Error("resize pty")
}
}
}()
return nil
}

View File

@@ -1,15 +1,19 @@
package main
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"runtime"
"time"
"github.com/Sirupsen/logrus"
"github.com/containerd/containerd/api/services/execution"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/windows"
"github.com/containerd/containerd/windows/hcs"
"github.com/crosbymichael/console"
protobuf "github.com/gogo/protobuf/types"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
specs "github.com/opencontainers/runtime-spec/specs-go"
@@ -42,6 +46,19 @@ func spec(id string, config *ocispec.ImageConfig, context *cli.Context) *specs.S
cwd = `C:\`
}
// Some sane defaults for console
w := 80
h := 20
if tty {
con := console.Current()
size, err := con.Size()
if err == nil {
w = int(size.Width)
h = int(size.Height)
}
}
return &specs.Spec{
Version: specs.Version,
Platform: specs.Platform{
@@ -60,8 +77,8 @@ func spec(id string, config *ocispec.ImageConfig, context *cli.Context) *specs.S
Username: config.User,
},
ConsoleSize: specs.Box{
Height: 20,
Width: 80,
Height: uint(w),
Width: uint(h),
},
},
Hostname: id,
@@ -135,3 +152,36 @@ func newCreateRequest(context *cli.Context, imageConfig *ocispec.ImageConfig, id
return create, nil
}
func handleConsoleResize(ctx context.Context, service execution.ContainerServiceClient, id string, pid uint32, con console.Console) error {
// do an initial resize of the console
size, err := con.Size()
if err != nil {
return err
}
go func() {
prevSize := size
for {
time.Sleep(time.Millisecond * 250)
size, err := con.Size()
if err != nil {
log.G(ctx).WithError(err).Error("get pty size")
continue
}
if size.Width != prevSize.Width || size.Height != prevSize.Height {
if _, err := service.Pty(ctx, &execution.PtyRequest{
ID: id,
Pid: pid,
Width: uint32(size.Width),
Height: uint32(size.Height),
}); err != nil {
log.G(ctx).WithError(err).Error("resize pty")
}
prevSize = size
}
}
}()
return nil
}