@@ -4,7 +4,9 @@ import * as FileSystem from "@effect/platform/FileSystem"
44import * as Path from "@effect/platform/Path"
55import { Duration , Effect } from "effect"
66
7+ import { loadControllerDockerRuntime , resolveControllerRuntimeOverlayPath } from "./controller-compose-runtime.js"
78import { computeLocalControllerRevision , controllerRevisionEnvKey } from "./controller-revision.js"
9+ import type { ControllerDockerRuntime } from "./controller-runtime.js"
810import { runCommandWithCapturedOutput } from "./frontend-lib/shell/command-runner.js"
911import { findExistingUpwards } from "./frontend-lib/usecases/path-helpers.js"
1012import type { ControllerBootstrapError } from "./host-errors.js"
@@ -18,6 +20,7 @@ export type ControllerBuildSkillerMode = "0" | "1"
1820export type ControllerComposeFiles = {
1921 readonly composePath : string
2022 readonly gpuOverlayPath : string | null
23+ readonly runtimeOverlayPath : string | null
2124}
2225
2326const skillerSubmodulePath = "third_party/skiller-desktop-skills-manager"
@@ -47,8 +50,9 @@ export const parseControllerBuildSkillerMode = (raw?: string): ControllerBuildSk
4750export const controllerRevisionForMode = (
4851 sourceRevision : string ,
4952 gpuMode : ControllerGpuMode ,
50- buildSkillerMode : ControllerBuildSkillerMode = "1"
51- ) : string => `${ sourceRevision } -${ gpuMode } -skiller${ buildSkillerMode } `
53+ buildSkillerMode : ControllerBuildSkillerMode = "1" ,
54+ dockerRuntime : ControllerDockerRuntime = "host"
55+ ) : string => `${ sourceRevision } -${ dockerRuntime } -${ gpuMode } -skiller${ buildSkillerMode } `
5256
5357const loadControllerGpuMode = ( ) : Effect . Effect < ControllerGpuMode , ControllerBootstrapError > => {
5458 const raw = process . env [ controllerGpuModeEnvKey ]
@@ -187,11 +191,21 @@ export const ensureSkillerSubmoduleInitialized = (
187191
188192export const composeFilesForMode = (
189193 composePath : string ,
190- gpuOverlayPath : string | null
191- ) : ReadonlyArray < string > =>
192- gpuOverlayPath === null
193- ? [ "-f" , composePath ]
194- : [ "-f" , composePath , "-f" , gpuOverlayPath ]
194+ gpuOverlayPath : string | null ,
195+ runtimeOverlayPath : string | null = null
196+ ) : ReadonlyArray < string > => [
197+ "-f" ,
198+ composePath ,
199+ ...( runtimeOverlayPath === null ? [ ] : [ "-f" , runtimeOverlayPath ] ) ,
200+ ...( gpuOverlayPath === null ? [ ] : [ "-f" , gpuOverlayPath ] )
201+ ]
202+
203+ export const composeFilesToArgs = ( composeFiles : ControllerComposeFiles ) : ReadonlyArray < string > =>
204+ composeFilesForMode (
205+ composeFiles . composePath ,
206+ composeFiles . gpuOverlayPath ,
207+ composeFiles . runtimeOverlayPath
208+ )
195209
196210const requireGpuOverlayPath = (
197211 composePath : string
@@ -215,13 +229,14 @@ const composeFilesForGpuMode = (
215229 gpuMode : ControllerGpuMode
216230) : Effect . Effect < ControllerComposeFiles , ControllerBootstrapError , FileSystem . FileSystem | Path . Path > =>
217231 gpuMode === "none"
218- ? Effect . succeed ( { composePath, gpuOverlayPath : null } )
232+ ? Effect . succeed ( { composePath, gpuOverlayPath : null , runtimeOverlayPath : null } )
219233 : requireGpuOverlayPath ( composePath ) . pipe (
220- Effect . map ( ( gpuOverlayPath ) => ( { composePath, gpuOverlayPath } ) )
234+ Effect . map ( ( gpuOverlayPath ) => ( { composePath, gpuOverlayPath, runtimeOverlayPath : null } ) )
221235 )
222236
223237type ComposePathAndGpuMode = {
224238 readonly composePath : string
239+ readonly dockerRuntime : ControllerDockerRuntime
225240 readonly gpuMode : ControllerGpuMode
226241 readonly buildSkillerMode : ControllerBuildSkillerMode
227242}
@@ -236,12 +251,12 @@ const withComposePathAndGpuMode = <A, R>(
236251 composeFilePath ( ) . pipe (
237252 Effect . mapError ( mapComposePathError ) ,
238253 Effect . flatMap ( ( composePath ) =>
239- loadControllerGpuMode ( ) . pipe (
240- Effect . flatMap ( ( gpuMode ) =>
241- loadControllerBuildSkillerMode ( ) . pipe (
242- Effect . flatMap ( ( buildSkillerMode ) => effect ( { buildSkillerMode , composePath , gpuMode } ) )
243- )
244- )
254+ Effect . all ( {
255+ buildSkillerMode : loadControllerBuildSkillerMode ( ) ,
256+ dockerRuntime : loadControllerDockerRuntime ( ) ,
257+ gpuMode : loadControllerGpuMode ( )
258+ } ) . pipe (
259+ Effect . flatMap ( ( modes ) => effect ( { composePath , ... modes } ) )
245260 )
246261 )
247262 )
@@ -250,16 +265,24 @@ export const resolveControllerComposeFiles = (): Effect.Effect<
250265 ControllerComposeFiles ,
251266 ControllerBootstrapError ,
252267 FileSystem . FileSystem | Path . Path
253- > => withComposePathAndGpuMode ( ( { composePath, gpuMode } ) => composeFilesForGpuMode ( composePath , gpuMode ) )
268+ > =>
269+ withComposePathAndGpuMode ( ( { composePath, dockerRuntime, gpuMode } ) =>
270+ Effect . gen ( function * ( _ ) {
271+ const composeFiles = yield * _ ( composeFilesForGpuMode ( composePath , gpuMode ) )
272+ const runtimeOverlayPath = yield * _ ( resolveControllerRuntimeOverlayPath ( composePath , dockerRuntime ) )
273+ return { ...composeFiles , runtimeOverlayPath }
274+ } )
275+ )
254276
255277const computeControllerRevision = (
256278 composePath : string ,
257279 gpuMode : ControllerGpuMode ,
258- buildSkillerMode : ControllerBuildSkillerMode
280+ buildSkillerMode : ControllerBuildSkillerMode ,
281+ dockerRuntime : ControllerDockerRuntime
259282) : Effect . Effect < string , ControllerBootstrapError , FileSystem . FileSystem | Path . Path > =>
260283 computeLocalControllerRevision ( composePath ) . pipe (
261284 Effect . mapError ( mapControllerRevisionError ) ,
262- Effect . map ( ( revision ) => controllerRevisionForMode ( revision , gpuMode , buildSkillerMode ) )
285+ Effect . map ( ( revision ) => controllerRevisionForMode ( revision , gpuMode , buildSkillerMode , dockerRuntime ) )
263286 )
264287
265288const persistControllerRevision = ( revision : string ) : Effect . Effect < void > =>
@@ -272,13 +295,13 @@ export const prepareControllerRevision = (): Effect.Effect<
272295 ControllerBootstrapError ,
273296 FileSystem . FileSystem | Path . Path | CommandExecutor . CommandExecutor
274297> =>
275- withComposePathAndGpuMode ( ( { buildSkillerMode, composePath, gpuMode } ) =>
298+ withComposePathAndGpuMode ( ( { buildSkillerMode, composePath, dockerRuntime , gpuMode } ) =>
276299 Effect . gen ( function * ( _ ) {
277300 const path = yield * _ ( Path . Path )
278301 if ( buildSkillerMode === "1" ) {
279302 yield * _ ( ensureSkillerSubmoduleInitialized ( path . dirname ( composePath ) ) )
280303 }
281- return yield * _ ( computeControllerRevision ( composePath , gpuMode , buildSkillerMode ) )
304+ return yield * _ ( computeControllerRevision ( composePath , gpuMode , buildSkillerMode , dockerRuntime ) )
282305 } )
283306 ) . pipe (
284307 Effect . tap ( ( revision ) => persistControllerRevision ( revision ) )
0 commit comments