@@ -3,7 +3,7 @@ import { Socket } from "net";
33import { IntervalRetry , log , RandomUuid , withFileLock } from "../common" ;
44import { ContainerRuntimeClient , ImageName } from "../container-runtime" ;
55import { GenericContainer } from "../generic-container/generic-container" ;
6- import { LABEL_TESTCONTAINERS_SESSION_ID } from "../utils/labels" ;
6+ import { LABEL_TESTCONTAINERS_RYUK , LABEL_TESTCONTAINERS_SESSION_ID } from "../utils/labels" ;
77import { Wait } from "../wait-strategies/wait" ;
88
99export const REAPER_IMAGE = process . env [ "RYUK_CONTAINER_IMAGE" ]
@@ -13,6 +13,8 @@ export const REAPER_IMAGE = process.env["RYUK_CONTAINER_IMAGE"]
1313export interface Reaper {
1414 sessionId : string ;
1515
16+ containerId : string ;
17+
1618 addSession ( sessionId : string ) : void ;
1719
1820 addComposeProject ( projectName : string ) : void ;
@@ -28,10 +30,10 @@ export async function getReaper(client: ContainerRuntimeClient): Promise<Reaper>
2830
2931 reaper = await withFileLock ( "testcontainers-node.lock" , async ( ) => {
3032 const reaperContainer = await findReaperContainer ( client ) ;
31- sessionId = reaperContainer ?. Labels [ "org.testcontainers.session-id" ] ?? new RandomUuid ( ) . nextUuid ( ) ;
33+ sessionId = reaperContainer ?. Labels [ LABEL_TESTCONTAINERS_SESSION_ID ] ?? new RandomUuid ( ) . nextUuid ( ) ;
3234
3335 if ( process . env . TESTCONTAINERS_RYUK_DISABLED === "true" ) {
34- return new DisabledReaper ( sessionId ) ;
36+ return new DisabledReaper ( sessionId , "" ) ;
3537 } else if ( reaperContainer ) {
3638 return await useExistingReaper ( reaperContainer , sessionId , client . info . containerRuntime . host ) ;
3739 } else {
@@ -46,7 +48,7 @@ export async function getReaper(client: ContainerRuntimeClient): Promise<Reaper>
4648async function findReaperContainer ( client : ContainerRuntimeClient ) : Promise < ContainerInfo | undefined > {
4749 const containers = await client . container . list ( ) ;
4850 return containers . find (
49- ( container ) => container . State === "running" && container . Labels [ "org.testcontainers.ryuk" ] === "true"
51+ ( container ) => container . State === "running" && container . Labels [ LABEL_TESTCONTAINERS_RYUK ] === "true"
5052 ) ;
5153}
5254
@@ -60,7 +62,7 @@ async function useExistingReaper(reaperContainer: ContainerInfo, sessionId: stri
6062
6163 const socket = await connectToReaperSocket ( host , reaperPort , reaperContainer . Id ) ;
6264
63- return new RyukReaper ( sessionId , socket ) ;
65+ return new RyukReaper ( sessionId , reaperContainer . Id , socket ) ;
6466}
6567
6668async function createNewReaper ( sessionId : string , remoteSocketPath : string ) : Promise < Reaper > {
@@ -76,6 +78,8 @@ async function createNewReaper(sessionId: string, remoteSocketPath: string): Pro
7678 . withBindMounts ( [ { source : remoteSocketPath , target : "/var/run/docker.sock" } ] )
7779 . withLabels ( { [ LABEL_TESTCONTAINERS_SESSION_ID ] : sessionId } )
7880 . withWaitStrategy ( Wait . forLogMessage ( / .* S t a r t e d .* / ) ) ;
81+ if ( process . env [ "TESTCONTAINERS_RYUK_VERBOSE" ] )
82+ container . withEnvironment ( { RYUK_VERBOSE : process . env [ "TESTCONTAINERS_RYUK_VERBOSE" ] } ) ;
7983
8084 if ( process . env . TESTCONTAINERS_RYUK_PRIVILEGED === "true" ) {
8185 container . withPrivilegedMode ( ) ;
@@ -89,7 +93,7 @@ async function createNewReaper(sessionId: string, remoteSocketPath: string): Pro
8993 startedContainer . getId ( )
9094 ) ;
9195
92- return new RyukReaper ( sessionId , socket ) ;
96+ return new RyukReaper ( sessionId , startedContainer . getId ( ) , socket ) ;
9397}
9498
9599async function connectToReaperSocket ( host : string , port : number , containerId : string ) : Promise < Socket > {
@@ -135,6 +139,7 @@ async function connectToReaperSocket(host: string, port: number, containerId: st
135139class RyukReaper implements Reaper {
136140 constructor (
137141 public readonly sessionId : string ,
142+ public readonly containerId : string ,
138143 private readonly socket : Socket
139144 ) { }
140145
@@ -148,7 +153,10 @@ class RyukReaper implements Reaper {
148153}
149154
150155class DisabledReaper implements Reaper {
151- constructor ( public readonly sessionId : string ) { }
156+ constructor (
157+ public readonly sessionId : string ,
158+ public readonly containerId : string
159+ ) { }
152160
153161 addComposeProject ( ) : void { }
154162
0 commit comments