mirror of
https://github.com/louislam/dockge.git
synced 2025-08-13 18:57:20 +02:00
Compare commits
13 Commits
child-proc
...
1.3.2
Author | SHA1 | Date | |
---|---|---|---|
8296c7b18f | |||
607c908f2d | |||
bd5dd3c3ad | |||
6eca6dc59f | |||
54fb2c1ef4 | |||
562abb485d | |||
86bed768ea | |||
b79db2375f | |||
b586cca711 | |||
793a9de50d | |||
0df3fee3f4 | |||
05b79ba50e | |||
a3c4082800 |
1
.github/DISCUSSION_TEMPLATE/ask-for-help.yml
vendored
1
.github/DISCUSSION_TEMPLATE/ask-for-help.yml
vendored
@ -1,4 +1,3 @@
|
|||||||
title: "❓ Ask for help"
|
|
||||||
labels: [help]
|
labels: [help]
|
||||||
body:
|
body:
|
||||||
- type: checkboxes
|
- type: checkboxes
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
title: 🚀 Feature Request
|
|
||||||
labels: [feature-request]
|
labels: [feature-request]
|
||||||
body:
|
body:
|
||||||
- type: checkboxes
|
- type: checkboxes
|
||||||
|
8
.github/ISSUE_TEMPLATE/ask-for-help.yaml
vendored
8
.github/ISSUE_TEMPLATE/ask-for-help.yaml
vendored
@ -1,14 +1,14 @@
|
|||||||
name: "❓ Ask for help"
|
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"
|
description: "⚠️ Please go to the \"Discussions\" tab to submit a Help Request"
|
||||||
body:
|
body:
|
||||||
- type: markdown
|
- type: markdown
|
||||||
attributes:
|
attributes:
|
||||||
value: |
|
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
|
- type: checkboxes
|
||||||
id: no-duplicate-issues
|
id: no-duplicate-issues
|
||||||
attributes:
|
attributes:
|
||||||
label: "Issues are for bug reports only"
|
label: "Issues are for bug reports only, please go to the \"Discussions\" tab to submit a Feature Request"
|
||||||
options:
|
options:
|
||||||
- label: "I understand"
|
- label: "I understand"
|
||||||
required: true
|
required: true
|
||||||
|
8
.github/ISSUE_TEMPLATE/feature_request.yaml
vendored
8
.github/ISSUE_TEMPLATE/feature_request.yaml
vendored
@ -1,14 +1,14 @@
|
|||||||
name: 🚀 Feature Request
|
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"
|
description: "⚠️ Please go to the \"Discussions\" tab to submit a Feature Request"
|
||||||
body:
|
body:
|
||||||
- type: markdown
|
- type: markdown
|
||||||
attributes:
|
attributes:
|
||||||
value: |
|
value: |
|
||||||
Please go to https://github.com/louislam/dockge/discussions/new?category=feature-request
|
⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ Please go to https://github.com/louislam/dockge/discussions/new?category=ask-for-help
|
||||||
- type: checkboxes
|
- type: checkboxes
|
||||||
id: no-duplicate-issues
|
id: no-duplicate-issues
|
||||||
attributes:
|
attributes:
|
||||||
label: "Issues are for bug reports only"
|
label: "Issues are for bug reports only, please go to the \"Discussions\" tab to submit a Feature Request"
|
||||||
options:
|
options:
|
||||||
- label: "I understand"
|
- label: "I understand"
|
||||||
required: true
|
required: true
|
||||||
|
@ -32,6 +32,8 @@ import User from "./models/user";
|
|||||||
import childProcessAsync from "promisify-child-process";
|
import childProcessAsync from "promisify-child-process";
|
||||||
import { Terminal } from "./terminal";
|
import { Terminal } from "./terminal";
|
||||||
|
|
||||||
|
import "dotenv/config";
|
||||||
|
|
||||||
export class DockgeServer {
|
export class DockgeServer {
|
||||||
app : Express;
|
app : Express;
|
||||||
httpServer : http.Server;
|
httpServer : http.Server;
|
||||||
|
@ -12,7 +12,7 @@ export class DockerSocketHandler extends SocketHandler {
|
|||||||
socket.on("deployStack", async (name : unknown, composeYAML : unknown, composeENV : unknown, isAdd : unknown, callback) => {
|
socket.on("deployStack", async (name : unknown, composeYAML : unknown, composeENV : unknown, isAdd : unknown, callback) => {
|
||||||
try {
|
try {
|
||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
const stack = this.saveStack(socket, server, name, composeYAML, composeENV, isAdd);
|
const stack = await this.saveStack(socket, server, name, composeYAML, composeENV, isAdd);
|
||||||
await stack.deploy(socket);
|
await stack.deploy(socket);
|
||||||
server.sendStackList();
|
server.sendStackList();
|
||||||
callback({
|
callback({
|
||||||
@ -234,7 +234,7 @@ export class DockerSocketHandler extends SocketHandler {
|
|||||||
socket.on("getDockerNetworkList", async (callback) => {
|
socket.on("getDockerNetworkList", async (callback) => {
|
||||||
try {
|
try {
|
||||||
checkLogin(socket);
|
checkLogin(socket);
|
||||||
const dockerNetworkList = server.getDockerNetworkList();
|
const dockerNetworkList = await server.getDockerNetworkList();
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
dockerNetworkList,
|
dockerNetworkList,
|
||||||
@ -264,7 +264,7 @@ export class DockerSocketHandler extends SocketHandler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
saveStack(socket : DockgeSocket, server : DockgeServer, name : unknown, composeYAML : unknown, composeENV : unknown, isAdd : unknown) : Stack {
|
async saveStack(socket : DockgeSocket, server : DockgeServer, name : unknown, composeYAML : unknown, composeENV : unknown, isAdd : unknown) : Promise<Stack> {
|
||||||
// Check types
|
// Check types
|
||||||
if (typeof(name) !== "string") {
|
if (typeof(name) !== "string") {
|
||||||
throw new ValidationError("Name must be a 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);
|
const stack = new Stack(server, name, composeYAML, composeENV, false);
|
||||||
stack.save(isAdd);
|
await stack.save(isAdd);
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { DockgeServer } from "./dockge-server";
|
import { DockgeServer } from "./dockge-server";
|
||||||
import fs from "fs";
|
import fs, { promises as fsAsync } from "fs";
|
||||||
import { log } from "./log";
|
import { log } from "./log";
|
||||||
import yaml from "yaml";
|
import yaml from "yaml";
|
||||||
import { DockgeSocket, ValidationError } from "./util-server";
|
import { DockgeSocket, fileExists, ValidationError } from "./util-server";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import {
|
import {
|
||||||
COMBINED_TERMINAL_COLS,
|
COMBINED_TERMINAL_COLS,
|
||||||
@ -99,6 +99,15 @@ export class Stack {
|
|||||||
|
|
||||||
// Check YAML format
|
// Check YAML format
|
||||||
yaml.parse(this.composeYAML);
|
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 {
|
get composeYAML() : string {
|
||||||
@ -146,29 +155,35 @@ export class Stack {
|
|||||||
* Save the stack to the disk
|
* Save the stack to the disk
|
||||||
* @param isAdd
|
* @param isAdd
|
||||||
*/
|
*/
|
||||||
save(isAdd : boolean) {
|
async save(isAdd : boolean) {
|
||||||
this.validate();
|
this.validate();
|
||||||
|
|
||||||
let dir = this.path;
|
let dir = this.path;
|
||||||
|
|
||||||
// Check if the name is used if isAdd
|
// Check if the name is used if isAdd
|
||||||
if (isAdd) {
|
if (isAdd) {
|
||||||
if (fs.existsSync(dir)) {
|
if (await fileExists(dir)) {
|
||||||
throw new ValidationError("Stack name already exists");
|
throw new ValidationError("Stack name already exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the stack folder
|
// Create the stack folder
|
||||||
fs.mkdirSync(dir);
|
await fsAsync.mkdir(dir);
|
||||||
} else {
|
} else {
|
||||||
if (!fs.existsSync(dir)) {
|
if (!await fileExists(dir)) {
|
||||||
throw new ValidationError("Stack not found");
|
throw new ValidationError("Stack not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write or overwrite the compose.yaml
|
// Write or overwrite the compose.yaml
|
||||||
fs.writeFileSync(path.join(dir, this._composeFileName), this.composeYAML);
|
await fsAsync.writeFile(path.join(dir, this._composeFileName), this.composeYAML);
|
||||||
|
|
||||||
|
const envPath = path.join(dir, ".env");
|
||||||
|
|
||||||
// Write or overwrite the .env
|
// Write or overwrite the .env
|
||||||
fs.writeFileSync(path.join(dir, ".env"), this.composeENV);
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async deploy(socket? : DockgeSocket) : Promise<number> {
|
async deploy(socket? : DockgeSocket) : Promise<number> {
|
||||||
@ -188,7 +203,7 @@ export class Stack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove the stack folder
|
// Remove the stack folder
|
||||||
fs.rmSync(this.path, {
|
await fsAsync.rm(this.path, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
force: true
|
force: true
|
||||||
});
|
});
|
||||||
@ -218,12 +233,12 @@ export class Stack {
|
|||||||
stackList = new Map<string, Stack>();
|
stackList = new Map<string, Stack>();
|
||||||
|
|
||||||
// Scan the stacks directory, and get the stack list
|
// Scan the stacks directory, and get the stack list
|
||||||
let filenameList = fs.readdirSync(stacksDir);
|
let filenameList = await fsAsync.readdir(stacksDir);
|
||||||
|
|
||||||
for (let filename of filenameList) {
|
for (let filename of filenameList) {
|
||||||
try {
|
try {
|
||||||
// Check if it is a directory
|
// Check if it is a directory
|
||||||
let stat = fs.statSync(path.join(stacksDir, filename));
|
let stat = await fsAsync.stat(path.join(stacksDir, filename));
|
||||||
if (!stat.isDirectory()) {
|
if (!stat.isDirectory()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -282,7 +297,12 @@ export class Stack {
|
|||||||
let res = await childProcessAsync.spawn("docker", [ "compose", "ls", "--all", "--format", "json" ], {
|
let res = await childProcessAsync.spawn("docker", [ "compose", "ls", "--all", "--format", "json" ], {
|
||||||
encoding: "utf-8",
|
encoding: "utf-8",
|
||||||
});
|
});
|
||||||
let composeList = JSON.parse(res.toString());
|
|
||||||
|
if (!res.stdout) {
|
||||||
|
return statusList;
|
||||||
|
}
|
||||||
|
|
||||||
|
let composeList = JSON.parse(res.stdout.toString());
|
||||||
|
|
||||||
for (let composeStack of composeList) {
|
for (let composeStack of composeList) {
|
||||||
statusList.set(composeStack.Name, this.statusConvert(composeStack.Status));
|
statusList.set(composeStack.Name, this.statusConvert(composeStack.Status));
|
||||||
@ -314,7 +334,7 @@ export class Stack {
|
|||||||
let dir = path.join(server.stacksDir, stackName);
|
let dir = path.join(server.stacksDir, stackName);
|
||||||
|
|
||||||
if (!skipFSOperations) {
|
if (!skipFSOperations) {
|
||||||
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
|
if (!await fileExists(dir) || !(await fsAsync.stat(dir)).isDirectory()) {
|
||||||
// Maybe it is a stack managed by docker compose directly
|
// Maybe it is a stack managed by docker compose directly
|
||||||
let stackList = await this.getStackList(server, true);
|
let stackList = await this.getStackList(server, true);
|
||||||
let stack = stackList.get(stackName);
|
let stack = stackList.get(stackName);
|
||||||
|
@ -5,6 +5,7 @@ import { log } from "./log";
|
|||||||
import { ERROR_TYPE_VALIDATION } from "./util-common";
|
import { ERROR_TYPE_VALIDATION } from "./util-common";
|
||||||
import { R } from "redbean-node";
|
import { R } from "redbean-node";
|
||||||
import { verifyPassword } from "./password-hash";
|
import { verifyPassword } from "./password-hash";
|
||||||
|
import fs from "fs";
|
||||||
|
|
||||||
export interface JWTDecoded {
|
export interface JWTDecoded {
|
||||||
username : string;
|
username : string;
|
||||||
@ -82,3 +83,9 @@ export async function doubleCheckPassword(socket : DockgeSocket, currentPassword
|
|||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fileExists(file : string) {
|
||||||
|
return fs.promises.access(file, fs.constants.F_OK)
|
||||||
|
.then(() => true)
|
||||||
|
.catch(() => false);
|
||||||
|
}
|
||||||
|
@ -152,6 +152,14 @@ export default {
|
|||||||
});
|
});
|
||||||
|
|
||||||
result.sort((m1, m2) => {
|
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 (m1.status !== m2.status) {
|
||||||
if (m2.status === RUNNING) {
|
if (m2.status === RUNNING) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
"registry": "Registro",
|
"registry": "Registro",
|
||||||
"compose": "Compose",
|
"compose": "Compose",
|
||||||
"addFirstStackMsg": "Componi il tuo primo stack!",
|
"addFirstStackMsg": "Componi il tuo primo stack!",
|
||||||
"stackName" : "Nome dello stack",
|
"stackName": "Nome dello stack",
|
||||||
"deployStack": "Deploy",
|
"deployStack": "Deploy",
|
||||||
"deleteStack": "Cancella",
|
"deleteStack": "Cancella",
|
||||||
"stopStack": "Stop",
|
"stopStack": "Stop",
|
||||||
@ -23,7 +23,7 @@
|
|||||||
"editStack": "Modifica",
|
"editStack": "Modifica",
|
||||||
"discardStack": "Annulla",
|
"discardStack": "Annulla",
|
||||||
"saveStackDraft": "Salva",
|
"saveStackDraft": "Salva",
|
||||||
"notAvailableShort" : "N/D",
|
"notAvailableShort": "N/D",
|
||||||
"deleteStackMsg": "Sei sicuro di voler eliminare questo stack?",
|
"deleteStackMsg": "Sei sicuro di voler eliminare questo stack?",
|
||||||
"stackNotManagedByDockgeMsg": "Questo stack non è gestito da Dockge.",
|
"stackNotManagedByDockgeMsg": "Questo stack non è gestito da Dockge.",
|
||||||
"primaryHostname": "Hostname primario",
|
"primaryHostname": "Hostname primario",
|
||||||
@ -91,5 +91,11 @@
|
|||||||
"Allowed commands:": "Comandi permessi:",
|
"Allowed commands:": "Comandi permessi:",
|
||||||
"Internal Networks": "Reti interne",
|
"Internal Networks": "Reti interne",
|
||||||
"External Networks": "Reti esterne",
|
"External Networks": "Reti esterne",
|
||||||
"No External Networks": "Nessuna rete esterna"
|
"No External Networks": "Nessuna rete esterna",
|
||||||
|
"reverseProxyMsg1": "Utilizzando un proxy inverso?",
|
||||||
|
"reverseProxyMsg2": "Controlla come configurarlo per WebSocket",
|
||||||
|
"Cannot connect to the socket server.": "Impossibile connettersi al server socket.",
|
||||||
|
"connecting...": "Connessione al server socket…",
|
||||||
|
"extra": "Extra",
|
||||||
|
"reconnecting...": "Riconnessione…"
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
"editStack": "編集",
|
"editStack": "編集",
|
||||||
"discardStack": "破棄",
|
"discardStack": "破棄",
|
||||||
"saveStackDraft": "保存",
|
"saveStackDraft": "保存",
|
||||||
"stackNotManagedByDockgeMsg": "このスタックはDockageによって管理されていません。",
|
"stackNotManagedByDockgeMsg": "このスタックはDockgeによって管理されていません。",
|
||||||
"general": "一般",
|
"general": "一般",
|
||||||
"scanFolder": "スタックフォルダをスキャン",
|
"scanFolder": "スタックフォルダをスキャン",
|
||||||
"dockerImage": "イメージ",
|
"dockerImage": "イメージ",
|
||||||
|
@ -90,5 +90,13 @@
|
|||||||
"Allowed commands:": "허용된 명령어:",
|
"Allowed commands:": "허용된 명령어:",
|
||||||
"Internal Networks": "내부 네트워크",
|
"Internal Networks": "내부 네트워크",
|
||||||
"External Networks": "외부 네트워크",
|
"External Networks": "외부 네트워크",
|
||||||
"No External Networks": "외부 네트워크 없음"
|
"No External Networks": "외부 네트워크 없음",
|
||||||
|
"reverseProxyMsg2": "여기서 WebSocket을 위한 설정을 확인해 보세요",
|
||||||
|
"downStack": "정지 & Down",
|
||||||
|
"reverseProxyMsg1": "리버스 프록시를 사용하고 계신가요?",
|
||||||
|
"Cannot connect to the socket server.": "소켓 서버에 연결하지 못했습니다.",
|
||||||
|
"connecting...": "소켓 서버에 연결하는 중…",
|
||||||
|
"extra": "기타",
|
||||||
|
"url": "URL | URL",
|
||||||
|
"reconnecting...": "재연결 중…"
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dockge",
|
"name": "dockge",
|
||||||
"version": "1.2.0",
|
"version": "1.3.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 18.0.0 && <= 18.17.1"
|
"node": ">= 18.0.0 && <= 18.17.1"
|
||||||
@ -33,6 +33,7 @@
|
|||||||
"composerize": "~1.4.1",
|
"composerize": "~1.4.1",
|
||||||
"croner": "~7.0.5",
|
"croner": "~7.0.5",
|
||||||
"dayjs": "~1.11.10",
|
"dayjs": "~1.11.10",
|
||||||
|
"dotenv": "~16.3.1",
|
||||||
"express": "~4.18.2",
|
"express": "~4.18.2",
|
||||||
"express-static-gzip": "~2.1.7",
|
"express-static-gzip": "~2.1.7",
|
||||||
"http-graceful-shutdown": "~3.1.13",
|
"http-graceful-shutdown": "~3.1.13",
|
||||||
|
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
@ -32,6 +32,9 @@ dependencies:
|
|||||||
dayjs:
|
dayjs:
|
||||||
specifier: ~1.11.10
|
specifier: ~1.11.10
|
||||||
version: 1.11.10
|
version: 1.11.10
|
||||||
|
dotenv:
|
||||||
|
specifier: ~16.3.1
|
||||||
|
version: 16.3.1
|
||||||
express:
|
express:
|
||||||
specifier: ~4.18.2
|
specifier: ~4.18.2
|
||||||
version: 4.18.2
|
version: 4.18.2
|
||||||
@ -2154,6 +2157,11 @@ packages:
|
|||||||
esutils: 2.0.3
|
esutils: 2.0.3
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/dotenv@16.3.1:
|
||||||
|
resolution: {integrity: sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==}
|
||||||
|
engines: {node: '>=12'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/eastasianwidth@0.2.0:
|
/eastasianwidth@0.2.0:
|
||||||
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
|
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
|
||||||
dev: false
|
dev: false
|
||||||
|
Reference in New Issue
Block a user