-
Notifications
You must be signed in to change notification settings - Fork 284
/
dist.go
84 lines (68 loc) · 1.93 KB
/
dist.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package dist
import (
"github.com/buildpacks/lifecycle/api"
)
const BuildpackLayersLabel = "io.buildpacks.buildpack.layers"
type BuildpackURI struct {
URI string `toml:"uri"`
}
type ImageRef struct {
ImageName string `toml:"image"`
}
type ImageOrURI struct {
BuildpackURI
ImageRef
}
func (c *ImageOrURI) DisplayString() string {
if c.BuildpackURI.URI != "" {
return c.BuildpackURI.URI
}
return c.ImageRef.ImageName
}
type Platform struct {
OS string `toml:"os"`
}
type Order []OrderEntry
type OrderEntry struct {
Group []BuildpackRef `toml:"group" json:"group"`
}
type BuildpackRef struct {
BuildpackInfo `yaml:"buildpackinfo,inline"`
Optional bool `toml:"optional,omitempty" json:"optional,omitempty" yaml:"optional,omitempty"`
}
type BuildpackLayers map[string]map[string]BuildpackLayerInfo
type BuildpackLayerInfo struct {
API *api.Version `json:"api"`
Stacks []Stack `json:"stacks,omitempty"`
Order Order `json:"order,omitempty"`
LayerDiffID string `json:"layerDiffID"`
Homepage string `json:"homepage,omitempty"`
Name string `json:"name,omitempty"`
}
func (b BuildpackLayers) Get(id, version string) (BuildpackLayerInfo, bool) {
buildpackLayerEntries, ok := b[id]
if !ok {
return BuildpackLayerInfo{}, false
}
if len(buildpackLayerEntries) == 1 && version == "" {
for key := range buildpackLayerEntries {
version = key
}
}
result, ok := buildpackLayerEntries[version]
return result, ok
}
func AddBuildpackToLayersMD(layerMD BuildpackLayers, descriptor BuildpackDescriptor, diffID string) {
bpInfo := descriptor.Info
if _, ok := layerMD[bpInfo.ID]; !ok {
layerMD[bpInfo.ID] = map[string]BuildpackLayerInfo{}
}
layerMD[bpInfo.ID][bpInfo.Version] = BuildpackLayerInfo{
API: descriptor.API,
Stacks: descriptor.Stacks,
Order: descriptor.Order,
LayerDiffID: diffID,
Homepage: bpInfo.Homepage,
Name: bpInfo.Name,
}
}