/
requirements.go
49 lines (45 loc) · 1.41 KB
/
requirements.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
package base
import (
"context"
"fmt"
"os/exec"
agentv0 "github.com/codefly-dev/core/generated/go/services/agent/v0"
"github.com/codefly-dev/core/wool"
)
func CheckPythonPath() (string, error) {
pythonVersions := []string{"python", "python3"}
for _, version := range pythonVersions {
if _, err := exec.LookPath(version); err == nil {
return version, nil
}
}
return "", fmt.Errorf("python/python3 is required and is not installed")
}
func CheckForRuntimes(ctx context.Context, requirements []*agentv0.Runtime) error {
w := wool.Get(ctx).In("CheckForRuntimes")
for _, req := range requirements {
switch req.Type {
case agentv0.Runtime_GO:
_, err := exec.LookPath("go")
if err != nil {
w.Warn("Go is required to run in native mode. But don't worry, you can still run in container mode!")
}
case agentv0.Runtime_NPM:
_, err := exec.LookPath("npm")
if err != nil {
w.Warn("NPM is required to run in native mode. But don't worry, you can still run in container mode!")
}
case agentv0.Runtime_PYTHON:
_, err := CheckPythonPath()
if err != nil {
w.Warn("Python is required to run in native mode. But don't worry, you can still run in container mode!")
}
case agentv0.Runtime_PYTHON_POETRY:
_, err := exec.LookPath("poetry")
if err != nil {
w.Warn("Poetry is required to run in native mode. But don't worry, you can still run in container mode!")
}
}
}
return nil
}