Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/modules/kafka/src/kafka-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe("KafkaContainer", { timeout: 240_000 }, () => {

const kafkaCliContainer = await new GenericContainer(KAFKA_IMAGE)
.withNetwork(network)
.withCommand(["bash", "-c", "echo 'START'; sleep infinity"])
.withCommand(["bash", "-c", "sleep infinity"])
.withCopyFilesToContainer([
{
source: path.resolve(certificatesDir, "kafka.client.truststore.pem"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("LocalStackContainer", { timeout: 180_000 }, () => {
const awsCliInDockerNetwork = await new GenericContainer("amazon/aws-cli:2.7.27")
.withNetwork(network)
.withEntrypoint(["bash"])
.withCommand(["-c", "echo 'START'; sleep infinity"])
.withCommand(["-c", "sleep infinity"])
.withEnvironment({
AWS_ACCESS_KEY_ID: "test",
AWS_SECRET_ACCESS_KEY: "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,35 @@ export class DockerContainerClient implements ContainerClient {
}
}

async logs(container: Container, opts?: ContainerLogsOptions): Promise<Readable> {
try {
log.debug(`Fetching container logs...`, { containerId: container.id });
const stream = (await container.logs({
logs(container: Container, opts?: ContainerLogsOptions): Promise<Readable> {
log.debug(`Fetching container logs...`, { containerId: container.id });

const proxyStream = new PassThrough();
proxyStream.setEncoding("utf8");

container
.logs({
follow: true,
stdout: true,
stderr: true,
tail: opts?.tail ?? -1,
since: opts?.since ?? 0,
})) as IncomingMessage;
stream.socket.unref();
const demuxedStream = this.demuxStream(container.id, stream);
log.debug(`Fetched container logs`, { containerId: container.id });
return demuxedStream;
} catch (err) {
log.error(`Failed to fetch container logs: ${err}`, { containerId: container.id });
throw err;
}
})
.then(async (stream) => {
const actualLogStream = stream as IncomingMessage;
actualLogStream.socket?.unref();

const demuxedStream = await this.demuxStream(container.id, actualLogStream);
demuxedStream.pipe(proxyStream);
demuxedStream.on("error", (err) => proxyStream.emit("error", err));
demuxedStream.on("end", () => proxyStream.end());
})
.catch((err) => {
log.error(`Failed to fetch container logs: ${err}`, { containerId: container.id });
proxyStream.end();
});

return Promise.resolve(proxyStream);
}

async exec(container: Container, command: string[], opts?: Partial<ExecOptions>): Promise<ExecResult> {
Expand Down