From 21e736459e5de62abeb55ab78bbad5d532a8f317 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Mon, 6 Nov 2023 21:24:06 +0800 Subject: [PATCH] wip --- backend/check-version.ts | 2 +- backend/database.ts | 2 +- backend/dockge-server.ts | 2 +- .../terminal-socket-handler.ts | 10 ++++--- backend/stack.ts | 6 ++--- backend/terminal.ts | 6 ++--- docker/Dockerfile | 10 +++++++ extra/mark-as-nightly.ts | 22 +++++++++++++++ extra/templates/uptime-kuma/compose.yaml | 1 - frontend/src/components/Terminal.vue | 8 +++++- frontend/src/components/settings/About.vue | 2 +- frontend/src/layouts/Layout.vue | 2 +- frontend/src/pages/ContainerTerminal.vue | 27 ++++++++++++++----- frontend/src/pages/Settings.vue | 3 +-- package.json | 6 +++-- 15 files changed, 82 insertions(+), 27 deletions(-) create mode 100644 extra/mark-as-nightly.ts diff --git a/backend/check-version.ts b/backend/check-version.ts index 6c4e319..acfb5fb 100644 --- a/backend/check-version.ts +++ b/backend/check-version.ts @@ -11,7 +11,7 @@ export default obj; // How much time in ms to wait between update checks const UPDATE_CHECKER_INTERVAL_MS = 1000 * 60 * 60 * 48; -const CHECK_URL = "https://uptime.kuma.pet/version"; +const CHECK_URL = "https://dockge.kuma.pet/version"; let interval : NodeJS.Timeout; diff --git a/backend/database.ts b/backend/database.ts index d5282e5..75f3c63 100644 --- a/backend/database.ts +++ b/backend/database.ts @@ -16,7 +16,7 @@ interface DBConfig { export class Database { /** - * SQLite file path (Default: ./data/kuma.db) + * SQLite file path (Default: ./data/dockge.db) * @type {string} */ static sqlitePath; diff --git a/backend/dockge-server.ts b/backend/dockge-server.ts index e2e7f42..befad03 100644 --- a/backend/dockge-server.ts +++ b/backend/dockge-server.ts @@ -69,7 +69,7 @@ export class DockgeServer { // Catch unexpected errors here let unexpectedErrorHandler = (error : unknown) => { console.trace(error); - console.error("If you keep encountering errors, please report to https://github.com/louislam/uptime-kuma/issues"); + console.error("If you keep encountering errors, please report to https://github.com/louislam/dockge"); }; process.addListener("unhandledRejection", unexpectedErrorHandler); process.addListener("uncaughtException", unexpectedErrorHandler); diff --git a/backend/socket-handlers/terminal-socket-handler.ts b/backend/socket-handlers/terminal-socket-handler.ts index 2b4fd9e..f647dfb 100644 --- a/backend/socket-handlers/terminal-socket-handler.ts +++ b/backend/socket-handlers/terminal-socket-handler.ts @@ -32,7 +32,7 @@ export class TerminalSocketHandler extends SocketHandler { let terminal = Terminal.getTerminal(terminalName); if (terminal instanceof InteractiveTerminal) { - log.debug("terminalInput", "Terminal found, writing to terminal."); + //log.debug("terminalInput", "Terminal found, writing to terminal."); terminal.write(cmd); } else { throw new Error("Terminal not found or it is not a Interactive Terminal."); @@ -79,7 +79,7 @@ export class TerminalSocketHandler extends SocketHandler { }); // Interactive Terminal for containers - socket.on("interactiveTerminal", async (stackName : unknown, serviceName : unknown, callback) => { + socket.on("interactiveTerminal", async (stackName : unknown, serviceName : unknown, shell : unknown, callback) => { try { checkLogin(socket); @@ -91,12 +91,16 @@ export class TerminalSocketHandler extends SocketHandler { throw new ValidationError("Service name must be a string."); } + if (typeof(shell) !== "string") { + throw new ValidationError("Shell must be a string."); + } + log.debug("interactiveTerminal", "Stack name: " + stackName); log.debug("interactiveTerminal", "Service name: " + serviceName); // Get stack const stack = Stack.getStack(server, stackName); - stack.joinContainerTerminal(socket, serviceName); + stack.joinContainerTerminal(socket, serviceName, shell); callback({ ok: true, diff --git a/backend/stack.ts b/backend/stack.ts index 293739c..f8cb423 100644 --- a/backend/stack.ts +++ b/backend/stack.ts @@ -317,14 +317,14 @@ export class Stack { terminal.start(); } - async joinContainerTerminal(socket: DockgeSocket, serviceName: string, index: number = 0) { + async joinContainerTerminal(socket: DockgeSocket, serviceName: string, shell : string = "sh", index: number = 0) { const terminalName = getContainerExecTerminalName(this.name, serviceName, index); let terminal = Terminal.getTerminal(terminalName); if (!terminal) { - terminal = new InteractiveTerminal(this.server, terminalName, "docker", [ "compose", "exec", serviceName, "bash" ], this.path); + terminal = new InteractiveTerminal(this.server, terminalName, "docker", [ "compose", "exec", serviceName, shell ], this.path); terminal.rows = TERMINAL_ROWS; - log.debug("deployStack", "Terminal created"); + log.debug("joinContainerTerminal", "Terminal created"); } terminal.join(socket); diff --git a/backend/terminal.ts b/backend/terminal.ts index 63324f1..2a31f17 100644 --- a/backend/terminal.ts +++ b/backend/terminal.ts @@ -98,12 +98,12 @@ export class Terminal { // Remove room this.server.io.in(this.name).socketsLeave(this.name); + Terminal.terminalMap.delete(this.name); + log.debug("Terminal", "Terminal " + this.name + " exited with code " + res.exitCode); + if (this.callback) { this.callback(res.exitCode); } - - Terminal.terminalMap.delete(this.name); - log.debug("Terminal", "Terminal " + this.name + " exited with code " + res.exitCode); }); } diff --git a/docker/Dockerfile b/docker/Dockerfile index 868ded2..80505c7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,3 +1,6 @@ +############################################ +# ⭐ Main Image +############################################ FROM louislam/dockge:base WORKDIR /app COPY --chown=node:node . . @@ -7,3 +10,10 @@ VOLUME /app/data EXPOSE 5001 ENTRYPOINT ["/usr/bin/dumb-init", "--"] CMD ["tsx", "./backend/index.ts"] + + +############################################ +# Mark as Nightly +############################################ +FROM release AS nightly +RUN pnpm run mark-as-nightly diff --git a/extra/mark-as-nightly.ts b/extra/mark-as-nightly.ts new file mode 100644 index 0000000..afb863f --- /dev/null +++ b/extra/mark-as-nightly.ts @@ -0,0 +1,22 @@ +import pkg from "../package.json"; +import fs from "fs"; +import dayjs from "dayjs"; + +const oldVersion = pkg.version; +const newVersion = oldVersion + "-nightly-" + dayjs().format("YYYYMMDDHHmmss"); + +console.log("Old Version: " + oldVersion); +console.log("New Version: " + newVersion); + +if (newVersion) { + // Process package.json + pkg.version = newVersion; + //pkg.scripts.setup = pkg.scripts.setup.replaceAll(oldVersion, newVersion); + //pkg.scripts["build-docker"] = pkg.scripts["build-docker"].replaceAll(oldVersion, newVersion); + fs.writeFileSync("package.json", JSON.stringify(pkg, null, 4) + "\n"); + + // Process README.md + if (fs.existsSync("README.md")) { + fs.writeFileSync("README.md", fs.readFileSync("README.md", "utf8").replaceAll(oldVersion, newVersion)); + } +} diff --git a/extra/templates/uptime-kuma/compose.yaml b/extra/templates/uptime-kuma/compose.yaml index 31a7dca..8027975 100644 --- a/extra/templates/uptime-kuma/compose.yaml +++ b/extra/templates/uptime-kuma/compose.yaml @@ -2,7 +2,6 @@ version: '3.8' services: uptime-kuma: image: louislam/uptime-kuma:1 - container_name: uptime-kuma volumes: - ./data:/app/data ports: diff --git a/frontend/src/components/Terminal.vue b/frontend/src/components/Terminal.vue index 5b6bde0..fe767a0 100644 --- a/frontend/src/components/Terminal.vue +++ b/frontend/src/components/Terminal.vue @@ -33,6 +33,12 @@ export default { type: String, }, + // Require if mode is interactive + shell: { + type: String, + default: "bash", + }, + rows: { type: Number, default: TERMINAL_ROWS, @@ -110,7 +116,7 @@ export default { }); } else if (this.mode === "interactive") { console.debug("Create Interactive terminal:", this.name); - this.$root.getSocket().emit("interactiveTerminal", this.stackName, this.serviceName, (res) => { + this.$root.getSocket().emit("interactiveTerminal", this.stackName, this.serviceName, this.shell, (res) => { if (!res.ok) { this.$root.toastRes(res); } diff --git a/frontend/src/components/settings/About.vue b/frontend/src/components/settings/About.vue index 39179f7..aed0bb5 100644 --- a/frontend/src/components/settings/About.vue +++ b/frontend/src/components/settings/About.vue @@ -10,7 +10,7 @@ ⚠️ {{ $t("Frontend Version do not match backend version!") }} - +
diff --git a/frontend/src/layouts/Layout.vue b/frontend/src/layouts/Layout.vue index ac36091..dd49b17 100644 --- a/frontend/src/layouts/Layout.vue +++ b/frontend/src/layouts/Layout.vue @@ -13,7 +13,7 @@ Dockge - + {{ $t("New Update") }} diff --git a/frontend/src/pages/ContainerTerminal.vue b/frontend/src/pages/ContainerTerminal.vue index b1c55c8..3eb4f7f 100644 --- a/frontend/src/pages/ContainerTerminal.vue +++ b/frontend/src/pages/ContainerTerminal.vue @@ -1,13 +1,13 @@ @@ -27,12 +27,25 @@ export default { stackName() { return this.$route.params.stackName; }, + shell() { + return this.$route.params.type; + }, serviceName() { return this.$route.params.serviceName; }, terminalName() { return getContainerExecTerminalName(this.stackName, this.serviceName, 0); - } + }, + sh() { + return { + name: "containerTerminal", + params: { + stackName: this.stackName, + serviceName: this.serviceName, + type: "sh", + }, + }; + }, }, mounted() { diff --git a/frontend/src/pages/Settings.vue b/frontend/src/pages/Settings.vue index 628de33..c5ac408 100644 --- a/frontend/src/pages/Settings.vue +++ b/frontend/src/pages/Settings.vue @@ -74,10 +74,9 @@ export default { subMenus() { return { - /* general: { title: this.$t("General"), - },*/ + }, appearance: { title: this.$t("Appearance"), }, diff --git a/package.json b/package.json index 521341a..eab18ee 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,10 @@ "dev:frontend": "cross-env NODE_ENV=development vite --host --config ./frontend/vite.config.ts", "build:frontend": "vite build --config ./frontend/vite.config.ts", "build:docker-base": "docker build -t louislam/dockge:base -f ./docker/Base.Dockerfile .", - "build:docker": "pnpm run build:frontend && docker build -t louislam/dockge:latest -f ./docker/Dockerfile .", - "start-docker": "docker run --rm -p 5001:5001 --name dockge louislam/dockge:latest" + "build:docker": "pnpm run build:frontend && docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:latest -f ./docker/Dockerfile . --push", + "build:docker-nightly": "pnpm run build:frontend && docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/dockge:nightly --target nightly -f ./docker/Dockerfile . --push", + "start-docker": "docker run --rm -p 5001:5001 --name dockge louislam/dockge:latest", + "mark-as-nightly": "tsx ./extra/mark-as-nightly.ts" }, "dependencies": { "@homebridge/node-pty-prebuilt-multiarch": "~0.11.7",