Expand Artifact API to expose build state
In order that something consuming an artifact can have access to extra builder specific data add the State method which allows the caller to ask for arbitary values by name.
This commit is contained in:
parent
ee6a118090
commit
90a57c411f
|
@ -52,6 +52,10 @@ func (a *Artifact) String() string {
|
||||||
return fmt.Sprintf("AMIs were created:\n\n%s", strings.Join(amiStrings, "\n"))
|
return fmt.Sprintf("AMIs were created:\n\n%s", strings.Join(amiStrings, "\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Artifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Artifact) Destroy() error {
|
func (a *Artifact) Destroy() error {
|
||||||
errors := make([]error, 0)
|
errors := make([]error, 0)
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,10 @@ func (a *Artifact) String() string {
|
||||||
return fmt.Sprintf("A snapshot was created: '%v' in region '%v'", a.snapshotName, a.regionName)
|
return fmt.Sprintf("A snapshot was created: '%v' in region '%v'", a.snapshotName, a.regionName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Artifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Artifact) Destroy() error {
|
func (a *Artifact) Destroy() error {
|
||||||
log.Printf("Destroying image: %d (%s)", a.snapshotId, a.snapshotName)
|
log.Printf("Destroying image: %d (%s)", a.snapshotId, a.snapshotName)
|
||||||
return a.client.DestroyImage(a.snapshotId)
|
return a.client.DestroyImage(a.snapshotId)
|
||||||
|
|
|
@ -27,6 +27,10 @@ func (a *ExportArtifact) String() string {
|
||||||
return fmt.Sprintf("Exported Docker file: %s", a.path)
|
return fmt.Sprintf("Exported Docker file: %s", a.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *ExportArtifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *ExportArtifact) Destroy() error {
|
func (a *ExportArtifact) Destroy() error {
|
||||||
return os.Remove(a.path)
|
return os.Remove(a.path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,10 @@ func (a *ImportArtifact) String() string {
|
||||||
return fmt.Sprintf("Imported Docker image: %s", a.Id())
|
return fmt.Sprintf("Imported Docker image: %s", a.Id())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*ImportArtifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *ImportArtifact) Destroy() error {
|
func (a *ImportArtifact) Destroy() error {
|
||||||
return a.Driver.DeleteImage(a.Id())
|
return a.Driver.DeleteImage(a.Id())
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,3 +37,7 @@ func (a *Artifact) Id() string {
|
||||||
func (a *Artifact) String() string {
|
func (a *Artifact) String() string {
|
||||||
return fmt.Sprintf("A disk image was created: %v", a.imageName)
|
return fmt.Sprintf("A disk image was created: %v", a.imageName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Artifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -24,6 +24,10 @@ func (a *NullArtifact) String() string {
|
||||||
return fmt.Sprintf("Did not export anything. This is the null builder")
|
return fmt.Sprintf("Did not export anything. This is the null builder")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *NullArtifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *NullArtifact) Destroy() error {
|
func (a *NullArtifact) Destroy() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,10 @@ func (a *Artifact) String() string {
|
||||||
return fmt.Sprintf("An image was created: %v", a.ImageId)
|
return fmt.Sprintf("An image was created: %v", a.ImageId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Artifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Artifact) Destroy() error {
|
func (a *Artifact) Destroy() error {
|
||||||
log.Printf("Destroying image: %d", a.ImageId)
|
log.Printf("Destroying image: %d", a.ImageId)
|
||||||
return a.Conn.DeleteImageById(a.ImageId)
|
return a.Conn.DeleteImageById(a.ImageId)
|
||||||
|
|
|
@ -66,6 +66,10 @@ func (a *artifact) String() string {
|
||||||
return fmt.Sprintf("VM files in directory: %s", a.dir)
|
return fmt.Sprintf("VM files in directory: %s", a.dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *artifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *artifact) Destroy() error {
|
func (a *artifact) Destroy() error {
|
||||||
return os.RemoveAll(a.dir)
|
return os.RemoveAll(a.dir)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,10 @@ func (a *Artifact) String() string {
|
||||||
return fmt.Sprintf("VM files in directory: %s", a.dir)
|
return fmt.Sprintf("VM files in directory: %s", a.dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Artifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Artifact) Destroy() error {
|
func (a *Artifact) Destroy() error {
|
||||||
return os.RemoveAll(a.dir)
|
return os.RemoveAll(a.dir)
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,10 @@ func (a *artifact) String() string {
|
||||||
return fmt.Sprintf("VM files in directory: %s", a.dir)
|
return fmt.Sprintf("VM files in directory: %s", a.dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *artifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *artifact) Destroy() error {
|
func (a *artifact) Destroy() error {
|
||||||
return os.RemoveAll(a.dir)
|
return os.RemoveAll(a.dir)
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,10 @@ func (a *localArtifact) String() string {
|
||||||
return fmt.Sprintf("VM files in directory: %s", a.dir)
|
return fmt.Sprintf("VM files in directory: %s", a.dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *localArtifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *localArtifact) Destroy() error {
|
func (a *localArtifact) Destroy() error {
|
||||||
return os.RemoveAll(a.dir)
|
return os.RemoveAll(a.dir)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,10 @@ func (a *Artifact) String() string {
|
||||||
return fmt.Sprintf("VM files in directory: %s", a.dir)
|
return fmt.Sprintf("VM files in directory: %s", a.dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Artifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Artifact) Destroy() error {
|
func (a *Artifact) Destroy() error {
|
||||||
return a.dir.RemoveAll()
|
return a.dir.RemoveAll()
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,10 @@ type Artifact interface {
|
||||||
// This is used for UI output. It can be multiple lines.
|
// This is used for UI output. It can be multiple lines.
|
||||||
String() string
|
String() string
|
||||||
|
|
||||||
|
// State allows the caller to ask for builder specific state information
|
||||||
|
// relating to the artifact instance.
|
||||||
|
State(name string) interface{}
|
||||||
|
|
||||||
// Destroy deletes the artifact. Packer calls this for various reasons,
|
// Destroy deletes the artifact. Packer calls this for various reasons,
|
||||||
// such as if a post-processor has processed this artifact and it is
|
// such as if a post-processor has processed this artifact and it is
|
||||||
// no longer needed.
|
// no longer needed.
|
||||||
|
|
|
@ -5,6 +5,7 @@ type MockArtifact struct {
|
||||||
BuilderIdValue string
|
BuilderIdValue string
|
||||||
FilesValue []string
|
FilesValue []string
|
||||||
IdValue string
|
IdValue string
|
||||||
|
StateValues map[string]interface{}
|
||||||
DestroyCalled bool
|
DestroyCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +38,11 @@ func (*MockArtifact) String() string {
|
||||||
return "string"
|
return "string"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *MockArtifact) State(name string) interface{} {
|
||||||
|
value, _ := a.StateValues[name]
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
func (a *MockArtifact) Destroy() error {
|
func (a *MockArtifact) Destroy() error {
|
||||||
a.DestroyCalled = true
|
a.DestroyCalled = true
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -2,6 +2,7 @@ package packer
|
||||||
|
|
||||||
type TestArtifact struct {
|
type TestArtifact struct {
|
||||||
id string
|
id string
|
||||||
|
state map[string]interface{}
|
||||||
destroyCalled bool
|
destroyCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +27,11 @@ func (*TestArtifact) String() string {
|
||||||
return "string"
|
return "string"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *TestArtifact) State(name string) interface{} {
|
||||||
|
value, _ := a.state[name]
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
func (a *TestArtifact) Destroy() error {
|
func (a *TestArtifact) Destroy() error {
|
||||||
a.destroyCalled = true
|
a.destroyCalled = true
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -38,6 +38,11 @@ func (a *artifact) String() (result string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *artifact) State(name string) (result interface{}) {
|
||||||
|
a.client.Call(a.endpoint+".State", name, &result)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (a *artifact) Destroy() error {
|
func (a *artifact) Destroy() error {
|
||||||
var result error
|
var result error
|
||||||
if err := a.client.Call(a.endpoint+".Destroy", new(interface{}), &result); err != nil {
|
if err := a.client.Call(a.endpoint+".Destroy", new(interface{}), &result); err != nil {
|
||||||
|
@ -67,6 +72,11 @@ func (s *ArtifactServer) String(args *interface{}, reply *string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ArtifactServer) State(name string, reply *interface{}) error {
|
||||||
|
*reply = s.artifact.State(name)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ArtifactServer) Destroy(args *interface{}, reply *error) error {
|
func (s *ArtifactServer) Destroy(args *interface{}, reply *error) error {
|
||||||
err := s.artifact.Destroy()
|
err := s.artifact.Destroy()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -35,6 +35,10 @@ func (self *Artifact) String() string {
|
||||||
return fmt.Sprintf("'%s' compressing: %s", self.Provider, self.Path)
|
return fmt.Sprintf("'%s' compressing: %s", self.Provider, self.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*Artifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (self *Artifact) Destroy() error {
|
func (self *Artifact) Destroy() error {
|
||||||
return os.Remove(self.Path)
|
return os.Remove(self.Path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,10 @@ func (a *Artifact) String() string {
|
||||||
return fmt.Sprintf("'%s': %s", a.Provider, a.Tag)
|
return fmt.Sprintf("'%s': %s", a.Provider, a.Tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*Artifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Artifact) Destroy() error {
|
func (a *Artifact) Destroy() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,10 @@ func (a *Artifact) String() string {
|
||||||
return fmt.Sprintf("'%s' provider box: %s", a.Provider, a.Path)
|
return fmt.Sprintf("'%s' provider box: %s", a.Provider, a.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Artifact) State(name string) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *Artifact) Destroy() error {
|
func (a *Artifact) Destroy() error {
|
||||||
return os.Remove(a.Path)
|
return os.Remove(a.Path)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue