[lxd] avoid extra container start/stop and race
Before we couldn't be sure if we were a permanent container or not. Now we explicitly pass this on the command line so we don't depend on the extra logic in `lxc publish --force` for ephemeral handling. This means we avoid restarting the container after we publish since we tear it down right away anyhow. Likewise, there was sometimes a race which prevented the deletion while the container was in a boot stage.
This commit is contained in:
parent
e29f06fe1c
commit
68bb72380a
|
@ -17,7 +17,7 @@ func (s *stepLxdLaunch) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
image := config.Image
|
image := config.Image
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"launch", image, name,
|
"launch", "--ephemeral=false", image, name,
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Say("Creating container...")
|
ui.Say("Creating container...")
|
||||||
|
|
|
@ -14,15 +14,26 @@ func (s *stepPublish) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
name := config.ContainerName
|
name := config.ContainerName
|
||||||
|
stop_args := []string{
|
||||||
|
// We created the container with "--ephemeral=false" so we know it is safe to stop.
|
||||||
|
"stop", name,
|
||||||
|
}
|
||||||
|
|
||||||
args := []string{
|
ui.Say("Stopping container...")
|
||||||
// If we use `lxc stop <container>`, an ephemeral container would die forever.
|
_, err := LXDCommand(stop_args...)
|
||||||
// `lxc publish` has special logic to handle this case.
|
if err != nil {
|
||||||
"publish", "--force", name, "--alias", config.OutputImage,
|
err := fmt.Errorf("Error stopping container: %s", err)
|
||||||
|
state.Put("error", err)
|
||||||
|
ui.Error(err.Error())
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
|
publish_args := []string{
|
||||||
|
"publish", name, "--alias", config.OutputImage,
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Say("Publishing container...")
|
ui.Say("Publishing container...")
|
||||||
stdoutString, err := LXDCommand(args...)
|
stdoutString, err := LXDCommand(publish_args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error publishing container: %s", err)
|
err := fmt.Errorf("Error publishing container: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
|
Loading…
Reference in New Issue