packer-cn/builder/docker/artifact_import.go

55 lines
1.1 KiB
Go
Raw Normal View History

package docker
import (
"fmt"
2020-05-06 19:39:41 -04:00
"strings"
)
// 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
// StateData should store data such as GeneratedData
// to be shared with post-processors
StateData map[string]interface{}
}
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-05-06 19:39:41 -04:00
tags := a.StateData["docker_tags"]
if tags == nil {
return fmt.Sprintf("Imported Docker image: %s", a.Id())
}
cast := tags.([]interface{})
names := []string{}
for _, name := range cast {
if n, ok := name.(string); ok {
names = append(names, n)
2020-05-06 19:39:41 -04:00
}
}
return fmt.Sprintf("Imported Docker image: %s with tags %s",
a.Id(), strings.Join(names, " "))
}
func (a *ImportArtifact) State(name string) interface{} {
return a.StateData[name]
}
func (a *ImportArtifact) Destroy() error {
return a.Driver.DeleteImage(a.Id())
}