2014-01-19 22:48:06 -05:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-05-06 19:39:41 -04:00
|
|
|
"strings"
|
2014-01-19 22:48:06 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// ImportArtifact is an Artifact implementation for when a container is
|
|
|
|
// exported from docker into a single flat file.
|
|
|
|
type ImportArtifact struct {
|
|
|
|
BuilderIdValue string
|
|
|
|
Driver Driver
|
|
|
|
IdValue 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{}
|
2014-01-19 22:48:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *ImportArtifact) BuilderId() string {
|
|
|
|
return a.BuilderIdValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*ImportArtifact) Files() []string {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *ImportArtifact) Id() string {
|
|
|
|
return a.IdValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *ImportArtifact) String() string {
|
2020-09-29 08:25:15 -04:00
|
|
|
var tags []string
|
|
|
|
switch t := a.StateData["docker_tags"].(type) {
|
|
|
|
case []string:
|
|
|
|
tags = t
|
|
|
|
case []interface{}:
|
|
|
|
for _, name := range t {
|
|
|
|
if n, ok := name.(string); ok {
|
|
|
|
tags = append(tags, n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-28 04:52:28 -04:00
|
|
|
if len(tags) > 0 {
|
|
|
|
return fmt.Sprintf("Imported Docker image: %s with tags %s",
|
|
|
|
a.Id(), strings.Join(tags, " "))
|
2020-05-07 05:39:09 -04:00
|
|
|
}
|
2020-09-28 04:52:28 -04:00
|
|
|
return fmt.Sprintf("Imported Docker image: %s", a.Id())
|
2014-01-19 22:48:06 -05:00
|
|
|
}
|
|
|
|
|
2020-01-30 05:27:58 -05:00
|
|
|
func (a *ImportArtifact) State(name string) interface{} {
|
|
|
|
return a.StateData[name]
|
2014-01-19 13:32:44 -05:00
|
|
|
}
|
|
|
|
|
2014-01-19 22:48:06 -05:00
|
|
|
func (a *ImportArtifact) Destroy() error {
|
|
|
|
return a.Driver.DeleteImage(a.Id())
|
|
|
|
}
|