-
Notifications
You must be signed in to change notification settings - Fork 2
/
step_fetch_box.go
60 lines (47 loc) · 1.25 KB
/
step_fetch_box.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"context"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/helper/multistep"
)
type StepFetchBox struct {
URL string
Name string
Version string
Provider string
BoxFile string
BuilderConfig map[string]interface{}
}
func (s *StepFetchBox) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
err := s.doRun(state)
if err != nil {
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
return multistep.ActionContinue
}
func (s *StepFetchBox) doRun(state multistep.StateBag) error {
ui := state.Get("ui").(packer.Ui)
ui.Message("(vagrant) Builder source_path ...")
if sourcePath, ok := s.BuilderConfig["source_path"]; ok {
ui.Message(fmt.Sprintf("(vagrant) Builder source_path: %s", sourcePath))
state.Put("source_path", sourcePath)
return nil
}
v, err := NewVagrant(ui)
if err != nil {
return err
}
sourcePath, err := v.fetchBoxFile(s.URL, s.Name, s.Version, s.Provider, s.BoxFile)
if err != nil {
return err
}
ui.Message(fmt.Sprintf("(vagrant) Builder source_path: %s", sourcePath))
state.Put("source_path", sourcePath)
return nil
}
func (s *StepFetchBox) Cleanup(state multistep.StateBag) {
}