Skip to content

Commit 326b485

Browse files
committed
Use JSON instead of string array
1 parent 040a02a commit 326b485

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

docs/environment.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ Example:
1616
"GENERIC_TIMEZONE",
1717
"N8N_RUNNERS_MAX_PAYLOAD",
1818
"N8N_RUNNERS_MAX_CONCURRENCY",
19-
"N8N_RUNNERS_TASK_TIMEOUT",
19+
"N8N_RUNNERS_TASK_TIMEOUT"
2020
],
21-
"override-envs": [
22-
"NODE_FUNCTION_ALLOW_BUILTIN=crypto",
23-
"NODE_FUNCTION_ALLOW_EXTERNAL=moment"
24-
"NODE_OPTIONS=--max-old-space-size=4096"
25-
]
26-
},
21+
"env-overrides": {
22+
"NODE_FUNCTION_ALLOW_BUILTIN": "crypto",
23+
"NODE_FUNCTION_ALLOW_EXTERNAL": "moment",
24+
"NODE_OPTIONS": "--max-old-space-size=4096"
25+
}
26+
}
2727
]
2828
}
2929
```

docs/setup.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ This launcher is intended for deployment as a sidecar container alongside one or
2020
"PATH",
2121
"GENERIC_TIMEZONE",
2222
],
23-
"override-envs": [
24-
"N8N_RUNNERS_TASK_TIMEOUT=80",
25-
"N8N_RUNNERS_AUTO_SHUTDOWN_TIMEOUT=120",
26-
"N8N_RUNNERS_MAX_CONCURRENCY=3",
27-
"NODE_FUNCTION_ALLOW_BUILTIN=crypto",
28-
"NODE_FUNCTION_ALLOW_EXTERNAL=moment"
29-
"NODE_OPTIONS=--max-old-space-size=4096",
30-
]
31-
},
23+
"env-overrides": {
24+
"N8N_RUNNERS_TASK_TIMEOUT": "80",
25+
"N8N_RUNNERS_AUTO_SHUTDOWN_TIMEOUT": "120",
26+
"N8N_RUNNERS_MAX_CONCURRENCY": "3",
27+
"NODE_FUNCTION_ALLOW_BUILTIN": "crypto",
28+
"NODE_FUNCTION_ALLOW_EXTERNAL": "moment",
29+
"NODE_OPTIONS": "--max-old-space-size=4096"
30+
}
31+
}
3232
]
3333
}
3434
```
@@ -39,7 +39,7 @@ Task runner config fields:
3939
- `workdir` is the path to directory containing the task runner binary.
4040
- `command` is the command to execute in order to start the task runner.
4141
- `args` are the args for the command to execute, currently the path to the task runner entrypoint.
42-
- `allowed-env` and `override-envs` are env vars that the launcher will pass through to or set directly on the runner, respectively. See [environment](environment.md).
42+
- `allowed-env` and `env-overrides` are env vars that the launcher will pass through to or set directly on the runner, respectively. See [environment](environment.md).
4343

4444
3. Set the **environment variables** for the launcher.
4545

internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type RunnerConfig struct {
7979
AllowedEnv []string `json:"allowed-env"`
8080

8181
// Env vars for the launcher to set directly on the runner.
82-
EnvOverrides []string `json:"env-overrides"`
82+
EnvOverrides map[string]string `json:"env-overrides"`
8383
}
8484

8585
func LoadConfig(runnerType string, lookuper envconfig.Lookuper) (*Config, error) {

internal/env/env.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,13 @@ func PrepareRunnerEnv(cfg *config.Config) []string {
132132
runnerEnv = append(runnerEnv, fmt.Sprintf("%s=%s", EnvVarAutoShutdownTimeout, cfg.AutoShutdownTimeout))
133133
runnerEnv = append(runnerEnv, fmt.Sprintf("%s=%s", EnvVarTaskTimeout, cfg.TaskTimeout))
134134

135-
for _, override := range cfg.Runner.EnvOverrides {
136-
parts := strings.SplitN(override, "=", 2)
137-
if len(parts) == 2 {
138-
key := parts[0]
139-
if slices.Contains(requiredRuntimeEnvVars, key) {
140-
logs.Warnf("Disregarded env-override for required runtime variable: %s", key)
141-
continue
142-
}
143-
runnerEnv = Clear(runnerEnv, key)
135+
for key, value := range cfg.Runner.EnvOverrides {
136+
if slices.Contains(requiredRuntimeEnvVars, key) {
137+
logs.Warnf("Disregarded env-override for required runtime variable: %s", key)
138+
continue
144139
}
145-
runnerEnv = append(runnerEnv, override)
140+
runnerEnv = Clear(runnerEnv, key)
141+
runnerEnv = append(runnerEnv, fmt.Sprintf("%s=%s", key, value))
146142
}
147143

148144
logs.Debugf("Env vars to pass to runner: %v", keys(runnerEnv))

internal/env/env_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,11 @@ func TestPrepareRunnerEnv(t *testing.T) {
253253
AutoShutdownTimeout: "30",
254254
TaskTimeout: "60",
255255
Runner: &config.RunnerConfig{
256-
AllowedEnv: []string{"CUSTOM_VAR1", "CUSTOM_VAR2"},
257-
EnvOverrides: []string{"CUSTOM_VAR1=overridden", "NEW_VAR=added"},
256+
AllowedEnv: []string{"CUSTOM_VAR1", "CUSTOM_VAR2"},
257+
EnvOverrides: map[string]string{
258+
"CUSTOM_VAR1": "overridden",
259+
"NEW_VAR": "added",
260+
},
258261
},
259262
},
260263
envSetup: map[string]string{
@@ -283,10 +286,10 @@ func TestPrepareRunnerEnv(t *testing.T) {
283286
TaskTimeout: "60",
284287
Runner: &config.RunnerConfig{
285288
AllowedEnv: []string{},
286-
EnvOverrides: []string{
287-
"N8N_RUNNERS_TASK_BROKER_URI=http://evil:5679",
288-
"N8N_RUNNERS_HEALTH_CHECK_SERVER_ENABLED=false",
289-
"CUSTOM_VAR=allowed",
289+
EnvOverrides: map[string]string{
290+
"N8N_RUNNERS_TASK_BROKER_URI": "http://evil:5679",
291+
"N8N_RUNNERS_HEALTH_CHECK_SERVER_ENABLED": "false",
292+
"CUSTOM_VAR": "allowed",
290293
},
291294
},
292295
},

0 commit comments

Comments
 (0)