[lxd] cleanup and tweaks
This commit is contained in:
parent
3a0ef7b8b8
commit
c62f9a0301
|
@ -43,9 +43,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
}
|
}
|
||||||
|
|
||||||
steps := []multistep.Step{
|
steps := []multistep.Step{
|
||||||
new(stepLxdLaunch),
|
&stepLxdLaunch{},
|
||||||
new(StepProvision),
|
&StepProvision{},
|
||||||
new(stepPublish),
|
&stepPublish{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the state bag
|
// Setup the state bag
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
|
|
||||||
func testConfig() map[string]interface{} {
|
func testConfig() map[string]interface{} {
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"output_dir": "foo",
|
"output_image": "foo",
|
||||||
"image": "bar",
|
"image": "bar",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,7 @@ type Config struct {
|
||||||
CommandWrapper string `mapstructure:"command_wrapper"`
|
CommandWrapper string `mapstructure:"command_wrapper"`
|
||||||
RawInitTimeout string `mapstructure:"init_timeout"`
|
RawInitTimeout string `mapstructure:"init_timeout"`
|
||||||
Image string `mapstructure:"image"`
|
Image string `mapstructure:"image"`
|
||||||
Remote string `mapstructure:"remote"`
|
|
||||||
//EnvVars []string `mapstructure:"template_environment_vars"`
|
//EnvVars []string `mapstructure:"template_environment_vars"`
|
||||||
//TargetRunlevel int `mapstructure:"target_runlevel"`
|
|
||||||
InitTimeout time.Duration
|
InitTimeout time.Duration
|
||||||
|
|
||||||
ctx interpolate.Context
|
ctx interpolate.Context
|
||||||
|
|
|
@ -19,17 +19,10 @@ func (s *stepLxdLaunch) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
|
||||||
name := config.ContainerName
|
name := config.ContainerName
|
||||||
image := config.Image
|
image := config.Image
|
||||||
remote := config.Remote
|
|
||||||
|
|
||||||
commands := make([][]string, 1)
|
commands := [][]string{
|
||||||
if remote == "" {
|
{"lxc", "launch", image, name},
|
||||||
commands[0] = []string{"lxc", "launch", image, name}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
commands[0] = []string{"lxc", "launch", fmt.Sprintf("%s:%s", remote, 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...")
|
ui.Say("Creating container...")
|
||||||
for _, command := range commands {
|
for _, command := range commands {
|
||||||
|
@ -42,7 +35,9 @@ func (s *stepLxdLaunch) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
return multistep.ActionHalt
|
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
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,21 +18,16 @@ func (s *stepPublish) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
|
||||||
name := config.ContainerName
|
name := config.ContainerName
|
||||||
|
|
||||||
//outputPath := filepath.Join(config.OutputDir, "rootfs.tar.gz")
|
commands := [][]string{
|
||||||
|
{"lxc", "stop", "--force", name},
|
||||||
commands := make([][]string, 2)
|
{"lxc", "publish", name, "--alias", config.OutputImage},
|
||||||
commands[0] = []string{
|
|
||||||
"lxc", "stop", "--force", name,
|
|
||||||
}
|
|
||||||
commands[1] = []string{
|
|
||||||
"lxc", "publish", name,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Say("Publishing container...")
|
ui.Say("Publishing container...")
|
||||||
for _, command := range commands {
|
for _, command := range commands {
|
||||||
err := s.SudoCommand(command...)
|
err := s.SudoCommand(command...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error exporting container: %s", err)
|
err := fmt.Errorf("Error publishing container: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
|
Loading…
Reference in New Issue