Skip to content

Commit 4479254

Browse files
committed
fix: bind env vars explicitly for viper to work without config file
AutomaticEnv() requires keys to be registered. Without a config file, viper has no keys and ignores environment variables.
1 parent 525316e commit 4479254

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ WORKDIR /app
2727
COPY --from=build /bin/flashduty-runner .
2828

2929
# Set environment variables
30-
ENV FLASHDUTY_API_KEY=""
31-
ENV FLASHDUTY_API_URL="wss://api.flashcat.cloud/runner/ws"
30+
ENV FLASHDUTY_RUNNER_API_KEY=""
31+
ENV FLASHDUTY_RUNNER_API_URL="wss://api.flashcat.cloud/runner/ws"
3232
ENV FLASHDUTY_RUNNER_NAME=""
33-
ENV FLASHDUTY_WORKSPACE_ROOT="/workspace"
34-
ENV FLASHDUTY_AUTO_UPDATE="false"
33+
ENV FLASHDUTY_RUNNER_WORKSPACE_ROOT="/workspace"
34+
ENV FLASHDUTY_RUNNER_AUTO_UPDATE="false"
3535

3636
# Create workspace directory
3737
VOLUME ["/workspace"]

config/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ func Load(configPath string) (*Config, error) {
106106
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
107107
v.AutomaticEnv()
108108

109+
// Explicitly bind environment variables (required for AutomaticEnv to work without config file)
110+
_ = v.BindEnv("api_key")
111+
_ = v.BindEnv("api_url")
112+
_ = v.BindEnv("name")
113+
_ = v.BindEnv("workspace_root")
114+
_ = v.BindEnv("auto_update")
115+
_ = v.BindEnv("log.level")
116+
_ = v.BindEnv("log.format")
117+
109118
// Unmarshal into config struct
110119
if err := v.Unmarshal(cfg); err != nil {
111120
return nil, fmt.Errorf("failed to unmarshal config: %w", err)

0 commit comments

Comments
 (0)