File tree 3 files changed +32
-16
lines changed
3 files changed +32
-16
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { ProxySettingCallback } from 'mockttp';
4
4
import { logError } from '../../error-tracking' ;
5
5
import { addShutdownHandler } from '../../shutdown' ;
6
6
7
+ import { getDockerAddress } from './docker-utils' ;
7
8
import { DOCKER_BUILD_LABEL } from './docker-build-injection' ;
8
9
import { DOCKER_CONTAINER_LABEL } from './docker-commands' ;
9
10
@@ -76,9 +77,16 @@ export async function startDockerInterceptionServices(
76
77
}
77
78
78
79
// Log if Docker was not available at proxy start, and why, for debugging later:
79
- isDockerAvailable ( { logError : true } ) . then ( ( isAvailable ) => {
80
- if ( isAvailable ) console . log ( 'Connected to Docker' ) ;
81
- // logError will log the specific not-available error, if this failed
80
+ isDockerAvailable ( { logError : true } ) . then ( async ( isAvailable ) => {
81
+ if ( isAvailable ) {
82
+ const dockerAddress = await getDockerAddress ( new Docker ( ) ) ;
83
+ console . log ( `Connected to Docker at ${
84
+ 'socketPath' in dockerAddress
85
+ ? dockerAddress . socketPath
86
+ : `tcp://${ dockerAddress . host } :${ dockerAddress . port } `
87
+ } `) ;
88
+ }
89
+ // logError:true will log the specific not-available error, if this failed
82
90
} ) ;
83
91
84
92
const networkMonitor = monitorDockerNetworkAliases ( proxyPort ) ;
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import { streamToBuffer } from '../../util/stream';
14
14
import { logError } from '../../error-tracking' ;
15
15
import { addShutdownHandler } from '../../shutdown' ;
16
16
17
+ import { getDockerAddress } from './docker-utils' ;
17
18
import {
18
19
isInterceptedContainer ,
19
20
transformContainerCreationConfig
@@ -76,18 +77,7 @@ async function createDockerProxy(
76
77
) {
77
78
const docker = new Dockerode ( ) ;
78
79
79
- // Hacky logic to reuse docker-modem's internal env + OS parsing logic to
80
- // work out where the local Docker host is:
81
- const modem = docker . modem as any as ( {
82
- getSocketPath ( ) : undefined | Promise < string > ;
83
- host : string ;
84
- port : number ;
85
- } ) ;
86
-
87
- const modemSocketPath = await modem . getSocketPath ( ) ;
88
- const dockerHostOptions = modemSocketPath
89
- ? { socketPath : modemSocketPath }
90
- : { host : modem . host , port : modem . port } ;
80
+ const dockerHostOptions = await getDockerAddress ( docker ) ;
91
81
92
82
const agent = new http . Agent ( { keepAlive : true } ) ;
93
83
Original file line number Diff line number Diff line change @@ -15,4 +15,22 @@ export const waitForDockerStream = (
15
15
16
16
resolve ( ) ;
17
17
} ) ;
18
- } ) ;
18
+ } ) ;
19
+
20
+ export const getDockerAddress = async ( docker : Docker ) : Promise <
21
+ | { socketPath : string }
22
+ | { host : string , port : number }
23
+ > => {
24
+ // Hacky logic to reuse docker-modem's internal env + OS parsing logic to
25
+ // work out where the local Docker host is:
26
+ const modem = docker . modem as any as ( {
27
+ getSocketPath ( ) : undefined | Promise < string > ;
28
+ host : string ;
29
+ port : number ;
30
+ } ) ;
31
+
32
+ const modemSocketPath = await modem . getSocketPath ( ) ;
33
+ return modemSocketPath
34
+ ? { socketPath : modemSocketPath }
35
+ : { host : modem . host , port : modem . port } ;
36
+ }
You can’t perform that action at this time.
0 commit comments