packer-cn/builder/vagrant/artifact.go

58 lines
1.3 KiB
Go
Raw Normal View History

2019-01-11 17:06:15 -05:00
package vagrant
import (
"fmt"
"path/filepath"
2020-12-17 16:29:25 -05:00
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
2019-01-11 17:06:15 -05:00
)
// This is the common builder ID to all of these artifacts.
const BuilderId = "vagrant"
// Artifact is the result of running the vagrant builder, namely a set
// of files associated with the resulting machine.
type artifact struct {
OutputDir string
BoxName string
Provider string
// StateData should store data such as GeneratedData
// to be shared with post-processors
StateData map[string]interface{}
2019-01-11 17:06:15 -05:00
}
// NewArtifact returns a vagrant artifact containing the .box file
func NewArtifact(provider, dir string, generatedData map[string]interface{}) packersdk.Artifact {
2019-01-11 17:06:15 -05:00
return &artifact{
OutputDir: dir,
BoxName: "package.box",
Provider: provider,
StateData: generatedData,
}
2019-01-11 17:06:15 -05:00
}
func (*artifact) BuilderId() string {
return BuilderId
}
func (a *artifact) Files() []string {
return []string{filepath.Join(a.OutputDir, a.BoxName)}
2019-01-11 17:06:15 -05:00
}
func (a *artifact) Id() string {
return a.Provider
2019-01-11 17:06:15 -05:00
}
func (a *artifact) String() string {
return fmt.Sprintf("Vagrant box '%s' for '%s' provider", a.BoxName, a.Provider)
2019-01-11 17:06:15 -05:00
}
func (a *artifact) State(name string) interface{} {
return a.StateData[name]
2019-01-11 17:06:15 -05:00
}
func (a *artifact) Destroy() error {
return nil
}