-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathdocker-host.ts
More file actions
52 lines (48 loc) · 1.92 KB
/
docker-host.ts
File metadata and controls
52 lines (48 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Optional override for the Docker host used by AWF's own container operations.
* Set via setAwfDockerHost() from the CLI --docker-host flag.
* When undefined, AWF auto-selects the local socket (see getLocalDockerEnv).
*/
let awfDockerHostOverride: string | undefined;
/**
* Sets the Docker host to use for AWF's own container operations.
*
* When set, overrides DOCKER_HOST for all docker CLI calls made by AWF
* (compose up/down, docker wait, docker logs, etc.).
*
* When not set, AWF auto-detects:
* - unix:// DOCKER_HOST values are kept as-is (local socket).
* - TCP DOCKER_HOST values (e.g. DinD) are cleared so docker falls back
* to the system default socket.
*
* @internal Called from cli.ts when --docker-host flag is provided.
*/
export function setAwfDockerHost(host: string | undefined): void {
awfDockerHostOverride = host;
}
/**
* Returns an environment object suitable for AWF's own docker CLI calls.
*
* When DOCKER_HOST is set to an external TCP daemon (e.g. a workflow-scope
* DinD sidecar), it is removed so docker/docker-compose use the local Unix
* socket instead. When --docker-host was provided via the CLI, that value
* is used regardless of the environment.
*
* The original DOCKER_HOST value is NOT removed from the agent container's
* environment — see generateDockerCompose for the passthrough logic.
*/
export function getLocalDockerEnv(): NodeJS.ProcessEnv {
const env = { ...process.env };
if (awfDockerHostOverride !== undefined) {
// Explicit CLI override — always use this socket for AWF operations
env.DOCKER_HOST = awfDockerHostOverride;
} else {
const dockerHost = env.DOCKER_HOST;
if (dockerHost && !dockerHost.startsWith('unix://')) {
// Non-unix DOCKER_HOST (e.g. tcp://localhost:2375 from a DinD sidecar).
// Clear it so AWF's docker commands target the local daemon, not the DinD one.
delete env.DOCKER_HOST;
}
}
return env;
}