|
1 | 1 | package orchestrator |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "log/slog" |
4 | 5 | "os" |
5 | 6 |
|
6 | 7 | "github.com/arduino/go-paths-helper" |
7 | 8 | ) |
8 | 9 |
|
9 | 10 | type OrchestratorConfig struct { |
10 | | - appsDir *paths.Path |
11 | | - dataDir *paths.Path |
12 | | - routerSocketPath *paths.Path |
| 11 | + appsDir *paths.Path |
| 12 | + dataDir *paths.Path |
| 13 | + routerSocketPath *paths.Path |
| 14 | + customEIModelsDir *paths.Path |
13 | 15 | } |
14 | 16 |
|
15 | 17 | func NewOrchestratorConfigFromEnv() (*OrchestratorConfig, error) { |
@@ -51,10 +53,26 @@ func NewOrchestratorConfigFromEnv() (*OrchestratorConfig, error) { |
51 | 53 | routerSocket = paths.New("/var/run/arduino-router.sock") |
52 | 54 | } |
53 | 55 |
|
| 56 | + // Ensure the custom EI modules directory exists |
| 57 | + customEIModelsDir := paths.New(os.Getenv("ARDUINO_APP_BRICKS__CUSTOM_MODEL_DIR")) |
| 58 | + if customEIModelsDir == nil { |
| 59 | + homeDir, err := os.UserHomeDir() |
| 60 | + if err != nil { |
| 61 | + return nil, err |
| 62 | + } |
| 63 | + customEIModelsDir = paths.New(homeDir, ".arduino-bricks/ei-models") |
| 64 | + } |
| 65 | + if customEIModelsDir.NotExist() { |
| 66 | + if err := customEIModelsDir.MkdirAll(); err != nil { |
| 67 | + slog.Warn("failed create custom model directory", "error", err) |
| 68 | + } |
| 69 | + } |
| 70 | + |
54 | 71 | c := &OrchestratorConfig{ |
55 | | - appsDir: appsDir, |
56 | | - dataDir: dataDir, |
57 | | - routerSocketPath: routerSocket, |
| 72 | + appsDir: appsDir, |
| 73 | + dataDir: dataDir, |
| 74 | + routerSocketPath: routerSocket, |
| 75 | + customEIModelsDir: customEIModelsDir, |
58 | 76 | } |
59 | 77 | if err := c.init(); err != nil { |
60 | 78 | return nil, err |
|
0 commit comments