-
Notifications
You must be signed in to change notification settings - Fork 3
/
detect.go
56 lines (49 loc) · 1.2 KB
/
detect.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
package passenger
import (
"fmt"
"path/filepath"
"github.com/paketo-buildpacks/packit/v2"
)
//go:generate faux --interface Parser --output fakes/parser.go
type Parser interface {
Parse(path string) (hasPassenger bool, err error)
}
type BuildPlanMetadata struct {
Launch bool `toml:"launch"`
}
func Detect(gemfileParser Parser) packit.DetectFunc {
return func(context packit.DetectContext) (packit.DetectResult, error) {
hasPassenger, err := gemfileParser.Parse(filepath.Join(context.WorkingDir, "Gemfile"))
if err != nil {
return packit.DetectResult{}, fmt.Errorf("failed to parse Gemfile: %w", err)
}
if !hasPassenger {
return packit.DetectResult{}, packit.Fail.WithMessage("passenger was not found in the Gemfile")
}
return packit.DetectResult{
Plan: packit.BuildPlan{
Provides: []packit.BuildPlanProvision{},
Requires: []packit.BuildPlanRequirement{
{
Name: "gems",
Metadata: BuildPlanMetadata{
Launch: true,
},
},
{
Name: "bundler",
Metadata: BuildPlanMetadata{
Launch: true,
},
},
{
Name: "mri",
Metadata: BuildPlanMetadata{
Launch: true,
},
},
},
},
}, nil
}
}