Skip to content

Commit 94ca8a1

Browse files
Ozy-Vikinglouislam
andauthored
Fix: Only adding folders to stack with a compose file. (louislam#299)
Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
1 parent db0add7 commit 94ca8a1

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

backend/stack.ts

+26-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import yaml from "yaml";
55
import { DockgeSocket, fileExists, ValidationError } from "./util-server";
66
import path from "path";
77
import {
8+
acceptedComposeFileNames,
89
COMBINED_TERMINAL_COLS,
910
COMBINED_TERMINAL_ROWS,
1011
CREATED_FILE,
@@ -40,8 +41,7 @@ export class Stack {
4041

4142
if (!skipFSOperations) {
4243
// Check if compose file name is different from compose.yaml
43-
const supportedFileNames = [ "compose.yaml", "compose.yml", "docker-compose.yml", "docker-compose.yaml" ];
44-
for (const filename of supportedFileNames) {
44+
for (const filename of acceptedComposeFileNames) {
4545
if (fs.existsSync(path.join(this.path, filename))) {
4646
this._composeFileName = filename;
4747
break;
@@ -222,6 +222,26 @@ export class Stack {
222222
}
223223
}
224224

225+
/**
226+
* Checks if a compose file exists in the specified directory.
227+
* @async
228+
* @static
229+
* @param {string} stacksDir - The directory of the stack.
230+
* @param {string} filename - The name of the directory to check for the compose file.
231+
* @returns {Promise<boolean>} A promise that resolves to a boolean indicating whether any compose file exists.
232+
*/
233+
static async composeFileExists(stacksDir : string, filename : string) : Promise<boolean> {
234+
let filenamePath = path.join(stacksDir, filename);
235+
// Check if any compose file exists
236+
for (const filename of acceptedComposeFileNames) {
237+
let composeFile = path.join(filenamePath, filename);
238+
if (await fileExists(composeFile)) {
239+
return true;
240+
}
241+
}
242+
return false;
243+
}
244+
225245
static async getStackList(server : DockgeServer, useCacheForManaged = false) : Promise<Map<string, Stack>> {
226246
let stacksDir = server.stacksDir;
227247
let stackList : Map<string, Stack>;
@@ -242,6 +262,10 @@ export class Stack {
242262
if (!stat.isDirectory()) {
243263
continue;
244264
}
265+
// If no compose file exists, skip it
266+
if (!await Stack.composeFileExists(stacksDir, filename)) {
267+
continue;
268+
}
245269
let stack = await this.getStack(server, filename);
246270
stack._status = CREATED_FILE;
247271
stackList.set(filename, stack);

backend/util-common.ts

+7
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ export const allowedRawKeys = [
116116
"\u0003", // Ctrl + C
117117
];
118118

119+
export const acceptedComposeFileNames = [
120+
"compose.yaml",
121+
"docker-compose.yaml",
122+
"docker-compose.yml",
123+
"compose.yml",
124+
];
125+
119126
/**
120127
* Generate a decimal integer number from a string
121128
* @param str Input

0 commit comments

Comments
 (0)