@@ -16,6 +16,7 @@ import (
1616
1717var CLI struct {
1818 ConfigFile string `help:"Path to YAML config file" type:"path"`
19+ Backend string `help:"Backend type (docker or direct)" enum:"docker,direct," default:""`
1920 APIKey string `help:"API key for authentication" env:"WARP_API_KEY" required:""`
2021 WorkerID string `help:"Worker host identifier (required via flag or config file)"`
2122 WebSocketURL string `default:"wss://oz.warp.dev/api/v1/selfhosted/worker/ws" hidden:""`
@@ -93,6 +94,16 @@ func mergeConfig(fileConfig *config.FileConfig) (worker.Config, error) {
9394 return worker.Config {}, fmt .Errorf ("invalid worker-id: values starting with 'warp' are reserved and cannot be used" )
9495 }
9596
97+ // Resolve backend type: CLI --backend > config file backend key > default "docker".
98+ backendType := CLI .Backend
99+ if backendType == "" && fileConfig != nil {
100+ if fileConfig .Backend .Direct != nil {
101+ backendType = "direct"
102+ } else if fileConfig .Backend .Docker != nil {
103+ backendType = "docker"
104+ }
105+ }
106+
96107 // Merge cleanup: --no-cleanup flag > config file cleanup > default (cleanup=true).
97108 noCleanup := CLI .NoCleanup
98109 if ! noCleanup && fileConfig != nil && fileConfig .Cleanup != nil {
@@ -105,32 +116,68 @@ func mergeConfig(fileConfig *config.FileConfig) (worker.Config, error) {
105116 return worker.Config {}, err
106117 }
107118
108- // Merge env: config file first, then CLI entries overlay (CLI wins on key conflict).
109- mergedEnv := make (map [string ]string )
110- if fileConfig != nil && fileConfig .Backend .Docker != nil {
111- mergedEnv = config .ResolveEnv (fileConfig .Backend .Docker .Environment )
112- }
113- for k , v := range cliEnv {
114- mergedEnv [k ] = v
115- }
116-
117- // Merge volumes: config file + CLI (concatenated).
118- var volumes []string
119- if fileConfig != nil && fileConfig .Backend .Docker != nil {
120- volumes = append (volumes , fileConfig .Backend .Docker .Volumes ... )
121- }
122- volumes = append (volumes , CLI .Volumes ... )
123-
124- return worker.Config {
119+ wc := worker.Config {
125120 APIKey : CLI .APIKey ,
126121 WorkerID : workerID ,
127122 WebSocketURL : CLI .WebSocketURL ,
128123 ServerRootURL : CLI .ServerRootURL ,
129124 LogLevel : CLI .LogLevel ,
130- NoCleanup : noCleanup ,
131- Volumes : volumes ,
132- Env : mergedEnv ,
133- }, nil
125+ BackendType : backendType ,
126+ }
127+
128+ switch backendType {
129+ case "direct" :
130+ // Merge env: config file first, then CLI overlay.
131+ mergedEnv := make (map [string ]string )
132+ if fileConfig != nil && fileConfig .Backend .Direct != nil {
133+ mergedEnv = config .ResolveEnv (fileConfig .Backend .Direct .Environment )
134+ }
135+ for k , v := range cliEnv {
136+ mergedEnv [k ] = v
137+ }
138+
139+ var workspaceRoot , ozPath , setupCmd , teardownCmd string
140+ if fileConfig != nil && fileConfig .Backend .Direct != nil {
141+ workspaceRoot = fileConfig .Backend .Direct .WorkspaceRoot
142+ ozPath = fileConfig .Backend .Direct .OzPath
143+ setupCmd = fileConfig .Backend .Direct .SetupCommand
144+ teardownCmd = fileConfig .Backend .Direct .TeardownCommand
145+ }
146+
147+ wc .Direct = & worker.DirectBackendConfig {
148+ WorkspaceRoot : workspaceRoot ,
149+ OzPath : ozPath ,
150+ SetupCommand : setupCmd ,
151+ TeardownCommand : teardownCmd ,
152+ NoCleanup : noCleanup ,
153+ Env : mergedEnv ,
154+ }
155+
156+ default : // docker
157+ // Merge env: config file first, then CLI overlay (CLI wins on key conflict).
158+ mergedEnv := make (map [string ]string )
159+ if fileConfig != nil && fileConfig .Backend .Docker != nil {
160+ mergedEnv = config .ResolveEnv (fileConfig .Backend .Docker .Environment )
161+ }
162+ for k , v := range cliEnv {
163+ mergedEnv [k ] = v
164+ }
165+
166+ // Merge volumes: config file + CLI (concatenated).
167+ var volumes []string
168+ if fileConfig != nil && fileConfig .Backend .Docker != nil {
169+ volumes = append (volumes , fileConfig .Backend .Docker .Volumes ... )
170+ }
171+ volumes = append (volumes , CLI .Volumes ... )
172+
173+ wc .Docker = & worker.DockerBackendConfig {
174+ NoCleanup : noCleanup ,
175+ Volumes : volumes ,
176+ Env : mergedEnv ,
177+ }
178+ }
179+
180+ return wc , nil
134181}
135182
136183// parseEnvFlags parses -e/--env flag values into a map.
0 commit comments