From 5ce6b905460b3d99035e4c97a852f853b7e929d6 Mon Sep 17 00:00:00 2001 From: broetchenrackete36 <54035716+broetchenrackete36@users.noreply.github.com> Date: Sat, 18 Nov 2023 06:36:57 +0100 Subject: [PATCH] Support compose.y[a]ml and docker-compose.y[a]ml (#55) * Support compose.y[a]ml and docker-compose.y[a]ml * using for-loop to iterate over supported compose filenames * Fix lint --------- Co-authored-by: Louis Lam --- backend/stack.ts | 15 +++++++++++++-- frontend/src/pages/Compose.vue | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/backend/stack.ts b/backend/stack.ts index 94726f00..af1b745e 100644 --- a/backend/stack.ts +++ b/backend/stack.ts @@ -24,6 +24,7 @@ export class Stack { protected _status: number = UNKNOWN; protected _composeYAML?: string; protected _configFilePath?: string; + protected _composeFileName: string = "compose.yaml"; protected server: DockgeServer; protected combinedTerminal? : Terminal; @@ -34,6 +35,15 @@ export class Stack { this.name = name; this.server = server; this._composeYAML = composeYAML; + + // 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) { + if (fs.existsSync(path.join(this.path, filename))) { + this._composeFileName = filename; + break; + } + } } toJSON() : object { @@ -50,6 +60,7 @@ export class Stack { status: this._status, tags: [], isManagedByDockge: this.isManagedByDockge, + composeFileName: this._composeFileName, }; } @@ -84,7 +95,7 @@ export class Stack { get composeYAML() : string { if (this._composeYAML === undefined) { try { - this._composeYAML = fs.readFileSync(path.join(this.path, "compose.yaml"), "utf-8"); + this._composeYAML = fs.readFileSync(path.join(this.path, this._composeFileName), "utf-8"); } catch (e) { this._composeYAML = ""; } @@ -135,7 +146,7 @@ export class Stack { } // Write or overwrite the compose.yaml - fs.writeFileSync(path.join(dir, "compose.yaml"), this.composeYAML); + fs.writeFileSync(path.join(dir, this._composeFileName), this.composeYAML); } async deploy(socket? : DockgeSocket) : Promise { diff --git a/frontend/src/pages/Compose.vue b/frontend/src/pages/Compose.vue index 4ccb0b63..07091064 100644 --- a/frontend/src/pages/Compose.vue +++ b/frontend/src/pages/Compose.vue @@ -118,7 +118,7 @@
-

compose.yaml

+

{{ stack.composeFileName }}