diff options
Diffstat (limited to 'vendor/github.com/mitchellh/packer/builder/lxd/step_publish.go')
-rw-r--r-- | vendor/github.com/mitchellh/packer/builder/lxd/step_publish.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/github.com/mitchellh/packer/builder/lxd/step_publish.go b/vendor/github.com/mitchellh/packer/builder/lxd/step_publish.go new file mode 100644 index 00000000..0c0aabd3 --- /dev/null +++ b/vendor/github.com/mitchellh/packer/builder/lxd/step_publish.go @@ -0,0 +1,54 @@ +package lxd + +import ( + "fmt" + "github.com/hashicorp/packer/packer" + "github.com/mitchellh/multistep" + "regexp" +) + +type stepPublish struct{} + +func (s *stepPublish) Run(state multistep.StateBag) multistep.StepAction { + config := state.Get("config").(*Config) + ui := state.Get("ui").(packer.Ui) + + name := config.ContainerName + stop_args := []string{ + // We created the container with "--ephemeral=false" so we know it is safe to stop. + "stop", name, + } + + ui.Say("Stopping container...") + _, err := LXDCommand(stop_args...) + if err != nil { + 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...") + stdoutString, err := LXDCommand(publish_args...) + if err != nil { + err := fmt.Errorf("Error publishing container: %s", err) + state.Put("error", err) + ui.Error(err.Error()) + return multistep.ActionHalt + } + + r := regexp.MustCompile("([0-9a-fA-F]+)$") + fingerprint := r.FindAllStringSubmatch(stdoutString, -1)[0][0] + + ui.Say(fmt.Sprintf("Created image: %s", fingerprint)) + + state.Put("imageFingerprint", fingerprint) + + return multistep.ActionContinue +} + +func (s *stepPublish) Cleanup(state multistep.StateBag) {} |