-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathstore.go
38 lines (31 loc) · 888 Bytes
/
store.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
package buildpack
import (
"path/filepath"
"github.com/BurntSushi/toml"
"github.com/buildpacks/lifecycle/launch"
)
type Buildpack interface {
Build(bpPlan Plan, config BuildConfig, bpEnv BuildEnv) (BuildResult, error)
ConfigFile() *Descriptor
Detect(config *DetectConfig, bpEnv BuildEnv) DetectRun
}
type DirBuildpackStore struct {
Dir string
}
func NewBuildpackStore(dir string) (*DirBuildpackStore, error) {
dir, err := filepath.Abs(dir)
if err != nil {
return nil, err
}
return &DirBuildpackStore{Dir: dir}, nil
}
func (f *DirBuildpackStore) Lookup(bpID, bpVersion string) (Buildpack, error) {
bpTOML := Descriptor{}
bpPath := filepath.Join(f.Dir, launch.EscapeID(bpID), bpVersion)
tomlPath := filepath.Join(bpPath, "buildpack.toml")
if _, err := toml.DecodeFile(tomlPath, &bpTOML); err != nil {
return nil, err
}
bpTOML.Dir = bpPath
return &bpTOML, nil
}