diff --git a/backend/stack.ts b/backend/stack.ts index 536ee50..1fbfa13 100644 --- a/backend/stack.ts +++ b/backend/stack.ts @@ -5,6 +5,7 @@ import yaml from "yaml"; import { DockgeSocket, fileExists, ValidationError } from "./util-server"; import path from "path"; import { + acceptedComposeFileNames, COMBINED_TERMINAL_COLS, COMBINED_TERMINAL_ROWS, CREATED_FILE, @@ -40,8 +41,7 @@ export class Stack { if (!skipFSOperations) { // Check if compose file name is different from compose.yaml - const supportedFileNames = [ "compose.yaml", "compose.yml", "docker-compose.yml", "docker-compose.yaml" ]; - for (const filename of supportedFileNames) { + for (const filename of acceptedComposeFileNames) { if (fs.existsSync(path.join(this.path, filename))) { this._composeFileName = filename; break; @@ -222,6 +222,26 @@ export class Stack { } } + /** + * Checks if a compose file exists in the specified directory. + * @async + * @static + * @param {string} stacksDir - The directory of the stack. + * @param {string} filename - The name of the directory to check for the compose file. + * @returns {Promise} A promise that resolves to a boolean indicating whether any compose file exists. + */ + static async composeFileExists(stacksDir : string, filename : string) : Promise { + let filenamePath = path.join(stacksDir, filename); + // Check if any compose file exists + for (const filename of acceptedComposeFileNames) { + let composeFile = path.join(filenamePath, filename); + if (await fileExists(composeFile)) { + return true; + } + } + return false; + } + static async getStackList(server : DockgeServer, useCacheForManaged = false) : Promise> { let stacksDir = server.stacksDir; let stackList : Map; @@ -242,6 +262,10 @@ export class Stack { if (!stat.isDirectory()) { continue; } + // If no compose file exists, skip it + if (!await Stack.composeFileExists(stacksDir, filename)) { + continue; + } let stack = await this.getStack(server, filename); stack._status = CREATED_FILE; stackList.set(filename, stack); diff --git a/backend/util-common.ts b/backend/util-common.ts index ddbcc65..433994c 100644 --- a/backend/util-common.ts +++ b/backend/util-common.ts @@ -116,6 +116,13 @@ export const allowedRawKeys = [ "\u0003", // Ctrl + C ]; +export const acceptedComposeFileNames = [ + "compose.yaml", + "docker-compose.yaml", + "docker-compose.yml", + "compose.yml", +]; + /** * Generate a decimal integer number from a string * @param str Input