Get terminal setting from spec
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
db2f72620f
commit
94d807aec4
1 changed files with 28 additions and 12 deletions
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -15,6 +16,7 @@ import (
|
||||||
"github.com/docker/containerd/api/grpc/types"
|
"github.com/docker/containerd/api/grpc/types"
|
||||||
"github.com/docker/docker/pkg/term"
|
"github.com/docker/docker/pkg/term"
|
||||||
"github.com/opencontainers/runc/libcontainer"
|
"github.com/opencontainers/runc/libcontainer"
|
||||||
|
"github.com/opencontainers/specs"
|
||||||
netcontext "golang.org/x/net/context"
|
netcontext "golang.org/x/net/context"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
@ -79,13 +81,9 @@ var StartCommand = cli.Command{
|
||||||
Usage: "checkpoint to start the container from",
|
Usage: "checkpoint to start the container from",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "interactive,i",
|
Name: "attach,a",
|
||||||
Usage: "connect to the stdio of the container",
|
Usage: "connect to the stdio of the container",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
|
||||||
Name: "tty,t",
|
|
||||||
Usage: "allocate a tty for use with the container",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) {
|
Action: func(context *cli.Context) {
|
||||||
var (
|
var (
|
||||||
|
@ -108,20 +106,25 @@ var StartCommand = cli.Command{
|
||||||
BundlePath: path,
|
BundlePath: path,
|
||||||
Checkpoint: context.String("checkpoint"),
|
Checkpoint: context.String("checkpoint"),
|
||||||
}
|
}
|
||||||
if context.Bool("interactive") {
|
if context.Bool("attach") {
|
||||||
|
mkterm, err := readTermSetting(path)
|
||||||
|
if err != nil {
|
||||||
|
fatal(err.Error(), 1)
|
||||||
|
}
|
||||||
|
if mkterm {
|
||||||
|
if err := attachTty(r); err != nil {
|
||||||
|
fatal(err.Error(), 1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if err := attachStdio(r); err != nil {
|
if err := attachStdio(r); err != nil {
|
||||||
fatal(err.Error(), 1)
|
fatal(err.Error(), 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if context.Bool("tty") {
|
|
||||||
if err := attachTty(r); err != nil {
|
|
||||||
fatal(err.Error(), 1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if _, err := c.CreateContainer(netcontext.Background(), r); err != nil {
|
if _, err := c.CreateContainer(netcontext.Background(), r); err != nil {
|
||||||
fatal(err.Error(), 1)
|
fatal(err.Error(), 1)
|
||||||
}
|
}
|
||||||
if stdin != nil {
|
if context.Bool("attach") {
|
||||||
go func() {
|
go func() {
|
||||||
io.Copy(stdin, os.Stdin)
|
io.Copy(stdin, os.Stdin)
|
||||||
if state != nil {
|
if state != nil {
|
||||||
|
@ -146,6 +149,19 @@ var (
|
||||||
state *term.State
|
state *term.State
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func readTermSetting(path string) (bool, error) {
|
||||||
|
f, err := os.Open(filepath.Join(path, "config.json"))
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
var spec specs.Spec
|
||||||
|
if err := json.NewDecoder(f).Decode(&spec); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return spec.Process.Terminal, nil
|
||||||
|
}
|
||||||
|
|
||||||
func attachTty(r *types.CreateContainerRequest) error {
|
func attachTty(r *types.CreateContainerRequest) error {
|
||||||
console, err := libcontainer.NewConsole(os.Getuid(), os.Getgid())
|
console, err := libcontainer.NewConsole(os.Getuid(), os.Getgid())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue