2019-01-11 17:06:15 -05:00
|
|
|
package vagrant
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
|
2020-11-19 15:17:11 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/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
|
2019-03-11 23:21:59 -04:00
|
|
|
Provider string
|
2020-01-30 05:27:58 -05:00
|
|
|
|
|
|
|
// 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
|
2020-11-19 15:17:11 -05:00
|
|
|
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",
|
2019-03-11 23:21:59 -04:00
|
|
|
Provider: provider,
|
2020-01-30 05:27:58 -05:00
|
|
|
StateData: generatedData,
|
2019-03-11 23:21:59 -04:00
|
|
|
}
|
2019-01-11 17:06:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (*artifact) BuilderId() string {
|
|
|
|
return BuilderId
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *artifact) Files() []string {
|
2019-03-11 23:21:59 -04:00
|
|
|
return []string{filepath.Join(a.OutputDir, a.BoxName)}
|
2019-01-11 17:06:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *artifact) Id() string {
|
2019-03-11 23:21:59 -04:00
|
|
|
return a.Provider
|
2019-01-11 17:06:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *artifact) String() string {
|
2019-03-11 23:21:59 -04:00
|
|
|
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{} {
|
2020-01-30 05:27:58 -05:00
|
|
|
return a.StateData[name]
|
2019-01-11 17:06:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *artifact) Destroy() error {
|
|
|
|
return nil
|
|
|
|
}
|