[lxd] cleanup and tweaks

This commit is contained in:
Chris Lundquist 2016-05-30 23:57:26 +00:00 committed by Megan Marsh
parent 3a0ef7b8b8
commit c62f9a0301
5 changed files with 14 additions and 26 deletions

View File

@ -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

View File

@ -9,8 +9,8 @@ import (
func testConfig() map[string]interface{} {
return map[string]interface{}{
"output_dir": "foo",
"image": "bar",
"output_image": "foo",
"image": "bar",
}
}

View File

@ -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

View File

@ -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 <container>` 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
}

View File

@ -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