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 <louislam@users.noreply.github.com>
This commit is contained in:
broetchenrackete36 2023-11-18 06:36:57 +01:00 committed by GitHub
parent a488518f6e
commit 5ce6b90546
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View file

@ -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<number> {

View file

@ -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}">