@@ -5,52 +5,50 @@ import type { PlatformError } from "@effect/platform/Error"
55import { Duration , Effect , pipe , Schedule } from "effect"
66
77import { runCommandCapture , runCommandExitCode , runCommandWithExitCodes } from "./command-runner.js"
8+ import { composeSpec , resolveDockerComposeEnv } from "./docker-compose-env.js"
9+ import { parseInspectNetworkEntry } from "./docker-inspect-parse.js"
810import { CommandFailedError , DockerCommandError } from "./errors.js"
911
1012export { classifyDockerAccessIssue , ensureDockerDaemonAccess } from "./docker-daemon-access.js"
1113export { parseDockerPublishedHostPorts , runDockerPsPublishedHostPorts } from "./docker-published-ports.js"
1214
13- const composeSpec = ( cwd : string , args : ReadonlyArray < string > ) => ( {
14- cwd,
15- command : "docker" ,
16- args : [ "compose" , "--ansi" , "never" , "--progress" , "plain" , ...args ]
17- } )
18-
19- const parseInspectNetworkEntry = ( line : string ) : ReadonlyArray < readonly [ string , string ] > => {
20- const idx = line . indexOf ( "=" )
21- if ( idx <= 0 ) {
22- return [ ]
23- }
24- const network = line . slice ( 0 , idx ) . trim ( )
25- const ip = line . slice ( idx + 1 ) . trim ( )
26- if ( network . length === 0 || ip . length === 0 ) {
27- return [ ]
28- }
29- const entry : readonly [ string , string ] = [ network , ip ]
30- return [ entry ]
31- }
32-
3315const runCompose = (
3416 cwd : string ,
3517 args : ReadonlyArray < string > ,
3618 okExitCodes : ReadonlyArray < number >
3719) : Effect . Effect < void , DockerCommandError | PlatformError , CommandExecutor . CommandExecutor > =>
38- runCommandWithExitCodes (
39- composeSpec ( cwd , args ) ,
40- okExitCodes ,
41- ( exitCode ) => new DockerCommandError ( { exitCode } )
42- )
20+ Effect . gen ( function * ( _ ) {
21+ const env = yield * _ ( resolveDockerComposeEnv ( cwd ) )
22+ yield * _ (
23+ runCommandWithExitCodes (
24+ {
25+ ...composeSpec ( cwd , args ) ,
26+ ...( Object . keys ( env ) . length > 0 ? { env } : { } )
27+ } ,
28+ okExitCodes ,
29+ ( exitCode ) => new DockerCommandError ( { exitCode } )
30+ )
31+ )
32+ } )
4333
4434const runComposeCapture = (
4535 cwd : string ,
4636 args : ReadonlyArray < string > ,
4737 okExitCodes : ReadonlyArray < number >
4838) : Effect . Effect < string , DockerCommandError | PlatformError , CommandExecutor . CommandExecutor > =>
49- runCommandCapture (
50- composeSpec ( cwd , args ) ,
51- okExitCodes ,
52- ( exitCode ) => new DockerCommandError ( { exitCode } )
53- )
39+ Effect . gen ( function * ( _ ) {
40+ const env = yield * _ ( resolveDockerComposeEnv ( cwd ) )
41+ return yield * _ (
42+ runCommandCapture (
43+ {
44+ ...composeSpec ( cwd , args ) ,
45+ ...( Object . keys ( env ) . length > 0 ? { env } : { } )
46+ } ,
47+ okExitCodes ,
48+ ( exitCode ) => new DockerCommandError ( { exitCode } )
49+ )
50+ )
51+ } )
5452
5553const dockerComposeUpRetrySchedule = Schedule . addDelay (
5654 Schedule . recurs ( 2 ) ,
0 commit comments