Compare commits

..

2 Commits

Author SHA1 Message Date
b0e7f5aff5 Fix 2023-12-03 21:23:04 +08:00
95c958ba9f Fix freeze issue 2023-12-03 21:17:16 +08:00
11 changed files with 27 additions and 66 deletions

View File

@ -1,4 +1,5 @@
labels: [help]
title: "❓ Ask for help"
labels: [help]
body:
- type: checkboxes
id: no-duplicate-issues

View File

@ -1,3 +1,4 @@
title: 🚀 Feature Request
labels: [feature-request]
body:
- type: checkboxes
@ -51,4 +52,4 @@ body:
attributes:
label: "📝 Additional Context"
description: "Add any other context or screenshots about the feature request here."
placeholder: "..."
placeholder: "..."

View File

@ -1,14 +1,14 @@
name: "⚠️ Ask for help (Please go to the \"Discussions\" tab to submit a Help Request)"
description: "⚠️ Please go to the \"Discussions\" tab to submit a Help Request"
name: " Ask for help"
description: "Please go to the Discussions tab to submit a Help Request"
body:
- type: markdown
attributes:
value: |
⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ Please go to https://github.com/louislam/dockge/discussions/new?category=ask-for-help
Please go to https://github.com/louislam/dockge/discussions/new?category=ask-for-help
- type: checkboxes
id: no-duplicate-issues
attributes:
label: "Issues are for bug reports only, please go to the \"Discussions\" tab to submit a Feature Request"
label: "Issues are for bug reports only"
options:
- label: "I understand"
required: true

View File

@ -1,14 +1,14 @@
name: 🚀 Feature Request (Please go to the "Discussions" tab to submit a Feature Request)
description: "⚠️ Please go to the \"Discussions\" tab to submit a Feature Request"
name: 🚀 Feature Request
description: "Please go to the Discussions tab to submit a Feature Request"
body:
- type: markdown
attributes:
value: |
⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ Please go to https://github.com/louislam/dockge/discussions/new?category=ask-for-help
Please go to https://github.com/louislam/dockge/discussions/new?category=feature-request
- type: checkboxes
id: no-duplicate-issues
attributes:
label: "Issues are for bug reports only, please go to the \"Discussions\" tab to submit a Feature Request"
label: "Issues are for bug reports only"
options:
- label: "I understand"
required: true

View File

