mirror of
https://github.com/louislam/dockge.git
synced 2026-05-23 06:52:17 +00:00
Compare commits
3 Commits
down
...
improvemen
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55bed44a53 | ||
|
|
e1dcbdc317 | ||
|
|
291d9671d8 |
@@ -103,6 +103,10 @@ class Logger {
|
|||||||
* @param level Log level. One of INFO, WARN, ERROR, DEBUG or can be customized.
|
* @param level Log level. One of INFO, WARN, ERROR, DEBUG or can be customized.
|
||||||
*/
|
*/
|
||||||
log(module: string, msg: unknown, level: string) {
|
log(module: string, msg: unknown, level: string) {
|
||||||
|
if (level === "DEBUG" && !isDev) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.hideLog[level] && this.hideLog[level].includes(module.toLowerCase())) {
|
if (this.hideLog[level] && this.hideLog[level].includes(module.toLowerCase())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,27 +187,6 @@ export class DockerSocketHandler extends SocketHandler {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// down stack
|
|
||||||
socket.on("downStack", async (stackName : unknown, callback) => {
|
|
||||||
try {
|
|
||||||
checkLogin(socket);
|
|
||||||
|
|
||||||
if (typeof(stackName) !== "string") {
|
|
||||||
throw new ValidationError("Stack name must be a string");
|
|
||||||
}
|
|
||||||
|
|
||||||
const stack = Stack.getStack(server, stackName);
|
|
||||||
await stack.down(socket);
|
|
||||||
callback({
|
|
||||||
ok: true,
|
|
||||||
msg: "Downed"
|
|
||||||
});
|
|
||||||
server.sendStackList();
|
|
||||||
} catch (e) {
|
|
||||||
callbackError(e, callback);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Services status
|
// Services status
|
||||||
socket.on("serviceStatusList", async (stackName : unknown, callback) => {
|
socket.on("serviceStatusList", async (stackName : unknown, callback) => {
|
||||||
try {
|
try {
|
||||||
@@ -217,7 +196,7 @@ export class DockerSocketHandler extends SocketHandler {
|
|||||||
throw new ValidationError("Stack name must be a string");
|
throw new ValidationError("Stack name must be a string");
|
||||||
}
|
}
|
||||||
|
|
||||||
const stack = Stack.getStack(server, stackName);
|
const stack = Stack.getStack(server, stackName, true);
|
||||||
const serviceStatusList = Object.fromEntries(await stack.getServiceStatusList());
|
const serviceStatusList = Object.fromEntries(await stack.getServiceStatusList());
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
|
|||||||
@@ -31,11 +31,12 @@ export class Stack {
|
|||||||
|
|
||||||
protected static managedStackList: Map<string, Stack> = new Map();
|
protected static managedStackList: Map<string, Stack> = new Map();
|
||||||
|
|
||||||
constructor(server : DockgeServer, name : string, composeYAML? : string) {
|
constructor(server : DockgeServer, name : string, composeYAML? : string, skipFSOperations = false) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this._composeYAML = composeYAML;
|
this._composeYAML = composeYAML;
|
||||||
|
|
||||||
|
if (!skipFSOperations) {
|
||||||
// Check if compose file name is different from compose.yaml
|
// Check if compose file name is different from compose.yaml
|
||||||
const supportedFileNames = [ "compose.yaml", "compose.yml", "docker-compose.yml", "docker-compose.yaml" ];
|
const supportedFileNames = [ "compose.yaml", "compose.yml", "docker-compose.yml", "docker-compose.yaml" ];
|
||||||
for (const filename of supportedFileNames) {
|
for (const filename of supportedFileNames) {
|
||||||
@@ -45,6 +46,7 @@ export class Stack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
toJSON() : object {
|
toJSON() : object {
|
||||||
let obj = this.toSimpleJSON();
|
let obj = this.toSimpleJSON();
|
||||||
@@ -281,12 +283,13 @@ export class Stack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static getStack(server: DockgeServer, stackName: string) : Stack {
|
static getStack(server: DockgeServer, stackName: string, skipFSOperations = false) : Stack {
|
||||||
let dir = path.join(server.stacksDir, stackName);
|
let dir = path.join(server.stacksDir, stackName);
|
||||||
|
|
||||||
|
if (!skipFSOperations) {
|
||||||
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
|
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
|
||||||
// Maybe it is a stack managed by docker compose directly
|
// Maybe it is a stack managed by docker compose directly
|
||||||
let stackList = this.getStackList(server);
|
let stackList = this.getStackList(server, true);
|
||||||
let stack = stackList.get(stackName);
|
let stack = stackList.get(stackName);
|
||||||
|
|
||||||
if (stack) {
|
if (stack) {
|
||||||
@@ -296,8 +299,18 @@ export class Stack {
|
|||||||
throw new ValidationError("Stack not found");
|
throw new ValidationError("Stack not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.debug("getStack", "Skip FS operations");
|
||||||
|
}
|
||||||
|
|
||||||
|
let stack : Stack;
|
||||||
|
|
||||||
|
if (!skipFSOperations) {
|
||||||
|
stack = new Stack(server, stackName);
|
||||||
|
} else {
|
||||||
|
stack = new Stack(server, stackName, undefined, true);
|
||||||
|
}
|
||||||
|
|
||||||
let stack = new Stack(server, stackName);
|
|
||||||
stack._status = UNKNOWN;
|
stack._status = UNKNOWN;
|
||||||
stack._configFilePath = path.resolve(dir);
|
stack._configFilePath = path.resolve(dir);
|
||||||
return stack;
|
return stack;
|
||||||
@@ -330,15 +343,6 @@ export class Stack {
|
|||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
async down(socket: DockgeSocket) : Promise<number> {
|
|
||||||
const terminalName = getComposeTerminalName(this.name);
|
|
||||||
let exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", [ "compose", "down" ], this.path);
|
|
||||||
if (exitCode !== 0) {
|
|
||||||
throw new Error("Failed to down, please check the terminal output for more information.");
|
|
||||||
}
|
|
||||||
return exitCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
async update(socket: DockgeSocket) {
|
async update(socket: DockgeSocket) {
|
||||||
const terminalName = getComposeTerminalName(this.name);
|
const terminalName = getComposeTerminalName(this.name);
|
||||||
let exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", [ "compose", "pull" ], this.path);
|
let exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", [ "compose", "pull" ], this.path);
|
||||||
@@ -386,11 +390,11 @@ export class Stack {
|
|||||||
async getServiceStatusList() {
|
async getServiceStatusList() {
|
||||||
let statusList = new Map<string, number>();
|
let statusList = new Map<string, number>();
|
||||||
|
|
||||||
let res = childProcess.execSync("docker compose ps --format json", {
|
let res = childProcess.spawnSync("docker", [ "compose", "ps", "--format", "json" ], {
|
||||||
cwd: this.path,
|
cwd: this.path,
|
||||||
});
|
});
|
||||||
|
|
||||||
let lines = res.toString().split("\n");
|
let lines = res.stdout.toString().split("\n");
|
||||||
|
|
||||||
for (let line of lines) {
|
for (let line of lines) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ export class Terminal {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
this._ptyProcess = pty.spawn(this.file, this.args, {
|
this._ptyProcess = pty.spawn(this.file, this.args, {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
cwd: this.cwd,
|
cwd: this.cwd,
|
||||||
@@ -96,7 +97,23 @@ export class Terminal {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// On Exit
|
// On Exit
|
||||||
this._ptyProcess.onExit((res) => {
|
this._ptyProcess.onExit(this.exit);
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
log.error("Terminal", "Failed to start terminal: " + error.message);
|
||||||
|
const exitCode = Number(error.message.split(" ").pop());
|
||||||
|
this.exit({
|
||||||
|
exitCode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exit event handler
|
||||||
|
* @param res
|
||||||
|
*/
|
||||||
|
protected exit = (res : {exitCode: number, signal?: number | undefined}) => {
|
||||||
this.server.io.to(this.name).emit("terminalExit", this.name, res.exitCode);
|
this.server.io.to(this.name).emit("terminalExit", this.name, res.exitCode);
|
||||||
|
|
||||||
// Remove room
|
// Remove room
|
||||||
@@ -108,8 +125,7 @@ export class Terminal {
|
|||||||
if (this.callback) {
|
if (this.callback) {
|
||||||
this.callback(res.exitCode);
|
this.callback(res.exitCode);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
}
|
|
||||||
|
|
||||||
public onExit(callback : (exitCode : number) => void) {
|
public onExit(callback : (exitCode : number) => void) {
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
|
|||||||
3
frontend/components.d.ts
vendored
3
frontend/components.d.ts
vendored
@@ -11,9 +11,6 @@ declare module 'vue' {
|
|||||||
Appearance: typeof import('./src/components/settings/Appearance.vue')['default']
|
Appearance: typeof import('./src/components/settings/Appearance.vue')['default']
|
||||||
ArrayInput: typeof import('./src/components/ArrayInput.vue')['default']
|
ArrayInput: typeof import('./src/components/ArrayInput.vue')['default']
|
||||||
ArraySelect: typeof import('./src/components/ArraySelect.vue')['default']
|
ArraySelect: typeof import('./src/components/ArraySelect.vue')['default']
|
||||||
BDropdown: typeof import('bootstrap-vue-next')['BDropdown']
|
|
||||||
BDropdownDivider: typeof import('bootstrap-vue-next')['BDropdownDivider']
|
|
||||||
BDropdownItem: typeof import('bootstrap-vue-next')['BDropdownItem']
|
|
||||||
BModal: typeof import('bootstrap-vue-next')['BModal']
|
BModal: typeof import('bootstrap-vue-next')['BModal']
|
||||||
Confirm: typeof import('./src/components/Confirm.vue')['default']
|
Confirm: typeof import('./src/components/Confirm.vue')['default']
|
||||||
Container: typeof import('./src/components/Container.vue')['default']
|
Container: typeof import('./src/components/Container.vue')['default']
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
"restartStack": "Restart",
|
"restartStack": "Restart",
|
||||||
"updateStack": "Update",
|
"updateStack": "Update",
|
||||||
"startStack": "Start",
|
"startStack": "Start",
|
||||||
"downStack": "Stop & Down",
|
|
||||||
"editStack": "Edit",
|
"editStack": "Edit",
|
||||||
"discardStack": "Discard",
|
"discardStack": "Discard",
|
||||||
"saveStackDraft": "Save",
|
"saveStackDraft": "Save",
|
||||||
|
|||||||
@@ -40,13 +40,6 @@
|
|||||||
<font-awesome-icon icon="stop" class="me-1" />
|
<font-awesome-icon icon="stop" class="me-1" />
|
||||||
{{ $t("stopStack") }}
|
{{ $t("stopStack") }}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<BDropdown v-if="!isEditMode && active" right text="" variant="normal">
|
|
||||||
<BDropdownItem @click="downStack">
|
|
||||||
<font-awesome-icon icon="stop" class="me-1" />
|
|
||||||
{{ $t("downStack") }}
|
|
||||||
</BDropdownItem>
|
|
||||||
</BDropdown>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button v-if="isEditMode && !isAdd" class="btn btn-normal" :disabled="processing" @click="discardStack">{{ $t("discardStack") }}</button>
|
<button v-if="isEditMode && !isAdd" class="btn btn-normal" :disabled="processing" @click="discardStack">{{ $t("discardStack") }}</button>
|
||||||
@@ -480,15 +473,6 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
downStack() {
|
|
||||||
this.processing = true;
|
|
||||||
|
|
||||||
this.$root.getSocket().emit("downStack", this.stack.name, (res) => {
|
|
||||||
this.processing = false;
|
|
||||||
this.$root.toastRes(res);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
restartStack() {
|
restartStack() {
|
||||||
this.processing = true;
|
this.processing = true;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
"lint": "eslint \"**/*.{ts,vue}\"",
|
"lint": "eslint \"**/*.{ts,vue}\"",
|
||||||
"check-ts": "tsc --noEmit",
|
"check-ts": "tsc --noEmit",
|
||||||
"start": "tsx ./backend/index.ts",
|
"start": "tsx ./backend/index.ts",
|
||||||
"dev:backend": "cross-env NODE_ENV=development tsx watch ./backend/index.ts",
|
"dev:backend": "cross-env NODE_ENV=development tsx watch --inspect ./backend/index.ts",
|
||||||
"dev:frontend": "cross-env NODE_ENV=development vite --host --config ./frontend/vite.config.ts",
|
"dev:frontend": "cross-env NODE_ENV=development vite --host --config ./frontend/vite.config.ts",
|
||||||
"release-final": "tsx ./extra/test-docker.ts && tsx extra/update-version.ts && pnpm run build:frontend && npm run build:docker",
|
"release-final": "tsx ./extra/test-docker.ts && tsx extra/update-version.ts && pnpm run build:frontend && npm run build:docker",
|
||||||
"build:frontend": "vite build --config ./frontend/vite.config.ts",
|
"build:frontend": "vite build --config ./frontend/vite.config.ts",
|
||||||
|
|||||||
Reference in New Issue
Block a user