diff --git a/builder/lxd/builder.go b/builder/lxd/builder.go index 735ca48e8..d43f6d1e0 100644 --- a/builder/lxd/builder.go +++ b/builder/lxd/builder.go @@ -43,9 +43,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe } steps := []multistep.Step{ - new(stepLxdLaunch), - new(StepProvision), - new(stepPublish), + &stepLxdLaunch{}, + &StepProvision{}, + &stepPublish{}, } // Setup the state bag diff --git a/builder/lxd/builder_test.go b/builder/lxd/builder_test.go index f08c18449..b84dd70d6 100644 --- a/builder/lxd/builder_test.go +++ b/builder/lxd/builder_test.go @@ -9,8 +9,8 @@ import ( func testConfig() map[string]interface{} { return map[string]interface{}{ - "output_dir": "foo", - "image": "bar", + "output_image": "foo", + "image": "bar", } } diff --git a/builder/lxd/config.go b/builder/lxd/config.go index bcd8dfe83..c2201943e 100644 --- a/builder/lxd/config.go +++ b/builder/lxd/config.go @@ -18,9 +18,7 @@ type Config struct { CommandWrapper string `mapstructure:"command_wrapper"` RawInitTimeout string `mapstructure:"init_timeout"` Image string `mapstructure:"image"` - Remote string `mapstructure:"remote"` //EnvVars []string `mapstructure:"template_environment_vars"` - //TargetRunlevel int `mapstructure:"target_runlevel"` InitTimeout time.Duration ctx interpolate.Context diff --git a/builder/lxd/step_lxd_launch.go b/builder/lxd/step_lxd_launch.go index c42218170..44a52b0b9 100644 --- a/builder/lxd/step_lxd_launch.go +++ b/builder/lxd/step_lxd_launch.go @@ -19,17 +19,10 @@ func (s *stepLxdLaunch) Run(state multistep.StateBag) multistep.StepAction { name := config.ContainerName image := config.Image - remote := config.Remote - commands := make([][]string, 1) - if remote == "" { - commands[0] = []string{"lxc", "launch", image, name} - } else { - - commands[0] = []string{"lxc", "launch", fmt.Sprintf("%s:%s", remote, image), name} + commands := [][]string{ + {"lxc", "launch", image, name}, } - //commands[0] = append(commands[0], config.Parameters...) - // todo: wait for init to finish before moving on to provisioning instead of this ui.Say("Creating container...") for _, command := range commands { @@ -42,7 +35,9 @@ func (s *stepLxdLaunch) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionHalt } } - time.Sleep(2 * time.Second) + // TODO: Should we check `lxc info ` for "Running"? + // We have to do this so /tmp doens't get cleared and lose our provisioner scripts. + time.Sleep(1 * time.Second) return multistep.ActionContinue } diff --git a/builder/lxd/step_publish.go b/builder/lxd/step_publish.go index 16224d3df..ccebcecdb 100644 --- a/builder/lxd/step_publish.go +++ b/builder/lxd/step_publish.go @@ -18,21 +18,16 @@ func (s *stepPublish) Run(state multistep.StateBag) multistep.StepAction { name := config.ContainerName - //outputPath := filepath.Join(config.OutputDir, "rootfs.tar.gz") - - commands := make([][]string, 2) - commands[0] = []string{ - "lxc", "stop", "--force", name, - } - commands[1] = []string{ - "lxc", "publish", name, + commands := [][]string{ + {"lxc", "stop", "--force", name}, + {"lxc", "publish", name, "--alias", config.OutputImage}, } ui.Say("Publishing container...") for _, command := range commands { err := s.SudoCommand(command...) if err != nil { - err := fmt.Errorf("Error exporting container: %s", err) + err := fmt.Errorf("Error publishing container: %s", err) state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt