github.com/mitchellh/packer@v1.3.2/builder/null/builder.go (about) 1 package null 2 3 import ( 4 "log" 5 6 "github.com/hashicorp/packer/common" 7 "github.com/hashicorp/packer/helper/communicator" 8 "github.com/hashicorp/packer/helper/multistep" 9 "github.com/hashicorp/packer/packer" 10 ) 11 12 const BuilderId = "fnoeding.null" 13 14 type Builder struct { 15 config *Config 16 runner multistep.Runner 17 } 18 19 func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { 20 c, warnings, errs := NewConfig(raws...) 21 if errs != nil { 22 return warnings, errs 23 } 24 b.config = c 25 26 return warnings, nil 27 } 28 29 func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { 30 steps := []multistep.Step{} 31 32 if b.config.CommConfig.Type != "none" { 33 steps = append(steps, 34 &communicator.StepConnect{ 35 Config: &b.config.CommConfig, 36 Host: CommHost(b.config.CommConfig.Host()), 37 SSHConfig: b.config.CommConfig.SSHConfigFunc(), 38 }, 39 ) 40 } 41 42 steps = append(steps, 43 new(common.StepProvision), 44 ) 45 46 // Setup the state bag and initial state for the steps 47 state := new(multistep.BasicStateBag) 48 state.Put("config", b.config) 49 state.Put("hook", hook) 50 state.Put("ui", ui) 51 52 // Run! 53 b.runner = common.NewRunner(steps, b.config.PackerConfig, ui) 54 b.runner.Run(state) 55 56 // If there was an error, return that 57 if rawErr, ok := state.GetOk("error"); ok { 58 return nil, rawErr.(error) 59 } 60 61 // No errors, must've worked 62 artifact := &NullArtifact{} 63 return artifact, nil 64 } 65 66 func (b *Builder) Cancel() { 67 if b.runner != nil { 68 log.Println("Cancelling the step runner...") 69 b.runner.Cancel() 70 } 71 }