@ -32,8 +32,6 @@ import User from "./models/user";
import childProcessAsync from "promisify-child-process";
import { Terminal } from "./terminal";
import "dotenv/config";
export class DockgeServer {
app : Express;
httpServer : http.Server;

View File

@ -12,7 +12,7 @@ export class DockerSocketHandler extends SocketHandler {
socket.on("deployStack", async (name : unknown, composeYAML : unknown, composeENV : unknown, isAdd : unknown, callback) => {
try {
checkLogin(socket);
const stack = await this.saveStack(socket, server, name, composeYAML, composeENV, isAdd);
const stack = this.saveStack(socket, server, name, composeYAML, composeENV, isAdd);
await stack.deploy(socket);
server.sendStackList();
callback({
@ -264,7 +264,7 @@ export class DockerSocketHandler extends SocketHandler {
});
}
async saveStack(socket : DockgeSocket, server : DockgeServer, name : unknown, composeYAML : unknown, composeENV : unknown, isAdd : unknown) : Promise<Stack> {
saveStack(socket : DockgeSocket, server : DockgeServer, name : unknown, composeYAML : unknown, composeENV : unknown, isAdd : unknown) : Stack {
// Check types
if (typeof(name) !== "string") {
throw new ValidationError("Name must be a string");
@ -280,7 +280,7 @@ export class DockerSocketHandler extends SocketHandler {
}
const stack = new Stack(server, name, composeYAML, composeENV, false);
await stack.save(isAdd);
stack.save(isAdd);
return stack;
}

View File

@ -1,8 +1,8 @@
import { DockgeServer } from "./dockge-server";
import fs, { promises as fsAsync } from "fs";
import fs from "fs";
import { log } from "./log";
import yaml from "yaml";
import { DockgeSocket, fileExists, ValidationError } from "./util-server";
import { DockgeSocket, ValidationError } from "./util-server";
import path from "path";
import {
COMBINED_TERMINAL_COLS,
@ -99,15 +99,6 @@ export class Stack {
// Check YAML format
yaml.parse(this.composeYAML);
let lines = this.composeENV.split("\n");
// Check if the .env is able to pass docker-compose
// Prevent "setenv: The parameter is incorrect"
// It only happens when there is one line and it doesn't contain "="
if (lines.length === 1 && !lines[0].includes("=") && lines[0].length > 0) {
throw new ValidationError("Invalid .env format");
}
}
get composeYAML() : string {
@ -155,35 +146,29 @@ export class Stack {
* Save the stack to the disk
* @param isAdd
*/
async save(isAdd : boolean) {
save(isAdd : boolean) {
this.validate();
let dir = this.path;
// Check if the name is used if isAdd
if (isAdd) {
if (await fileExists(dir)) {
if (fs.existsSync(dir)) {
throw new ValidationError("Stack name already exists");
}
// Create the stack folder
await fsAsync.mkdir(dir);
fs.mkdirSync(dir);
} else {
if (!await fileExists(dir)) {
if (!fs.existsSync(dir)) {
throw new ValidationError("Stack not found");
}
}
// Write or overwrite the compose.yaml
await fsAsync.writeFile(path.join(dir, this._composeFileName), this.composeYAML);
const envPath = path.join(dir, ".env");
fs.writeFileSync(path.join(dir, this._composeFileName), this.composeYAML);
// Write or overwrite the .env
// If .env is not existing and the composeENV is empty, we don't need to write it
if (await fileExists(envPath) || this.composeENV.trim() !== "") {
await fsAsync.writeFile(envPath, this.composeENV);
}
fs.writeFileSync(path.join(dir, ".env"), this.composeENV);
}
async deploy(socket? : DockgeSocket) : Promise<number> {
@ -203,7 +188,7 @@ export class Stack {
}
// Remove the stack folder
await fsAsync.rm(this.path, {
fs.rmSync(this.path, {
recursive: true,
force: true
});
@ -233,12 +218,12 @@ export class Stack {
stackList = new Map<string, Stack>();
// Scan the stacks directory, and get the stack list
let filenameList = await fsAsync.readdir(stacksDir);
let filenameList = fs.readdirSync(stacksDir);
for (let filename of filenameList) {
try {
// Check if it is a directory
let stat = await fsAsync.stat(path.join(stacksDir, filename));
let stat = fs.statSync(path.join(stacksDir, filename));
if (!stat.isDirectory()) {
continue;
}
@ -329,7 +314,7 @@ export class Stack {
let dir = path.join(server.stacksDir, stackName);
if (!skipFSOperations) {
if (!await fileExists(dir) || !(await fsAsync.stat(dir)).isDirectory()) {
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
// Maybe it is a stack managed by docker compose directly
let stackList = await this.getStackList(server, true);
let stack = stackList.get(stackName);

View File

@ -5,7 +5,6 @@ import { log } from "./log";
import { ERROR_TYPE_VALIDATION } from "./util-common";
import { R } from "redbean-node";
import { verifyPassword } from "./password-hash";
import fs from "fs";
export interface JWTDecoded {
username : string;
@ -83,9 +82,3 @@ export async function doubleCheckPassword(socket : DockgeSocket, currentPassword
return user;
}
export function fileExists(file : string) {
return fs.promises.access(file, fs.constants.F_OK)
.then(() => true)
.catch(() => false);
}

View File

@ -152,14 +152,6 @@ export default {
});
result.sort((m1, m2) => {
// sort by managed by dockge
if (m1.isManagedByDockge && !m2.isManagedByDockge) {
return -1;
} else if (!m1.isManagedByDockge && m2.isManagedByDockge) {
return 1;
}
if (m1.status !== m2.status) {
if (m2.status === RUNNING) {
return 1;

View File

@ -33,7 +33,6 @@
"composerize": "~1.4.1",
"croner": "~7.0.5",
"dayjs": "~1.11.10",
"dotenv": "~16.3.1",
"express": "~4.18.2",
"express-static-gzip": "~2.1.7",
"http-graceful-shutdown": "~3.1.13",

8
pnpm-lock.yaml generated
View File

@ -32,9 +32,6 @@ dependencies:
dayjs:
specifier: ~1.11.10
version: 1.11.10
dotenv:
specifier: ~16.3.1
version: 16.3.1
express:
specifier: ~4.18.2
version: 4.18.2
@ -2157,11 +2154,6 @@ packages:
esutils: 2.0.3
dev: true
/dotenv@16.3.1:
resolution: {integrity: sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==}
engines: {node: '>=12'}
dev: false
/eastasianwidth@0.2.0:
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
dev: false