Skip to content

Commit 70cf2b2

Browse files
Add custom EI model directory (#453)
Co-authored-by: Alessio Perugini <alessio@perugini.xyz>
1 parent 32d618c commit 70cf2b2

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

internal/orchestrator/config.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package orchestrator
22

33
import (
4+
"log/slog"
45
"os"
56

67
"github.com/arduino/go-paths-helper"
78
)
89

910
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
1315
}
1416

1517
func NewOrchestratorConfigFromEnv() (*OrchestratorConfig, error) {
@@ -51,10 +53,26 @@ func NewOrchestratorConfigFromEnv() (*OrchestratorConfig, error) {
5153
routerSocket = paths.New("/var/run/arduino-router.sock")
5254
}
5355

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+
5471
c := &OrchestratorConfig{
55-
appsDir: appsDir,
56-
dataDir: dataDir,
57-
routerSocketPath: routerSocket,
72+
appsDir: appsDir,
73+
dataDir: dataDir,
74+
routerSocketPath: routerSocket,
75+
customEIModelsDir: customEIModelsDir,
5876
}
5977
if err := c.init(); err != nil {
6078
return nil, err

0 commit comments

Comments
 (0)