forked from buildpacks/pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inspect_builder.go
62 lines (54 loc) · 1.59 KB
/
inspect_builder.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
package pack
import (
"context"
"strings"
"github.com/pkg/errors"
"github.com/buildpacks/pack/internal/builder"
"github.com/buildpacks/pack/internal/dist"
"github.com/buildpacks/pack/internal/image"
"github.com/buildpacks/pack/internal/style"
)
type BuilderInfo struct {
Description string
Stack string
Mixins []string
RunImage string
RunImageMirrors []string
Buildpacks []dist.BuildpackInfo
Order dist.Order
Lifecycle builder.LifecycleDescriptor
CreatedBy builder.CreatorMetadata
}
func (c *Client) InspectBuilder(name string, daemon bool) (*BuilderInfo, error) {
img, err := c.imageFetcher.Fetch(context.Background(), name, daemon, false)
if err != nil {
if errors.Cause(err) == image.ErrNotFound {
return nil, nil
}
return nil, err
}
bldr, err := builder.FromImage(img)
if err != nil {
return nil, errors.Wrapf(err, "invalid builder %s", style.Symbol(name))
}
var commonMixins, buildMixins []string
commonMixins = []string{}
for _, mixin := range bldr.Mixins() {
if strings.HasPrefix(mixin, "build:") {
buildMixins = append(buildMixins, mixin)
} else {
commonMixins = append(commonMixins, mixin)
}
}
return &BuilderInfo{
Description: bldr.Description(),
Stack: bldr.StackID,
Mixins: append(commonMixins, buildMixins...),
RunImage: bldr.Stack().RunImage.Image,
RunImageMirrors: bldr.Stack().RunImage.Mirrors,
Buildpacks: bldr.Buildpacks(),
Order: bldr.Order(),
Lifecycle: bldr.LifecycleDescriptor(),
CreatedBy: bldr.CreatedBy(),
}, nil
}