/
buildpack_descriptor.go
60 lines (50 loc) · 1.49 KB
/
buildpack_descriptor.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
package dist
import (
"fmt"
"sort"
"strings"
"github.com/buildpacks/lifecycle/api"
"github.com/buildpacks/pack/internal/stringset"
"github.com/buildpacks/pack/internal/style"
)
type BuildpackDescriptor struct {
API *api.Version `toml:"api"`
Info BuildpackInfo `toml:"buildpack"`
Stacks []Stack `toml:"stacks"`
Order Order `toml:"order"`
}
func (b *BuildpackDescriptor) EscapedID() string {
return strings.ReplaceAll(b.Info.ID, "/", "_")
}
func (b *BuildpackDescriptor) EnsureStackSupport(stackID string, providedMixins []string, validateRunStageMixins bool) error {
if len(b.Stacks) == 0 {
return nil // Order buildpack, no validation required
}
bpMixins, err := b.findMixinsForStack(stackID)
if err != nil {
return err
}
if !validateRunStageMixins {
var filtered []string
for _, m := range bpMixins {
if !strings.HasPrefix(m, "run:") {
filtered = append(filtered, m)
}
}
bpMixins = filtered
}
_, missing, _ := stringset.Compare(providedMixins, bpMixins)
if len(missing) > 0 {
sort.Strings(missing)
return fmt.Errorf("buildpack %s requires missing mixin(s): %s", style.Symbol(b.Info.FullName()), strings.Join(missing, ", "))
}
return nil
}
func (b *BuildpackDescriptor) findMixinsForStack(stackID string) ([]string, error) {
for _, s := range b.Stacks {
if s.ID == stackID || s.ID == "*" {
return s.Mixins, nil
}
}
return nil, fmt.Errorf("buildpack %s does not support stack %s", style.Symbol(b.Info.FullName()), style.Symbol(stackID))
}