You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: separate XDG directories for config, data, state and runtime (#1368)
**Description**
This refactors aigw to use distinct directories following XDG Base
Directory Specification conventions:
- --config-home/$AIGW_CONFIG_HOME: Configuration files (default:
~/.config/aigw)
- --data-home/$AIGW_DATA_HOME: Envoy binaries via func-e (default:
~/.local/share/aigw)
- --state-home/$AIGW_STATE_HOME: Run logs and state (default:
~/.local/state/aigw)
- --runtime-dir/$AIGW_RUNTIME_DIR: Ephemeral files like UDS (default:
/tmp/aigw-${UID})
This separation aligns with XDG principles where configuration, data,
state, and runtime files are independently configurable for different
storage tiers. This is particularly useful for Docker deployments to map
volumes appropriately.
This also adds --run-id/$AIGW_RUN_ID to override the default
YYYYMMDD_HHMMSS_UUU timestamp format with a custom identifier. Setting
this to '0' enables predictable paths for Docker/Kubernetes single-run
scenarios.
**Related Issues/PRs (if applicable)**
once envoyproxy/gateway#7225 is merged we have
some maintenance to remove the /tmp/envoy-gateway/certs tech debt
---------
Signed-off-by: Adrian Cole <[email protected]>
// cmd corresponds to the top-level `aigw` command.
26
28
cmdstruct {
29
+
// Global XDG flags
30
+
ConfigHomestring`name:"config-home" env:"AIGW_CONFIG_HOME" help:"Configuration files directory. Defaults to ~/.config/aigw" type:"path"`
31
+
DataHomestring`name:"data-home" env:"AIGW_DATA_HOME" help:"Downloaded Envoy binaries directory. Defaults to ~/.local/share/aigw" type:"path"`
32
+
StateHomestring`name:"state-home" env:"AIGW_STATE_HOME" help:"Persistent state and logs directory. Defaults to ~/.local/state/aigw" type:"path"`
33
+
RuntimeDirstring`name:"runtime-dir" env:"AIGW_RUNTIME_DIR" help:"Ephemeral runtime files directory. Defaults to /tmp/aigw-$UID" type:"path"`
34
+
27
35
// Version is the sub-command to show the version.
28
36
Versionstruct{} `cmd:"" help:"Show version."`
29
37
// Run is the sub-command parsed by the `cmdRun` struct.
@@ -34,16 +42,74 @@ type (
34
42
// cmdRun corresponds to `aigw run` command.
35
43
cmdRunstruct {
36
44
Debugbool`help:"Enable debug logging emitted to stderr."`
37
-
Pathstring`arg:"" name:"path" optional:"" help:"Path to the AI Gateway configuration yaml file. Optional when at least OPENAI_API_KEY, AZURE_OPENAI_API_KEY, or ANTHROPIC_API_KEY is set." type:"path"`
45
+
Pathstring`arg:"" name:"path" optional:"" help:"Path to the AI Gateway configuration yaml file. Defaults to $AIGW_CONFIG_HOME/config.yaml if exists, otherwise optional when at least OPENAI_API_KEY, AZURE_OPENAI_API_KEY or ANTHROPIC_API_KEY is set." type:"path"`
38
46
AdminPortint`help:"HTTP port for the admin server (serves /metrics and /health endpoints)." default:"1064"`
39
47
McpConfigstring`name:"mcp-config" help:"Path to MCP servers configuration file." type:"path"`
40
48
McpJSONstring`name:"mcp-json" help:"JSON string of MCP servers configuration."`
49
+
RunIDstring`name:"run-id" env:"AIGW_RUN_ID" help:"Run identifier for this invocation. Defaults to timestamp-based ID or $AIGW_RUN_ID. Use '0' for Docker/Kubernetes."`
41
50
mcpConfig*autoconfig.MCPServers`kong:"-"`// Internal field: normalized MCP JSON data
51
+
dirs*xdg.Directories`kong:"-"`// Internal field: XDG directories, set by BeforeApply
52
+
runOpts*runOpts`kong:"-"`// Internal field: run options, set by Validate
42
53
}
43
54
// cmdHealthcheck corresponds to `aigw healthcheck` command.
44
55
cmdHealthcheckstruct{}
45
56
)
46
57
58
+
// BeforeApply is called by Kong before applying defaults to set XDG directory defaults.
59
+
func (c*cmd) BeforeApply(_*kong.Context) error {
60
+
// Expand paths unconditionally (handles ~/, env vars, and converts to absolute)
61
+
// Set defaults only if not set (empty string)
62
+
ifc.ConfigHome=="" {
63
+
c.ConfigHome="~/.config/aigw"
64
+
}
65
+
c.ConfigHome=expandPath(c.ConfigHome)
66
+
67
+
ifc.DataHome=="" {
68
+
c.DataHome="~/.local/share/aigw"
69
+
}
70
+
c.DataHome=expandPath(c.DataHome)
71
+
72
+
ifc.StateHome=="" {
73
+
c.StateHome="~/.local/state/aigw"
74
+
}
75
+
c.StateHome=expandPath(c.StateHome)
76
+
77
+
ifc.RuntimeDir=="" {
78
+
c.RuntimeDir="/tmp/aigw-${UID}"
79
+
}
80
+
c.RuntimeDir=expandPath(c.RuntimeDir)
81
+
82
+
// Populate Run.dirs with expanded XDG directories for use in Run.BeforeApply
83
+
c.Run.dirs=&xdg.Directories{
84
+
ConfigHome: c.ConfigHome,
85
+
DataHome: c.DataHome,
86
+
StateHome: c.StateHome,
87
+
RuntimeDir: c.RuntimeDir,
88
+
}
89
+
90
+
returnnil
91
+
}
92
+
93
+
// BeforeApply is called by Kong before applying defaults to set computed default values.
0 commit comments