-
Notifications
You must be signed in to change notification settings - Fork 64
/
context.go
78 lines (64 loc) · 1.42 KB
/
context.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
package context
import (
"fmt"
"log"
"os/exec"
"strings"
"github.com/spiceai/spiceai/pkg/context/docker"
"github.com/spiceai/spiceai/pkg/context/metal"
)
type RuntimeContext interface {
Name() string
Init(isDevelopmentMode bool) error
Version() (string, error)
IsRuntimeInstallRequired() bool
InstallOrUpgradeRuntime() error
IsRuntimeUpgradeAvailable() (string, error)
SpiceRuntimeDir() string
AppDir() string
PodsDir() string
AIEngineDir() string
AIEnginePythonCmdPath() string
GetRunCmd(manifestPath string) (*exec.Cmd, error)
GetSpiceAppRelativePath(absolutePath string) string
}
var (
currentContext RuntimeContext
)
func NewContext(context string) (RuntimeContext, error) {
context = strings.ToLower(context)
var contextToSet RuntimeContext
switch context {
case "docker":
contextToSet = docker.NewDockerContext()
case "metal":
contextToSet = metal.NewMetalContext()
default:
return nil, fmt.Errorf("invalid context '%s'", context)
}
return contextToSet, nil
}
func SetDefaultContext() error {
rtcontext, err := NewContext("metal")
if err != nil {
return err
}
err = rtcontext.Init(false)
if err != nil {
return err
}
SetContext(rtcontext)
return nil
}
func SetContext(context RuntimeContext) {
currentContext = context
}
func CurrentContext() RuntimeContext {
if currentContext == nil {
err := SetDefaultContext()
if err != nil {
log.Fatal(err)
}
}
return currentContext
}