Browse Source

Support compose.y[a]ml and docker-compose.y[a]ml

broetchenrackete36 1 year ago
parent
commit
ac9408d3eb
2 changed files with 14 additions and 3 deletions
  1. 13 2
      backend/stack.ts
  2. 1 1
      frontend/src/pages/Compose.vue

+ 13 - 2
backend/stack.ts

@@ -24,6 +24,7 @@ export class Stack {
     protected _status: number = UNKNOWN;
     protected _status: number = UNKNOWN;
     protected _composeYAML?: string;
     protected _composeYAML?: string;
     protected _configFilePath?: string;
     protected _configFilePath?: string;
+    protected _composeFileName: string = "compose.yaml";
     protected server: DockgeServer;
     protected server: DockgeServer;
 
 
     protected combinedTerminal? : Terminal;
     protected combinedTerminal? : Terminal;
@@ -34,6 +35,15 @@ export class Stack {
         this.name = name;
         this.name = name;
         this.server = server;
         this.server = server;
         this._composeYAML = composeYAML;
         this._composeYAML = composeYAML;
+
+        // Check if compose file name is different from compose.yaml
+        if (fs.existsSync(path.join(this.path, "compose.yml"))){
+            this._composeFileName = "compose.yml";
+        } else if (fs.existsSync(path.join(this.path, "docker-compose.yml"))){
+            this._composeFileName = "docker-compose.yml";
+        } else if (fs.existsSync(path.join(this.path, "docker-compose.yaml"))){
+            this._composeFileName = "docker-compose.yaml";
+        }
     }
     }
 
 
     toJSON() : object {
     toJSON() : object {
@@ -50,6 +60,7 @@ export class Stack {
             status: this._status,
             status: this._status,
             tags: [],
             tags: [],
             isManagedByDockge: this.isManagedByDockge,
             isManagedByDockge: this.isManagedByDockge,
+            composeFileName: this._composeFileName,
         };
         };
     }
     }
 
 
@@ -84,7 +95,7 @@ export class Stack {
     get composeYAML() : string {
     get composeYAML() : string {
         if (this._composeYAML === undefined) {
         if (this._composeYAML === undefined) {
             try {
             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) {
             } catch (e) {
                 this._composeYAML = "";
                 this._composeYAML = "";
             }
             }
@@ -135,7 +146,7 @@ export class Stack {
         }
         }
 
 
         // Write or overwrite the compose.yaml
         // 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<number> {
     async deploy(socket? : DockgeSocket) : Promise<number> {

+ 1 - 1
frontend/src/pages/Compose.vue

@@ -118,7 +118,7 @@
                     </div>
                     </div>
                 </div>
                 </div>
                 <div class="col-lg-6">
                 <div class="col-lg-6">
-                    <h4 class="mb-3">compose.yaml</h4>
+                    <h4 class="mb-3">{{ stack.composeFileName }}</h4>
 
 
                     <!-- YAML editor -->
                     <!-- YAML editor -->
                     <div class="shadow-box mb-3 editor-box" :class="{'edit-mode' : isEditMode}">
                     <div class="shadow-box mb-3 editor-box" :class="{'edit-mode' : isEditMode}">