|
1 | 1 | package config |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
4 | 5 | "log/slog" |
5 | 6 | "os" |
| 7 | + "path" |
| 8 | + "strings" |
6 | 9 |
|
7 | 10 | "github.com/arduino/go-paths-helper" |
8 | 11 | ) |
9 | 12 |
|
| 13 | +// Do not manually modify this, we keep it updated with the `task generate:bricks-and-models-index` |
| 14 | +var runnerVersion = "0.1.16" |
| 15 | + |
10 | 16 | type Configuration struct { |
11 | | - appsDir *paths.Path |
12 | | - configDir *paths.Path |
13 | | - dataDir *paths.Path |
14 | | - routerSocketPath *paths.Path |
15 | | - customEIModelsDir *paths.Path |
| 17 | + appsDir *paths.Path |
| 18 | + configDir *paths.Path |
| 19 | + dataDir *paths.Path |
| 20 | + routerSocketPath *paths.Path |
| 21 | + customEIModelsDir *paths.Path |
| 22 | + PythonImage string |
| 23 | + UsedPythonImageTag string |
| 24 | + RunnerVersion string |
16 | 25 | } |
17 | 26 |
|
18 | 27 | func NewFromEnv() (Configuration, error) { |
@@ -78,12 +87,18 @@ func NewFromEnv() (Configuration, error) { |
78 | 87 | } |
79 | 88 | } |
80 | 89 |
|
| 90 | + pythonImage, usedPythonImageTag := getPythonImageAndTag() |
| 91 | + slog.Debug("Using pythonImage", slog.String("image", pythonImage)) |
| 92 | + |
81 | 93 | c := Configuration{ |
82 | | - appsDir: appsDir, |
83 | | - configDir: configDir, |
84 | | - dataDir: dataDir, |
85 | | - routerSocketPath: routerSocket, |
86 | | - customEIModelsDir: customEIModelsDir, |
| 94 | + appsDir: appsDir, |
| 95 | + configDir: configDir, |
| 96 | + dataDir: dataDir, |
| 97 | + routerSocketPath: routerSocket, |
| 98 | + customEIModelsDir: customEIModelsDir, |
| 99 | + PythonImage: pythonImage, |
| 100 | + UsedPythonImageTag: usedPythonImageTag, |
| 101 | + RunnerVersion: runnerVersion, |
87 | 102 | } |
88 | 103 | if err := c.init(); err != nil { |
89 | 104 | return Configuration{}, err |
@@ -127,3 +142,22 @@ func (c *Configuration) RouterSocketPath() *paths.Path { |
127 | 142 | func (c *Configuration) AssetsDir() *paths.Path { |
128 | 143 | return c.dataDir.Join("assets") |
129 | 144 | } |
| 145 | + |
| 146 | +func getPythonImageAndTag() (string, string) { |
| 147 | + registryBase := os.Getenv("DOCKER_REGISTRY_BASE") |
| 148 | + if registryBase == "" { |
| 149 | + registryBase = "ghcr.io/bcmi-labs/" |
| 150 | + } |
| 151 | + |
| 152 | + // Python image: image name (repository) and optionally a tag. |
| 153 | + pythonImageAndTag := os.Getenv("DOCKER_PYTHON_BASE_IMAGE") |
| 154 | + if pythonImageAndTag == "" { |
| 155 | + pythonImageAndTag = fmt.Sprintf("arduino/appslab-python-apps-base:%s", runnerVersion) |
| 156 | + } |
| 157 | + pythonImage := path.Join(registryBase, pythonImageAndTag) |
| 158 | + var usedPythonImageTag string |
| 159 | + if idx := strings.LastIndex(pythonImage, ":"); idx != -1 { |
| 160 | + usedPythonImageTag = pythonImage[idx+1:] |
| 161 | + } |
| 162 | + return pythonImage, usedPythonImageTag |
| 163 | +} |
0 commit comments