forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artifact_import.go
57 lines (48 loc) · 1.17 KB
/
artifact_import.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package docker
import (
"fmt"
"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 {
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)
}
}
}
if len(tags) > 0 {
return fmt.Sprintf("Imported Docker image: %s with tags %s",
a.Id(), strings.Join(tags, " "))
}
return fmt.Sprintf("Imported Docker image: %s", a.Id())
}
func (a *ImportArtifact) State(name string) interface{} {
return a.StateData[name]
}
func (a *ImportArtifact) Destroy() error {
return a.Driver.DeleteImage(a.Id())
}