Skip to content

Commit

Permalink
Support compose.y[a]ml and docker-compose.y[a]ml (#55)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
broetchenrackete36 and louislam authored Nov 18, 2023
1 parent a488518 commit 5ce6b90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions backend/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -50,6 +60,7 @@ export class Stack {
status: this._status,
tags: [],
isManagedByDockge: this.isManagedByDockge,
composeFileName: this._composeFileName,
};
}

Expand Down Expand Up @@ -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 = "";
}
Expand Down Expand Up @@ -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<number> {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Compose.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
</div>
</div>
<div class="col-lg-6">
<h4 class="mb-3">compose.yaml</h4>
<h4 class="mb-3">{{ stack.composeFileName }}</h4>

<!-- YAML editor -->
<div class="shadow-box mb-3 editor-box" :class="{'edit-mode' : isEditMode}">
Expand Down

0 comments on commit 5ce6b90

Please sign in to comment.