From ba25e68fe0fdb6de12d44f26e8908890734a0591 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 29 Nov 2018 14:32:52 -0800 Subject: [PATCH] add a new breakpoint provisioner --- command/plugin.go | 2 + provisioner/breakpoint/provisioner.go | 73 +++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 provisioner/breakpoint/provisioner.go diff --git a/command/plugin.go b/command/plugin.go index 71db5843e..d0cd68153 100644 --- a/command/plugin.go +++ b/command/plugin.go @@ -65,6 +65,7 @@ import ( vspheretemplatepostprocessor "github.com/hashicorp/packer/post-processor/vsphere-template" ansibleprovisioner "github.com/hashicorp/packer/provisioner/ansible" ansiblelocalprovisioner "github.com/hashicorp/packer/provisioner/ansible-local" + breakpointprovisioner "github.com/hashicorp/packer/provisioner/breakpoint" chefclientprovisioner "github.com/hashicorp/packer/provisioner/chef-client" chefsoloprovisioner "github.com/hashicorp/packer/provisioner/chef-solo" convergeprovisioner "github.com/hashicorp/packer/provisioner/converge" @@ -122,6 +123,7 @@ var Builders = map[string]packer.Builder{ var Provisioners = map[string]packer.Provisioner{ "ansible": new(ansibleprovisioner.Provisioner), "ansible-local": new(ansiblelocalprovisioner.Provisioner), + "breakpoint": new(breakpointprovisioner.Provisioner), "chef-client": new(chefclientprovisioner.Provisioner), "chef-solo": new(chefsoloprovisioner.Provisioner), "converge": new(convergeprovisioner.Provisioner), diff --git a/provisioner/breakpoint/provisioner.go b/provisioner/breakpoint/provisioner.go new file mode 100644 index 000000000..05428383d --- /dev/null +++ b/provisioner/breakpoint/provisioner.go @@ -0,0 +1,73 @@ +package breakpoint + +import ( + "fmt" + "log" + "os" + + "github.com/hashicorp/packer/common" + "github.com/hashicorp/packer/helper/config" + "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/template/interpolate" +) + +type Config struct { + common.PackerConfig `mapstructure:",squash"` + + // The local path of the file to upload. + Note string `mapstructure:"note"` + + ctx interpolate.Context +} + +type Provisioner struct { + config Config +} + +func (p *Provisioner) Prepare(raws ...interface{}) error { + err := config.Decode(&p.config, &config.DecodeOpts{ + Interpolate: true, + InterpolateContext: &p.config.ctx, + InterpolateFilter: &interpolate.RenderFilter{ + Exclude: []string{}, + }, + }, raws...) + if err != nil { + return err + } + + return nil +} + +func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { + if p.config.Note != "" { + ui.Say(fmt.Sprintf("Pausing at breakpoint provisioner with note \"%s\".", p.config.Note)) + } else { + ui.Say("Pausing at breakpoint provisioner.") + } + + message := fmt.Sprintf( + "Press enter to continue.") + + result := make(chan string, 1) + go func() { + line, err := ui.Ask(message) + if err != nil { + log.Printf("Error asking for input: %s", err) + } + + result <- line + }() + + select { + case <-result: + return nil + } + + return nil +} + +func (p *Provisioner) Cancel() { + // Just hard quit. + os.Exit(0) +}