Skip to content

Commit 3e12381

Browse files
authored
fix(docker): improve container start and update handling (#1339)
1 parent 8863cc5 commit 3e12381

File tree

3 files changed

+399
-35
lines changed

3 files changed

+399
-35
lines changed

alchemy/src/docker/api.ts

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,44 @@ type VolumeInfo = {
6969
Scope: string;
7070
};
7171

72-
type ContainerInfo = {
72+
export type ContainerInfo = {
7373
Id: string;
7474
State: { Status: "created" | "running" | "paused" | "stopped" | "exited" };
7575
Created: string;
76+
Config: {
77+
Image: string;
78+
Cmd: string[] | null;
79+
Env: string[] | null;
80+
Healthcheck?: {
81+
Test: string[] | null;
82+
Interval?: number;
83+
Timeout?: number;
84+
Retries?: number;
85+
StartPeriod?: number;
86+
StartInterval?: number;
87+
} | null;
88+
};
89+
HostConfig: {
90+
PortBindings: Record<
91+
string,
92+
Array<{ HostIp: string; HostPort: string }> | null
93+
> | null;
94+
Binds: string[] | null;
95+
RestartPolicy: {
96+
Name: string;
97+
MaximumRetryCount: number;
98+
};
99+
AutoRemove: boolean;
100+
};
101+
NetworkSettings: {
102+
Networks: Record<
103+
string,
104+
{
105+
NetworkID: string;
106+
Aliases: string[] | null;
107+
}
108+
> | null;
109+
};
76110
};
77111

78112
/**
@@ -103,6 +137,7 @@ export class DockerApi {
103137
async exec(
104138
args: string[],
105139
remainingAttempts = 3,
140+
quiet = false,
106141
): Promise<{ stdout: string; stderr: string }> {
107142
// If a custom config directory is provided, ensure all commands use it by
108143
// setting the DOCKER_CONFIG env variable for the spawned process.
@@ -124,13 +159,17 @@ export class DockerApi {
124159

125160
// Stream stdout in real-time
126161
subprocess.stdout?.on("data", (chunk: string) => {
127-
process.stdout.write(chunk);
162+
if (!quiet) {
163+
process.stdout.write(chunk);
164+
}
128165
stdout += chunk;
129166
});
130167

131168
// Stream stderr in real-time
132169
subprocess.stderr?.on("data", (chunk: string) => {
133-
process.stderr.write(chunk);
170+
if (!quiet) {
171+
process.stderr.write(chunk);
172+
}
134173
stderr += chunk;
135174
});
136175

@@ -364,7 +403,11 @@ export class DockerApi {
364403
* @returns Container details in JSON format
365404
*/
366405
async inspectContainer(containerId: string): Promise<ContainerInfo[]> {
367-
const { stdout } = await this.exec(["container", "inspect", containerId]);
406+
const { stdout } = await this.exec(
407+
["container", "inspect", containerId],
408+
undefined,
409+
true,
410+
);
368411
try {
369412
return JSON.parse(stdout.trim()) as ContainerInfo[];
370413
} catch (_error) {

0 commit comments

Comments
 (0)