This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
/
detect.go
75 lines (64 loc) · 1.54 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
// Copyright 2021-2022 VMware, Inc.
// SPDX-License-Identifier: BSD-2-Clause
package python
import (
"github.com/buildpacks/libcnb"
"github.com/paketo-buildpacks/libpak"
"github.com/paketo-buildpacks/libpak/bard"
"kn-fn/buildpacks/config"
)
type Detect struct {
Logger bard.Logger
}
func (d Detect) Detect(context libcnb.DetectContext) (libcnb.DetectResult, error) {
result := libcnb.DetectResult{}
funcYaml := config.ParseFuncYaml(context.Application.Path, d.Logger)
cr, err := libpak.NewConfigurationResolver(context.Buildpack, &d.Logger)
if err != nil {
return libcnb.DetectResult{}, err
}
functionClass, functionClassSet := cr.Resolve("BP_FUNCTION")
if _, _, err := parseFunctionClass(functionClass); err != nil {
d.Logger.Body(err.Error())
return libcnb.DetectResult{}, nil
}
result.Plans = append(result.Plans, libcnb.BuildPlan{
Provides: []libcnb.BuildPlanProvide{
{
Name: "python-function",
},
},
Requires: []libcnb.BuildPlanRequire{
{
Name: "python-function",
Metadata: map[string]any{
"launch": true,
"func_yaml_envs": funcYaml.Envs,
"func_yaml_options": funcYaml.Options,
},
},
{
Name: "site-packages",
Metadata: map[string]any{
"build": true,
"launch": true,
},
},
{
Name: "pip",
Metadata: map[string]any{
"build": true,
},
},
{
Name: "cpython",
Metadata: map[string]any{
"build": true,
"launch": true,
},
},
},
})
result.Pass = funcYaml.Exists || functionClassSet
return result, nil
}