@@ -119,10 +119,24 @@ const stub = (name: string) => async (): Promise<void> => {
119119 * Resolve project paths
120120 */
121121function resolvePaths ( ) : PathResolution {
122- const projectDir = process . cwd ( ) ;
123- const composeFile = path . resolve ( projectDir , "docker-compose.yml" ) ;
124- const instancesFile = path . resolve ( projectDir , "instances.yml" ) ;
125- return { fs, path, projectDir, composeFile, instancesFile } ;
122+ const startDir = process . cwd ( ) ;
123+ let currentDir = startDir ;
124+
125+ while ( true ) {
126+ const composeFile = path . resolve ( currentDir , "docker-compose.yml" ) ;
127+ if ( fs . existsSync ( composeFile ) ) {
128+ const instancesFile = path . resolve ( currentDir , "instances.yml" ) ;
129+ return { fs, path, projectDir : currentDir , composeFile, instancesFile } ;
130+ }
131+
132+ const parentDir = path . dirname ( currentDir ) ;
133+ if ( parentDir === currentDir ) break ;
134+ currentDir = parentDir ;
135+ }
136+
137+ throw new Error (
138+ `docker-compose.yml not found. Run monitoring commands from the PostgresAI project directory or one of its subdirectories (starting search from ${ startDir } ).`
139+ ) ;
126140}
127141
128142/**
@@ -140,7 +154,15 @@ function getComposeCmd(): string[] | null {
140154 * Run docker compose command
141155 */
142156async function runCompose ( args : string [ ] ) : Promise < number > {
143- const { composeFile } = resolvePaths ( ) ;
157+ let composeFile : string ;
158+ try {
159+ ( { composeFile } = resolvePaths ( ) ) ;
160+ } catch ( error ) {
161+ const message = error instanceof Error ? error . message : String ( error ) ;
162+ console . error ( message ) ;
163+ process . exitCode = 1 ;
164+ return 1 ;
165+ }
144166 const cmd = getComposeCmd ( ) ;
145167 if ( ! cmd ) {
146168 console . error ( "docker compose not found (need docker-compose or docker compose)" ) ;
287309 . command ( "config" )
288310 . description ( "show monitoring services configuration" )
289311 . action ( async ( ) => {
290- const { fs, projectDir, composeFile, instancesFile } = resolvePaths ( ) ;
312+ let projectDir : string ;
313+ let composeFile : string ;
314+ let instancesFile : string ;
315+ try {
316+ ( { projectDir, composeFile, instancesFile } = resolvePaths ( ) ) ;
317+ } catch ( error ) {
318+ const message = error instanceof Error ? error . message : String ( error ) ;
319+ console . error ( message ) ;
320+ process . exitCode = 1 ;
321+ return ;
322+ }
291323 console . log ( `Project Directory: ${ projectDir } ` ) ;
292324 console . log ( `Docker Compose File: ${ composeFile } ` ) ;
293325 console . log ( `Instances File: ${ instancesFile } ` ) ;
0 commit comments