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

Closes #694 #724

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 19 additions & 0 deletions backend/agent-socket-handlers/docker-socket-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,25 @@ export class DockerSocketHandler extends AgentSocketHandler {
}
});

agentSocket.on("forceDeleteStack", async (name : unknown, callback) => {
try {
checkLogin(socket);
if (typeof(name) !== "string") {
throw new ValidationError("Name must be a string");
}
const stack = await Stack.getStack(server, name);
await stack.forceDelete(socket);
server.sendStackList();
callbackResult({
ok: true,
msg: "Deleted",
msgi18n: true,
}, callback);
} catch (e) {
callbackError(e, callback);
}
});

agentSocket.on("getStack", async (stackName : unknown, callback) => {
try {
checkLogin(socket);
Expand Down
19 changes: 16 additions & 3 deletions backend/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class Stack {

async deploy(socket : DockgeSocket) : Promise<number> {
const terminalName = getComposeTerminalName(socket.endpoint, this.name);
let exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", [ "compose", "up", "-d", "--remove-orphans" ], this.path);
let exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", ["compose", "up", "-d", "--remove-orphans"], this.path);
if (exitCode !== 0) {
throw new Error("Failed to deploy, please check the terminal output for more information.");
}
Expand All @@ -217,9 +217,9 @@ export class Stack {

async delete(socket: DockgeSocket) : Promise<number> {
const terminalName = getComposeTerminalName(socket.endpoint, this.name);
let exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", [ "compose", "down", "--remove-orphans" ], this.path);
let exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", ["compose", "down", "--remove-orphans"], this.path);
if (exitCode !== 0) {
throw new Error("Failed to delete, please check the terminal output for more information.");
throw new Error(`Failed to delete ${this.name}, please check the terminal output for more information.`);
}

// Remove the stack folder
Expand All @@ -231,6 +231,19 @@ export class Stack {
return exitCode;
}

async forceDelete(socket: DockgeSocket): Promise<number> {
const terminalName = getComposeTerminalName(socket.endpoint, this.name);
let exitCode = await Terminal.exec(this.server, socket, terminalName, "docker", ["compose", "down", "-v", "--remove-orphans"], this.path);

// Remove the stack folder
await fsAsync.rm(this.path, {
recursive: true,
force: true
});

return exitCode;
}

async updateStatus() {
let statusList = await Stack.getStatusList();
let status = statusList.get(this.name);
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"stackName": "Stack Name",
"deployStack": "Deploy",
"deleteStack": "Delete",
"forceDeleteStack": "Force Delete",
"stopStack": "Stop",
"restartStack": "Restart",
"updateStack": "Update",
Expand All @@ -25,6 +26,7 @@
"saveStackDraft": "Save",
"notAvailableShort": "N/A",
"deleteStackMsg": "Are you sure you want to delete this stack?",
"forceDeleteStackMsg": "Force deleting may leave behind some files or configuration. Are you sure you want to force delete this stack?",
"stackNotManagedByDockgeMsg": "This stack is not managed by Dockge.",
"primaryHostname": "Primary Hostname",
"general": "General",
Expand Down
28 changes: 25 additions & 3 deletions frontend/src/pages/Compose.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<transition name="slide-fade" appear>
<div>
<h1 v-if="isAdd" class="mb-3">{{$t("compose")}}</h1>
<h1 v-if="isAdd" class="mb-3">{{ $t("compose") }}</h1>
<h1 v-else class="mb-3">
<Uptime :stack="globalStack" :pill="true" /> {{ stack.name }}
<span v-if="$root.agentCount > 1" class="agent-name">
Expand Down Expand Up @@ -55,10 +55,14 @@
</div>

<button v-if="isEditMode && !isAdd" class="btn btn-normal" :disabled="processing" @click="discardStack">{{ $t("discardStack") }}</button>
<button v-if="!isEditMode" class="btn btn-danger" :disabled="processing" @click="showDeleteDialog = !showDeleteDialog">
<button v-if="!isEditMode && !errorDelete" class="btn btn-danger" :disabled="processing" @click="showDeleteDialog = !showDeleteDialog">
<font-awesome-icon icon="trash" class="me-1" />
{{ $t("deleteStack") }}
</button>
<button v-if="errorDelete" class="btn btn-danger" :disabled="processing" @click="showForceDeleteDialog = !showForceDeleteDialog">
<font-awesome-icon icon="trash" class="me-1" />
{{ $t("forceDeleteStack") }}
</button>
</div>

<!-- URLs -->
Expand Down Expand Up @@ -150,7 +154,7 @@

<!-- Combined Terminal Output -->
<div v-show="!isEditMode">
<h4 class="mb-3">{{$t("terminal")}}</h4>
<h4 class="mb-3">{{ $t("terminal") }}</h4>
<Terminal
ref="combinedTerminal"
class="mb-3 terminal"
Expand Down Expand Up @@ -232,6 +236,11 @@
<BModal v-model="showDeleteDialog" :okTitle="$t('deleteStack')" okVariant="danger" @ok="deleteDialog">
{{ $t("deleteStackMsg") }}
</BModal>

<!-- Force Delete Dialog -->
<BModal v-model="showForceDeleteDialog" :okTitle="$t('forceDeleteStack')" okVariant="danger" @ok="forceDeleteDialog">
{{ $t("forceDeleteStackMsg") }}
</BModal>
</div>
</transition>
</template>
Expand Down Expand Up @@ -307,8 +316,10 @@ export default {
},
serviceStatusList: {},
isEditMode: false,
errorDelete: false,
submitted: false,
showDeleteDialog: false,
showForceDeleteDialog: false,
newContainerName: "",
stopServiceStatusTimeout: false,
};
Expand Down Expand Up @@ -647,6 +658,17 @@ export default {

deleteDialog() {
this.$root.emitAgent(this.endpoint, "deleteStack", this.stack.name, (res) => {
this.$root.toastRes(res);
if (res.ok) {
this.$router.push("/");
} else {
this.errorDelete = true;
}
});
},

forceDeleteDialog() {
this.$root.emitAgent(this.endpoint, "forceDeleteStack", this.stack.name, (res) => {
this.$root.toastRes(res);
if (res.ok) {
this.$router.push("/");
Expand Down
Loading
Loading