@@ -11,9 +11,9 @@ import { spawn, exec, spawnSync, execSync } from "node:child_process";
1111 */
1212export function runDockerContainerAndWait ( name : string , args : string [ ] , logLine : string ) : string {
1313 // kill any old container that might be running from previous builds
14- // spawnSync("docker", ["rm", "-f", name]) TODO
14+ spawnSync ( "docker" , [ "rm" , "-f" , name ] )
1515 // Start the container in detached mode
16- console . log ( "Spawning Docker container..." , name , args ) ;
16+ console . log ( "Spawning Docker container..." , name , args , logLine ) ;
1717 const dockerRun = spawnSync ( "docker" , args ) ;
1818 if ( dockerRun . error ) {
1919 console . error ( `Failed to start Docker process: ${ dockerRun . error } ` ) ;
@@ -32,9 +32,10 @@ export function runDockerContainerAndWait(name: string, args: string[], logLine:
3232 // Wait for the container to be running
3333 console . log ( "Waiting for container to be ready..." ) ;
3434 waitForContainer ( containerId ) ;
35- console . log ( "Container is ready. Waiting for log line..." ) ;
36- waitForLogLine ( containerId , logLine ) ;
37- console . log ( "Log line found." ) ;
35+ console . log ( "Container is ready" ) ;
36+ // waitForLogLine(containerId, logLine);
37+ // console.log("Log line found.");
38+ // TODO - rm -f container if it didn't run successfully
3839 return containerId ;
3940}
4041
@@ -48,6 +49,7 @@ function waitForContainer(containerId: string) {
4849 const stdout = execSync ( `docker inspect -f '{{.State.Running}}' ${ containerId } ` )
4950 if ( stdout . toString ( ) . trim ( ) === "true" ) {
5051 console . log ( `Container ${ containerId } is running.` ) ;
52+ sleep ( 60000 ) ;
5153 return ;
5254 }
5355 console . log ( `Container ${ containerId } is not yet running.` ) ;
@@ -62,32 +64,33 @@ function waitForContainer(containerId: string) {
6264 * @param containerId - The container ID.
6365 * @param logLine - The line to wait for.
6466 */
65- function waitForLogLine ( containerId : string , logLine : string ) {
66- let attempts = 60 ;
67- while ( attempts > 0 ) {
68- const logProcess = spawnSync ( "docker" , [ "logs" , containerId ] ) ;
69- if ( logProcess . error ) {
70- const message = `Failed to get container logs: ${ containerId } ${ logProcess . error } ` ;
71- console . error ( message ) ;
72- throw new Error ( message ) ;
73- }
74- if ( logProcess . status !== 0 ) {
75- const message = `Docker process exited with code ${ logProcess . status } , ${ logProcess . stderr . toString ( ) } ` ;
76- console . error ( message ) ;
77- throw new Error ( message ) ;
78- }
67+ // function waitForLogLine(containerId: string, logLine: string) {
68+ // let attempts = 60;
69+ // while (attempts > 0) {
70+ // console.log(`Checking logs for ${containerId}... ${attempts} attempts remaining.`);
71+ // const logProcess = spawnSync("docker", ["logs", containerId]);
72+ // if (logProcess.error) {
73+ // const message = `Failed to get container logs: ${containerId} ${logProcess.error}`;
74+ // console.error(message);
75+ // throw new Error(message);
76+ // }
77+ // if (logProcess.status !== 0) {
78+ // const message = `Docker process exited with code ${logProcess.status}, ${logProcess.stderr.toString()}`;
79+ // console.error(message);
80+ // throw new Error(message);
81+ // }
7982
80- const logs = logProcess . stdout . toString ( ) ;
81- console . log ( 'LOGS' , logs ) ;
82- if ( logs . includes ( logLine ) ) {
83- return ;
84- }
85- attempts -- ;
86- sleep ( 1000 ) ;
87- }
83+ // const logs = logProcess.stdout.toString();
84+ // console.log('LOGS', logs);
85+ // if (logs.includes(logLine)) {
86+ // return;
87+ // }
88+ // attempts--;
89+ // sleep(1000);
90+ // }
8891
89- throw new Error ( `Log line not found: ${ logLine } ` ) ;
90- }
92+ // throw new Error(`Log line not found: ${logLine}`);
93+ // }
9194
9295/**
9396 * Stops the container.
0 commit comments