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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ContainerRuntimeClient, getContainerRuntimeClient, ImageName } from "..
import { CONTAINER_STATUSES } from "../container-runtime/clients/container/types";
import { StartedNetwork } from "../network/network";
import { PortForwarderInstance, SSHD_IMAGE } from "../port-forwarder/port-forwarder";
import { getReaper, REAPER_IMAGE } from "../reaper/reaper";
import { getReaper, getReaperImage } from "../reaper/reaper";
import { StartedTestContainer, TestContainer } from "../test-container";
import {
ArchiveToCopy,
Expand Down Expand Up @@ -70,15 +70,15 @@ export class GenericContainer implements TestContainer {
constructor(image: string) {
this.imageName = ImageName.fromString(image);
this.createOpts = { Image: this.imageName.string };
this.hostConfig = { AutoRemove: this.imageName.string === REAPER_IMAGE };
this.hostConfig = { AutoRemove: this.imageName.string === getReaperImage() };
}

private isHelperContainer() {
return this.isReaper() || this.imageName.string === SSHD_IMAGE;
}

private isReaper() {
return this.imageName.string === REAPER_IMAGE;
return this.imageName.string === getReaperImage();
}

protected beforeContainerCreated?(): Promise<void>;
Expand Down
17 changes: 13 additions & 4 deletions packages/testcontainers/src/reaper/reaper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ import { GenericContainer } from "../generic-container/generic-container";
import { LABEL_TESTCONTAINERS_RYUK, LABEL_TESTCONTAINERS_SESSION_ID } from "../utils/labels";
import { Wait } from "../wait-strategies/wait";

export const REAPER_IMAGE = process.env["RYUK_CONTAINER_IMAGE"]
? ImageName.fromString(process.env["RYUK_CONTAINER_IMAGE"]).string
: ImageName.fromString("testcontainers/ryuk:0.14.0").string;
/**
* Resolve the Ryuk reaper image name. Read lazily so that callers (and tests)
* can set `process.env.RYUK_CONTAINER_IMAGE` _after_ this module is imported —
* including via `.env` files loaded by `dotenv` at runtime.
*
* See https://github.com/testcontainers/testcontainers-node/issues/1310.
*/
export function getReaperImage(): string {
return process.env["RYUK_CONTAINER_IMAGE"]
? ImageName.fromString(process.env["RYUK_CONTAINER_IMAGE"]).string
: ImageName.fromString("testcontainers/ryuk:0.14.0").string;
}

export interface Reaper {
sessionId: string;
Expand Down Expand Up @@ -87,7 +96,7 @@ async function useExistingReaper(reaperContainer: ContainerInfo, sessionId: stri
async function createNewReaper(sessionId: string, remoteSocketPath: string): Promise<Reaper> {
log.debug(`Creating new Reaper for session "${sessionId}" with socket path "${remoteSocketPath}"...`);

const container = new GenericContainer(REAPER_IMAGE)
const container = new GenericContainer(getReaperImage())
.withName(`testcontainers-ryuk-${sessionId}`)
.withExposedPorts(
process.env["TESTCONTAINERS_RYUK_PORT"]
Expand Down
Loading