Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip #1

Merged
merged 27 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
  • Loading branch information
louislam committed Nov 6, 2023
commit 21e736459e5de62abeb55ab78bbad5d532a8f317
2 changes: 1 addition & 1 deletion backend/check-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion backend/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion backend/dockge-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions backend/socket-handlers/terminal-socket-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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);

Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions backend/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions backend/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
10 changes: 10 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
############################################
# ⭐ Main Image
############################################
FROM louislam/dockge:base
WORKDIR /app
COPY --chown=node:node . .
Expand All @@ -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
22 changes: 22 additions & 0 deletions extra/mark-as-nightly.ts
Original file line number Diff line number Diff line change
@@ -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));
}
}
1 change: 0 additions & 1 deletion extra/templates/uptime-kuma/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ version: '3.8'
services:
uptime-kuma:
image: louislam/uptime-kuma:1
container_name: uptime-kuma
volumes:
- ./data:/app/data
ports:
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/components/Terminal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export default {
type: String,
},

// Require if mode is interactive
shell: {
type: String,
default: "bash",
},

rows: {
type: Number,
default: TERMINAL_ROWS,
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/settings/About.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
⚠️ {{ $t("Frontend Version do not match backend version!") }}
</div>

<div class="my-3 update-link"><a href="https://github.com/louislam/uptime-kuma/releases" target="_blank" rel="noopener">{{ $t("Check Update On GitHub") }}</a></div>
<div class="my-3 update-link"><a href="https://github.com/louislam/dockge/releases" target="_blank" rel="noopener">{{ $t("Check Update On GitHub") }}</a></div>

<div class="mt-1">
<div class="form-check">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layouts/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<span class="fs-4 title">Dockge</span>
</router-link>

<a v-if="hasNewVersion" target="_blank" href="https://github.com/louislam/uptime-kuma/releases" class="btn btn-info me-3">
<a v-if="hasNewVersion" target="_blank" href="https://github.com/louislam/dockge/releases" class="btn btn-info me-3">
<font-awesome-icon icon="arrow-alt-circle-up" /> {{ $t("New Update") }}
</a>

Expand Down
27 changes: 20 additions & 7 deletions frontend/src/pages/ContainerTerminal.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<transition name="slide-fade" appear>
<div>
<h1 class="mb-3">Bash</h1>
<p>
Stack: {{ stackName }}<br />
Container: {{ serviceName }}
</p>
<h1 class="mb-3">Terminal - {{ serviceName }} ({{ stackName }})</h1>

<Terminal class="terminal" :rows="20" mode="interactive" :name="terminalName" :stack-name="stackName" :service-name="serviceName"></Terminal>
<div class="mb-3">
<router-link :to="sh" class="btn btn-normal me-2">Switch to sh</router-link>
</div>

<Terminal class="terminal" :rows="20" mode="interactive" :name="terminalName" :stack-name="stackName" :service-name="serviceName" :shell="shell"></Terminal>
</div>
</transition>
</template>
Expand All @@ -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() {

Expand Down
3 changes: 1 addition & 2 deletions frontend/src/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ export default {

subMenus() {
return {
/*
general: {
title: this.$t("General"),
},*/
},
appearance: {
title: this.$t("Appearance"),
},
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down