2017-09-12 11:30:39 -04:00
|
|
|
package oci
|
2017-02-13 05:35:14 -05:00
|
|
|
|
|
|
|
import (
|
2018-06-26 05:05:56 -04:00
|
|
|
"context"
|
2017-02-13 05:35:14 -05:00
|
|
|
"fmt"
|
2018-01-22 20:21:10 -05:00
|
|
|
|
2018-04-11 05:20:40 -04:00
|
|
|
"github.com/oracle/oci-go-sdk/core"
|
2017-02-13 05:35:14 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// Artifact is an artifact implementation that contains a built Custom Image.
|
|
|
|
type Artifact struct {
|
2018-04-11 05:20:40 -04:00
|
|
|
Image core.Image
|
2017-02-13 05:35:14 -05:00
|
|
|
Region string
|
|
|
|
driver Driver
|
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{}
|
2017-02-13 05:35:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// BuilderId uniquely identifies the builder.
|
|
|
|
func (a *Artifact) BuilderId() string {
|
|
|
|
return BuilderId
|
|
|
|
}
|
|
|
|
|
|
|
|
// Files lists the files associated with an artifact. We don't have any files
|
|
|
|
// as the custom image is stored server side.
|
|
|
|
func (a *Artifact) Files() []string {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Id returns the OCID of the associated Image.
|
|
|
|
func (a *Artifact) Id() string {
|
2018-04-11 05:20:40 -04:00
|
|
|
return *a.Image.Id
|
2017-02-13 05:35:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Artifact) String() string {
|
2018-04-11 05:20:40 -04:00
|
|
|
var displayName string
|
|
|
|
if a.Image.DisplayName != nil {
|
|
|
|
displayName = *a.Image.DisplayName
|
|
|
|
}
|
|
|
|
|
2017-02-13 05:35:14 -05:00
|
|
|
return fmt.Sprintf(
|
|
|
|
"An image was created: '%v' (OCID: %v) in region '%v'",
|
2018-04-11 05:20:40 -04:00
|
|
|
displayName, *a.Image.Id, a.Region,
|
2017-02-13 05:35:14 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-06-26 05:05:56 -04:00
|
|
|
// State ...
|
2017-02-13 05:35:14 -05:00
|
|
|
func (a *Artifact) State(name string) interface{} {
|
2020-01-30 05:27:58 -05:00
|
|
|
return a.StateData[name]
|
2017-02-13 05:35:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy deletes the custom image associated with the artifact.
|
|
|
|
func (a *Artifact) Destroy() error {
|
2018-06-26 05:05:56 -04:00
|
|
|
return a.driver.DeleteImage(context.TODO(), *a.Image.Id)
|
2017-02-13 05:35:14 -05:00
|
|
|
}
|