forked from extern/dockge
Fix: Only adding folders to stack with a compose file. (#299)
Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
This commit is contained in:
parent
db0add7e4c
commit
94ca8a152a
@ -5,6 +5,7 @@ import yaml from "yaml";
|
|||||||
import { DockgeSocket, fileExists, ValidationError } from "./util-server";
|
import { DockgeSocket, fileExists, ValidationError } from "./util-server";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import {
|
import {
|
||||||
|
acceptedComposeFileNames,
|
||||||
COMBINED_TERMINAL_COLS,
|
COMBINED_TERMINAL_COLS,
|
||||||
COMBINED_TERMINAL_ROWS,
|
COMBINED_TERMINAL_ROWS,
|
||||||
CREATED_FILE,
|
CREATED_FILE,
|
||||||
@ -40,8 +41,7 @@ export class Stack {
|
|||||||
|
|
||||||
if (!skipFSOperations) {
|
if (!skipFSOperations) {
|
||||||
// Check if compose file name is different from compose.yaml
|
// 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 acceptedComposeFileNames) {
|
||||||
for (const filename of supportedFileNames) {
|
|
||||||
if (fs.existsSync(path.join(this.path, filename))) {
|
if (fs.existsSync(path.join(this.path, filename))) {
|
||||||
this._composeFileName = filename;
|
this._composeFileName = filename;
|
||||||
break;
|
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<boolean>} A promise that resolves to a boolean indicating whether any compose file exists.
|
||||||
|
*/
|
||||||
|
static async composeFileExists(stacksDir : string, filename : string) : Promise<boolean> {
|
||||||
|
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<Map<string, Stack>> {
|
static async getStackList(server : DockgeServer, useCacheForManaged = false) : Promise<Map<string, Stack>> {
|
||||||
let stacksDir = server.stacksDir;
|
let stacksDir = server.stacksDir;
|
||||||
let stackList : Map<string, Stack>;
|
let stackList : Map<string, Stack>;
|
||||||
@ -242,6 +262,10 @@ export class Stack {
|
|||||||
if (!stat.isDirectory()) {
|
if (!stat.isDirectory()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// If no compose file exists, skip it
|
||||||
|
if (!await Stack.composeFileExists(stacksDir, filename)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let stack = await this.getStack(server, filename);
|
let stack = await this.getStack(server, filename);
|
||||||
stack._status = CREATED_FILE;
|
stack._status = CREATED_FILE;
|
||||||
stackList.set(filename, stack);
|
stackList.set(filename, stack);
|
||||||
|
@ -116,6 +116,13 @@ export const allowedRawKeys = [
|
|||||||
"\u0003", // Ctrl + C
|
"\u0003", // Ctrl + C
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const acceptedComposeFileNames = [
|
||||||
|
"compose.yaml",
|
||||||
|
"docker-compose.yaml",
|
||||||
|
"docker-compose.yml",
|
||||||
|
"compose.yml",
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a decimal integer number from a string
|
* Generate a decimal integer number from a string
|
||||||
* @param str Input
|
* @param str Input
|
||||||
|
Loading…
Reference in New Issue
Block a user