Merge pull request #8498 from hashicorp/f-builder_docker-typeassertion-check
builder/docker: Fix interface conversion issue when getting config from state bag
This commit is contained in:
commit
a72242cd70
|
@ -77,7 +77,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
|
||||||
|
|
||||||
// Setup the state bag and initial state for the steps
|
// Setup the state bag and initial state for the steps
|
||||||
state := new(multistep.BasicStateBag)
|
state := new(multistep.BasicStateBag)
|
||||||
state.Put("config", b.config)
|
state.Put("config", &b.config)
|
||||||
state.Put("hook", hook)
|
state.Put("hook", hook)
|
||||||
state.Put("ui", ui)
|
state.Put("ui", ui)
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,17 @@ type StepCommit struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepCommit) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepCommit) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
config, ok := state.Get("config").(*Config)
|
||||||
|
if !ok {
|
||||||
|
err := fmt.Errorf("error encountered obtaining docker config")
|
||||||
|
state.Put("error", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
driver := state.Get("driver").(Driver)
|
driver := state.Get("driver").(Driver)
|
||||||
containerId := state.Get("container_id").(string)
|
containerId := state.Get("container_id").(string)
|
||||||
config := state.Get("config").(*Config)
|
|
||||||
ui := state.Get("ui").(packer.Ui)
|
|
||||||
|
|
||||||
if config.WindowsContainer {
|
if config.WindowsContainer {
|
||||||
// docker can't commit a running Windows container
|
// docker can't commit a running Windows container
|
||||||
err := driver.StopContainer(containerId)
|
err := driver.StopContainer(containerId)
|
||||||
|
|
|
@ -12,7 +12,13 @@ import (
|
||||||
type StepConnectDocker struct{}
|
type StepConnectDocker struct{}
|
||||||
|
|
||||||
func (s *StepConnectDocker) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepConnectDocker) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
config := state.Get("config").(*Config)
|
config, ok := state.Get("config").(*Config)
|
||||||
|
if !ok {
|
||||||
|
err := fmt.Errorf("error encountered obtaining docker config")
|
||||||
|
state.Put("error", err)
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
containerId := state.Get("container_id").(string)
|
containerId := state.Get("container_id").(string)
|
||||||
driver := state.Get("driver").(Driver)
|
driver := state.Get("driver").(Driver)
|
||||||
tempDir := state.Get("temp_dir").(string)
|
tempDir := state.Get("temp_dir").(string)
|
||||||
|
|
|
@ -14,11 +14,14 @@ import (
|
||||||
type StepExport struct{}
|
type StepExport struct{}
|
||||||
|
|
||||||
func (s *StepExport) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepExport) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
config := state.Get("config").(*Config)
|
|
||||||
|
|
||||||
driver := state.Get("driver").(Driver)
|
|
||||||
containerId := state.Get("container_id").(string)
|
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
config, ok := state.Get("config").(*Config)
|
||||||
|
if !ok {
|
||||||
|
err := fmt.Errorf("error encountered obtaining docker config")
|
||||||
|
state.Put("error", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
// We should catch this in validation, but guard anyway
|
// We should catch this in validation, but guard anyway
|
||||||
if config.ExportPath == "" {
|
if config.ExportPath == "" {
|
||||||
|
@ -44,6 +47,9 @@ func (s *StepExport) Run(ctx context.Context, state multistep.StateBag) multiste
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
driver := state.Get("driver").(Driver)
|
||||||
|
containerId := state.Get("container_id").(string)
|
||||||
|
|
||||||
ui.Say("Exporting the container")
|
ui.Say("Exporting the container")
|
||||||
if err := driver.Export(containerId, f); err != nil {
|
if err := driver.Export(containerId, f); err != nil {
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
|
@ -12,9 +12,14 @@ import (
|
||||||
type StepPull struct{}
|
type StepPull struct{}
|
||||||
|
|
||||||
func (s *StepPull) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepPull) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
config := state.Get("config").(*Config)
|
|
||||||
driver := state.Get("driver").(Driver)
|
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
config, ok := state.Get("config").(*Config)
|
||||||
|
if !ok {
|
||||||
|
err := fmt.Errorf("error encountered obtaining docker config")
|
||||||
|
state.Put("error", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
if !config.Pull {
|
if !config.Pull {
|
||||||
log.Println("Pull disabled, won't docker pull")
|
log.Println("Pull disabled, won't docker pull")
|
||||||
|
@ -38,6 +43,7 @@ func (s *StepPull) Run(ctx context.Context, state multistep.StateBag) multistep.
|
||||||
config.LoginPassword = password
|
config.LoginPassword = password
|
||||||
}
|
}
|
||||||
|
|
||||||
|
driver := state.Get("driver").(Driver)
|
||||||
if config.Login || config.EcrLogin {
|
if config.Login || config.EcrLogin {
|
||||||
ui.Message("Logging in...")
|
ui.Message("Logging in...")
|
||||||
err := driver.Login(
|
err := driver.Login(
|
||||||
|
|
|
@ -13,10 +13,14 @@ type StepRun struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepRun) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepRun) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
config := state.Get("config").(*Config)
|
|
||||||
driver := state.Get("driver").(Driver)
|
|
||||||
tempDir := state.Get("temp_dir").(string)
|
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
config, ok := state.Get("config").(*Config)
|
||||||
|
if !ok {
|
||||||
|
err := fmt.Errorf("error encountered obtaining docker config")
|
||||||
|
state.Put("error", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
runConfig := ContainerConfig{
|
runConfig := ContainerConfig{
|
||||||
Image: config.Image,
|
Image: config.Image,
|
||||||
|
@ -28,8 +32,11 @@ func (s *StepRun) Run(ctx context.Context, state multistep.StateBag) multistep.S
|
||||||
for host, container := range config.Volumes {
|
for host, container := range config.Volumes {
|
||||||
runConfig.Volumes[host] = container
|
runConfig.Volumes[host] = container
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tempDir := state.Get("temp_dir").(string)
|
||||||
runConfig.Volumes[tempDir] = config.ContainerDir
|
runConfig.Volumes[tempDir] = config.ContainerDir
|
||||||
|
|
||||||
|
driver := state.Get("driver").(Driver)
|
||||||
ui.Say("Starting docker container...")
|
ui.Say("Starting docker container...")
|
||||||
containerId, err := driver.StartContainer(&runConfig)
|
containerId, err := driver.StartContainer(&runConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue