From e3ab74e09f9f5b73a5efa046b4b8498487a9cdf5 Mon Sep 17 00:00:00 2001 From: georgevicbell Date: Thu, 16 Jul 2015 21:06:03 -0400 Subject: [PATCH 1/7] Add Config struct for docker PTY --- builder/docker/communicator.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/builder/docker/communicator.go b/builder/docker/communicator.go index 6fedf2769..56ea3b1d3 100644 --- a/builder/docker/communicator.go +++ b/builder/docker/communicator.go @@ -24,10 +24,14 @@ type Communicator struct { HostDir string ContainerDir string Version *version.Version - + config *Config lock sync.Mutex } +type Config struct { + // Pty, if true, will request a pty from docker with -t + Pty bool +} func (c *Communicator) Start(remote *packer.RemoteCmd) error { // Create a temporary file to store the output. Because of a bug in // Docker, sometimes all the output doesn't properly show up. This @@ -45,7 +49,11 @@ func (c *Communicator) Start(remote *packer.RemoteCmd) error { var cmd *exec.Cmd if c.canExec() { - cmd = exec.Command("docker", "exec", "-i", c.ContainerId, "/bin/sh") + if c.config.Pty { + cmd = exec.Command("docker", "exec", "-i", "-t", c.ContainerId, "/bin/sh") + } else { + cmd = exec.Command("docker", "exec", "-i", c.ContainerId, "/bin/sh") + } } else { cmd = exec.Command("docker", "attach", c.ContainerId) } From fb39fa2cc6d3f9ae8ea9e3d205d3beed155d9400 Mon Sep 17 00:00:00 2001 From: georgevicbell Date: Thu, 16 Jul 2015 21:13:04 -0400 Subject: [PATCH 2/7] Update step_connect_docker.go --- builder/docker/step_connect_docker.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builder/docker/step_connect_docker.go b/builder/docker/step_connect_docker.go index 31f2ea2e4..da2be51af 100644 --- a/builder/docker/step_connect_docker.go +++ b/builder/docker/step_connect_docker.go @@ -7,6 +7,7 @@ import ( type StepConnectDocker struct{} func (s *StepConnectDocker) Run(state multistep.StateBag) multistep.StepAction { + config := state.Get("config").(Config) containerId := state.Get("container_id").(string) driver := state.Get("driver").(Driver) tempDir := state.Get("temp_dir").(string) @@ -25,6 +26,7 @@ func (s *StepConnectDocker) Run(state multistep.StateBag) multistep.StepAction { HostDir: tempDir, ContainerDir: "/packer-files", Version: version, + Config: config, } state.Put("communicator", comm) From 3a681d0c0c0eb8d4b5c00f87cfc39d1dc9b4ee07 Mon Sep 17 00:00:00 2001 From: georgevicbell Date: Thu, 16 Jul 2015 21:22:11 -0400 Subject: [PATCH 3/7] Add Pty Bool --- builder/docker/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/docker/config.go b/builder/docker/config.go index af5f25fec..03b9dbfb0 100644 --- a/builder/docker/config.go +++ b/builder/docker/config.go @@ -28,7 +28,7 @@ type Config struct { LoginUsername string `mapstructure:"login_username"` LoginPassword string `mapstructure:"login_password"` LoginServer string `mapstructure:"login_server"` - + Pty bool ctx interpolate.Context } From 4da4150abe51b67687e5bdf9b6e5d1797aa60eed Mon Sep 17 00:00:00 2001 From: georgevicbell Date: Thu, 16 Jul 2015 21:37:08 -0400 Subject: [PATCH 4/7] Update communicator.go --- builder/docker/communicator.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/builder/docker/communicator.go b/builder/docker/communicator.go index 56ea3b1d3..3d495463f 100644 --- a/builder/docker/communicator.go +++ b/builder/docker/communicator.go @@ -28,10 +28,6 @@ type Communicator struct { lock sync.Mutex } -type Config struct { - // Pty, if true, will request a pty from docker with -t - Pty bool -} func (c *Communicator) Start(remote *packer.RemoteCmd) error { // Create a temporary file to store the output. Because of a bug in // Docker, sometimes all the output doesn't properly show up. This From d00271aab382fad79d7a85b9cf3e6bb5a6eeb9b8 Mon Sep 17 00:00:00 2001 From: georgevicbell Date: Thu, 16 Jul 2015 21:50:24 -0400 Subject: [PATCH 5/7] Fix Capitilzation --- builder/docker/communicator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/docker/communicator.go b/builder/docker/communicator.go index 3d495463f..c07cc2f70 100644 --- a/builder/docker/communicator.go +++ b/builder/docker/communicator.go @@ -24,7 +24,7 @@ type Communicator struct { HostDir string ContainerDir string Version *version.Version - config *Config + Config *Config lock sync.Mutex } From b2811a8252a1e69bc064da38811a1cb92771c7a5 Mon Sep 17 00:00:00 2001 From: georgevicbell Date: Thu, 16 Jul 2015 21:51:13 -0400 Subject: [PATCH 6/7] Update communicator.go --- builder/docker/communicator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/docker/communicator.go b/builder/docker/communicator.go index c07cc2f70..63ef4cd5b 100644 --- a/builder/docker/communicator.go +++ b/builder/docker/communicator.go @@ -45,7 +45,7 @@ func (c *Communicator) Start(remote *packer.RemoteCmd) error { var cmd *exec.Cmd if c.canExec() { - if c.config.Pty { + if c.Config.Pty { cmd = exec.Command("docker", "exec", "-i", "-t", c.ContainerId, "/bin/sh") } else { cmd = exec.Command("docker", "exec", "-i", c.ContainerId, "/bin/sh") From bf0c326cd5f88111f9b1b7736ccf469ccb46ebe0 Mon Sep 17 00:00:00 2001 From: georgevicbell Date: Thu, 16 Jul 2015 22:07:39 -0400 Subject: [PATCH 7/7] Update step_connect_docker.go --- builder/docker/step_connect_docker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/docker/step_connect_docker.go b/builder/docker/step_connect_docker.go index da2be51af..315cfc204 100644 --- a/builder/docker/step_connect_docker.go +++ b/builder/docker/step_connect_docker.go @@ -7,7 +7,7 @@ import ( type StepConnectDocker struct{} func (s *StepConnectDocker) Run(state multistep.StateBag) multistep.StepAction { - config := state.Get("config").(Config) + config := state.Get("config").(*Config) containerId := state.Get("container_id").(string) driver := state.Get("driver").(Driver) tempDir := state.Get("temp_dir").(string)