@@ -17,6 +17,7 @@ import { Auth } from "../../auth"
1717import { Flag } from "../../flag/flag"
1818import { Session } from "../../session"
1919import { Instance } from "../../project/instance"
20+ import { ModelsDev } from "../../provider/models"
2021
2122declare global {
2223 const OPENCODE_TUI_PATH : string
@@ -130,13 +131,16 @@ export const TuiCommand = cmd({
130131 if ( Object . keys ( providers ) . length === 0 ) {
131132 return "needs_provider"
132133 }
134+ const cfg = await Config . get ( )
135+ const useDocker = ( args . docker ?? ( cfg . server ?. docker === true ) ) === true
136+
133137 const server = await ( async ( ) => {
134- if ( ! args . docker ) {
138+ if ( ! useDocker ) {
135139 return Server . listen ( { port : args . port , hostname : args . hostname } )
136140 }
137141
138- const docker = Bun . which ( "docker" )
139- if ( ! docker ) {
142+ const dockerBin = Bun . which ( "docker" )
143+ if ( ! dockerBin ) {
140144 UI . error ( "docker not found, starting server locally" )
141145 return Server . listen ( { port : args . port , hostname : args . hostname } )
142146 }
@@ -145,12 +149,13 @@ export const TuiCommand = cmd({
145149 const needBuild = ! ! df || ( args as { dockerBuild ?: boolean } ) . dockerBuild === true
146150 const img = await ( async ( ) => {
147151 const defaultImg = "opencodeai/opencode:server"
148- if ( ! needBuild ) return ( args as { dockerImage ?: string } ) . dockerImage ?? defaultImg
152+ const configured = cfg . server ?. image
153+ if ( ! needBuild ) return ( args as { dockerImage ?: string } ) . dockerImage ?? configured ?? defaultImg
149154 const f = df ?? "Dockerfile"
150155 const ctx = ( args as { dockerContext ?: string } ) . dockerContext ?? path . dirname ( path . resolve ( f ) )
151- const base = ( args as { dockerImage ?: string } ) . dockerImage ?? defaultImg
156+ const base = ( args as { dockerImage ?: string } ) . dockerImage ?? configured ?? defaultImg
152157 const tag = base === defaultImg ? "opencode:local" : base
153- const b = Bun . spawn ( { cmd : [ docker , "build" , "-t" , tag , "-f" , f , ctx ] , stdout : "inherit" , stderr : "inherit" } )
158+ const b = Bun . spawn ( { cmd : [ dockerBin , "build" , "-t" , tag , "-f" , f , ctx ] , stdout : "inherit" , stderr : "inherit" } )
154159 const code = await b . exited
155160 if ( code !== 0 ) {
156161 UI . error ( "docker build failed, starting server locally" )
@@ -170,9 +175,17 @@ export const TuiCommand = cmd({
170175 const host = "127.0.0.1"
171176 const cport = 8080
172177 const vol = process . cwd ( ) + ":/workspace"
178+ const db = await ModelsDev . get ( )
179+ const envlist : string [ ] = [ ]
180+ for ( const p of Object . values ( db ) ) {
181+ for ( const k of p . env ) {
182+ const v = process . env [ k ]
183+ if ( v ) envlist . push ( `${ k } =${ v } ` )
184+ }
185+ }
173186
174187 const cmd = [
175- docker ,
188+ dockerBin ,
176189 "run" ,
177190 "--rm" ,
178191 "-d" ,
@@ -182,6 +195,7 @@ export const TuiCommand = cmd({
182195 vol ,
183196 "-w" ,
184197 "/workspace" ,
198+ ...envlist . flatMap ( ( e ) => [ "-e" , e ] ) ,
185199 img ,
186200 "bun" ,
187201 "run" ,
@@ -214,7 +228,7 @@ export const TuiCommand = cmd({
214228 port,
215229 url,
216230 stop : async ( ) => {
217- const stop = Bun . spawn ( { cmd : [ docker , "stop" , id ] , stdout : "ignore" , stderr : "inherit" } )
231+ const stop = Bun . spawn ( { cmd : [ dockerBin , "stop" , id ] , stdout : "ignore" , stderr : "inherit" } )
218232 await stop . exited
219233 } ,
220234 }
@@ -240,7 +254,7 @@ export const TuiCommand = cmd({
240254 Log . Default . info ( "tui" , {
241255 cmd,
242256 } )
243- if ( args . docker ) {
257+ if ( useDocker ) {
244258 const auth = await Auth . all ( )
245259 await Promise . all (
246260 Object . entries ( auth ) . map ( ( [ id , info ] ) =>
0 commit comments