* Save the stack to the disk * @param isAdd
(isAdd : boolean)
| 176 | * @param isAdd |
| 177 | */ |
| 178 | async save(isAdd : boolean) { |
| 179 | this.validate(); |
| 180 | |
| 181 | let dir = this.path; |
| 182 | |
| 183 | // Check if the name is used if isAdd |
| 184 | if (isAdd) { |
| 185 | if (await fileExists(dir)) { |
| 186 | throw new ValidationError("Stack name already exists"); |
| 187 | } |
| 188 | |
| 189 | // Create the stack folder |
| 190 | await fsAsync.mkdir(dir); |
| 191 | } else { |
| 192 | if (!await fileExists(dir)) { |
| 193 | throw new ValidationError("Stack not found"); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | // Write or overwrite the compose.yaml |
| 198 | await fsAsync.writeFile(path.join(dir, this._composeFileName), this.composeYAML); |
| 199 | |
| 200 | const envPath = path.join(dir, ".env"); |
| 201 | |
| 202 | // Write or overwrite the .env |
| 203 | // If .env is not existing and the composeENV is empty, we don't need to write it |
| 204 | if (await fileExists(envPath) || this.composeENV.trim() !== "") { |
| 205 | await fsAsync.writeFile(envPath, this.composeENV); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | async deploy(socket : DockgeSocket) : Promise<number> { |
| 210 | const terminalName = getComposeTerminalName(socket.endpoint, this.name); |
no test coverage detected