From 848985b2001d1bb3fc8feefa2fea02141da2f98d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 19 Jun 2013 21:12:11 -0700 Subject: [PATCH] builder/virtualbox: proper artifact [GH-23] --- builder/virtualbox/artifact.go | 33 +++++++++++++++++++++++++++++++++ builder/virtualbox/builder.go | 22 +++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 builder/virtualbox/artifact.go diff --git a/builder/virtualbox/artifact.go b/builder/virtualbox/artifact.go new file mode 100644 index 000000000..831e2f3d4 --- /dev/null +++ b/builder/virtualbox/artifact.go @@ -0,0 +1,33 @@ +package virtualbox + +import ( + "fmt" + "os" +) + +// Artifact is the result of running the VirtualBox builder, namely a set +// of files associated with the resulting machine. +type Artifact struct { + dir string + f []string +} + +func (*Artifact) BuilderId() string { + return BuilderId +} + +func (a *Artifact) Files() []string { + return a.f +} + +func (*Artifact) Id() string { + return "VM" +} + +func (a *Artifact) String() string { + return fmt.Sprintf("VM files in directory: %s", a.dir) +} + +func (a *Artifact) Destroy() error { + return os.RemoveAll(a.dir) +} diff --git a/builder/virtualbox/builder.go b/builder/virtualbox/builder.go index fdd30db95..d692a93ae 100644 --- a/builder/virtualbox/builder.go +++ b/builder/virtualbox/builder.go @@ -11,6 +11,7 @@ import ( "net/url" "os" "os/exec" + "path/filepath" "strings" "time" ) @@ -231,7 +232,26 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe return nil, rawErr.(error) } - return nil, nil + // Compile the artifact list + files := make([]string, 0, 5) + visit := func(path string, info os.FileInfo, err error) error { + if !info.IsDir() { + files = append(files, path) + } + + return err + } + + if err := filepath.Walk(b.config.OutputDir, visit); err != nil { + return nil, err + } + + artifact := &Artifact{ + dir: b.config.OutputDir, + f: files, + } + + return artifact, nil } func (b *Builder) Cancel() {