forked from paketo-buildpacks/httpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect.go
94 lines (79 loc) · 2.27 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
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
85
86
87
88
89
90
91
92
93
94
package httpd
import (
"path/filepath"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/fs"
)
const PlanDependencyHTTPD = "httpd"
//go:generate faux --interface Parser --output fakes/parser.go
type Parser interface {
ParseVersion(path string) (version, versionSource string, err error)
}
type BuildPlanMetadata struct {
Version string `toml:"version,omitempty"`
VersionSource string `toml:"version-source,omitempty"`
Launch bool `toml:"launch"`
}
func Detect(buildEnvironment BuildEnvironment, parser Parser) packit.DetectFunc {
return func(context packit.DetectContext) (packit.DetectResult, error) {
plan := packit.DetectResult{
Plan: packit.BuildPlan{
Provides: []packit.BuildPlanProvision{
{Name: PlanDependencyHTTPD},
},
},
}
var requirements []packit.BuildPlanRequirement
if buildEnvironment.WebServer == "httpd" {
requirements = append(requirements, packit.BuildPlanRequirement{
Name: PlanDependencyHTTPD,
Metadata: BuildPlanMetadata{
Launch: true,
},
})
plan.Plan.Requires = requirements
}
exists, err := fs.Exists(filepath.Join(context.WorkingDir, "httpd.conf"))
if err != nil {
return packit.DetectResult{}, err
}
if !exists {
return plan, nil
}
if buildEnvironment.HTTPDVersion != "" {
requirements = append(requirements, packit.BuildPlanRequirement{
Name: PlanDependencyHTTPD,
Metadata: BuildPlanMetadata{
Version: buildEnvironment.HTTPDVersion,
VersionSource: "BP_HTTPD_VERSION",
Launch: true,
},
})
}
version, versionSource, err := parser.ParseVersion(filepath.Join(context.WorkingDir, "buildpack.yml"))
if err != nil {
return packit.DetectResult{}, err
}
if version != "" {
requirements = append(requirements, packit.BuildPlanRequirement{
Name: PlanDependencyHTTPD,
Metadata: BuildPlanMetadata{
Version: version,
VersionSource: versionSource,
Launch: true,
},
})
plan.Plan.Requires = requirements
}
if buildEnvironment.Reload {
requirements = append(requirements, packit.BuildPlanRequirement{
Name: "watchexec",
Metadata: map[string]interface{}{
"launch": true,
},
})
plan.Plan.Requires = requirements
}
return plan, nil
}
}