Skip to content

Commit

Permalink
fix reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
wrfly committed Jul 21, 2018
1 parent 878dcc3 commit 5a4ebf6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
5 changes: 3 additions & 2 deletions container/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewCli(conf config.DockerConfig, args []string) (*DockerCli, error) {
host = "tcp://" + host
}
version := "v1.24"
logrus.Infof("docker connecting to %s", host)
UA := map[string]string{"User-Agent": "engine-api-cli-1.0"}
cli, err := client.NewClient(host, version, nil, UA)
if err != nil {
Expand All @@ -49,13 +50,13 @@ func NewCli(conf config.DockerConfig, args []string) (*DockerCli, error) {
if err != nil {
return nil, err
}
logrus.Infof("New docker client: OS [%s], API [%s]", ping.OSType, ping.APIVersion)
logrus.Infof("new docker client: OS [%s], API [%s]", ping.OSType, ping.APIVersion)
dockerCli := &DockerCli{
cli: cli,
containers: &types.Containers{},
listOptions: listOptions,
}
logrus.Infof("Warm up containers info...")
logrus.Infof("warm up containers info...")
dockerCli.List(ctx)

return dockerCli, nil
Expand Down
43 changes: 20 additions & 23 deletions container/kube/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,23 @@ type execInjector struct {
ttyIn io.ReadCloser
ttyOut io.WriteCloser

resize resizeFunction
sq remotecommand.TerminalSizeQueue
sq *sizeQueue
}

func newInjector(ctx context.Context) execInjector {

r, out := io.Pipe()
in, w := io.Pipe()

sq := &sizeQueue{
ctx: ctx,
resizeChan: make(chan remotecommand.TerminalSize),
}
enj := execInjector{
r: r,
w: w,
ttyIn: in,
ttyOut: out,
sq: &sizeQueue{
ctx: ctx,
resizeChan: make(chan remotecommand.TerminalSize),
},
}
enj.resize = func(width int, height int) error {
defer func() {
recover()
}()
size := remotecommand.TerminalSize{
Width: uint16(width),
Height: uint16(height),
}
enj.sq.(*sizeQueue).resizeChan <- size
return nil
sq: sq,
}

return enj
Expand All @@ -63,13 +51,11 @@ func (enj *execInjector) Exit() error {
// exit the shell
enj.Write([]byte("exit\n"))

// close the size queue
enj.sq.(*sizeQueue).close()

enj.r.Close()
enj.w.Close()
enj.ttyIn.Close()
enj.ttyOut.Close()
enj.sq.close()

return nil
}
Expand All @@ -82,10 +68,10 @@ func (enj *execInjector) ResizeTerminal(width int, height int) error {
logrus.Debugf("resize terminal to: %dx%d", width, height)
var err error
for i := 0; i < 3; i++ {
if err = enj.resize(width, height); err == nil {
if err = enj.sq.resize(width, height); err == nil {
break
}
time.Sleep(time.Millisecond * 5)
time.Sleep(time.Millisecond * 50)
}
return err
}
Expand All @@ -106,3 +92,14 @@ func (s *sizeQueue) Next() *remotecommand.TerminalSize {
func (s *sizeQueue) close() {
close(s.resizeChan)
}

func (s *sizeQueue) resize(width int, height int) error {
defer func() {
recover()
}()
s.resizeChan <- remotecommand.TerminalSize{
Width: uint16(width),
Height: uint16(height),
}
return nil
}
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ services:
- 8080:8080
environment:
- WEB_TTY_DEBUG=false
- WEB_TTY_DOCKER_HOST=/var/run/docker.sock
- DOCKER_HOST=/var/run/docker.sock
# - WEB_TTY_DOCKER_HOST=/var/run/docker.sock
# both the env key is OK, first is WEB_TTY_DOCKER_HOST
# if WEB_TTY_DOCKER_HOST not found, then try to use DOCKER_HOST
volumes:
- /var/run/docker.sock:/var/run/docker.sock
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func main() {
},
&cli.StringFlag{
Name: "docker-host",
EnvVars: envVars("docker-host"),
EnvVars: append(envVars("docker-host"), "DOCKER_HOST"),
Value: "/var/run/docker.sock",
Usage: "docker host path",
Destination: &conf.Backend.Docker.DockerHost,
Expand Down

0 comments on commit 5a4ebf6

Please sign in to comment.