mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-06 12:12:16 +00:00
Merge pull request #3258 from Dokploy/fix/long-request-on-cleanup
Fix/long request on cleanup
This commit is contained in:
@@ -173,7 +173,7 @@ export const ShowStorageActions = ({ serverId }: Props) => {
|
|||||||
serverId: serverId,
|
serverId: serverId,
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
toast.success("Cleaned all");
|
toast.success("Cleaning in progress... Please wait");
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
toast.error("Error cleaning all");
|
toast.error("Error cleaning all");
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
checkGPUStatus,
|
checkGPUStatus,
|
||||||
checkPortInUse,
|
checkPortInUse,
|
||||||
cleanupAll,
|
cleanupAll,
|
||||||
|
cleanupAllBackground,
|
||||||
cleanupBuilders,
|
cleanupBuilders,
|
||||||
cleanupContainers,
|
cleanupContainers,
|
||||||
cleanupImages,
|
cleanupImages,
|
||||||
@@ -193,9 +194,10 @@ export const settingsRouter = createTRPCRouter({
|
|||||||
cleanAll: adminProcedure
|
cleanAll: adminProcedure
|
||||||
.input(apiServerSchema)
|
.input(apiServerSchema)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
await cleanupAll(input?.serverId);
|
// Execute cleanup in background and return immediately to avoid gateway timeouts
|
||||||
|
const result = await cleanupAllBackground(input?.serverId);
|
||||||
|
|
||||||
return true;
|
return result;
|
||||||
}),
|
}),
|
||||||
cleanMonitoring: adminProcedure.mutation(async () => {
|
cleanMonitoring: adminProcedure.mutation(async () => {
|
||||||
if (IS_CLOUD) {
|
if (IS_CLOUD) {
|
||||||
|
|||||||
@@ -171,9 +171,17 @@ ${exec}
|
|||||||
|
|
||||||
echo "Execution completed."`;
|
echo "Execution completed."`;
|
||||||
|
|
||||||
|
const cleanupCommands = {
|
||||||
|
containers: "docker container prune --force",
|
||||||
|
images: "docker image prune --all --force",
|
||||||
|
builders: "docker builder prune --all --force",
|
||||||
|
system: "docker system prune --all --force",
|
||||||
|
volumes: "docker volume prune --all --force",
|
||||||
|
};
|
||||||
|
|
||||||
export const cleanupContainers = async (serverId?: string) => {
|
export const cleanupContainers = async (serverId?: string) => {
|
||||||
try {
|
try {
|
||||||
const command = "docker container prune --force";
|
const command = cleanupCommands.containers;
|
||||||
|
|
||||||
if (serverId) {
|
if (serverId) {
|
||||||
await execAsyncRemote(serverId, dockerSafeExec(command));
|
await execAsyncRemote(serverId, dockerSafeExec(command));
|
||||||
@@ -189,7 +197,7 @@ export const cleanupContainers = async (serverId?: string) => {
|
|||||||
|
|
||||||
export const cleanupImages = async (serverId?: string) => {
|
export const cleanupImages = async (serverId?: string) => {
|
||||||
try {
|
try {
|
||||||
const command = "docker image prune --all --force";
|
const command = cleanupCommands.images;
|
||||||
|
|
||||||
if (serverId) {
|
if (serverId) {
|
||||||
await execAsyncRemote(serverId, dockerSafeExec(command));
|
await execAsyncRemote(serverId, dockerSafeExec(command));
|
||||||
@@ -203,7 +211,7 @@ export const cleanupImages = async (serverId?: string) => {
|
|||||||
|
|
||||||
export const cleanupVolumes = async (serverId?: string) => {
|
export const cleanupVolumes = async (serverId?: string) => {
|
||||||
try {
|
try {
|
||||||
const command = "docker volume prune --all --force";
|
const command = cleanupCommands.volumes;
|
||||||
|
|
||||||
if (serverId) {
|
if (serverId) {
|
||||||
await execAsyncRemote(serverId, dockerSafeExec(command));
|
await execAsyncRemote(serverId, dockerSafeExec(command));
|
||||||
@@ -219,7 +227,7 @@ export const cleanupVolumes = async (serverId?: string) => {
|
|||||||
|
|
||||||
export const cleanupBuilders = async (serverId?: string) => {
|
export const cleanupBuilders = async (serverId?: string) => {
|
||||||
try {
|
try {
|
||||||
const command = "docker builder prune --all --force";
|
const command = cleanupCommands.builders;
|
||||||
|
|
||||||
if (serverId) {
|
if (serverId) {
|
||||||
await execAsyncRemote(serverId, dockerSafeExec(command));
|
await execAsyncRemote(serverId, dockerSafeExec(command));
|
||||||
@@ -235,7 +243,7 @@ export const cleanupBuilders = async (serverId?: string) => {
|
|||||||
|
|
||||||
export const cleanupSystem = async (serverId?: string) => {
|
export const cleanupSystem = async (serverId?: string) => {
|
||||||
try {
|
try {
|
||||||
const command = "docker system prune --all --force";
|
const command = cleanupCommands.system;
|
||||||
|
|
||||||
if (serverId) {
|
if (serverId) {
|
||||||
await execAsyncRemote(serverId, dockerSafeExec(command));
|
await execAsyncRemote(serverId, dockerSafeExec(command));
|
||||||
@@ -256,6 +264,34 @@ export const cleanupAll = async (serverId?: string) => {
|
|||||||
await cleanupSystem(serverId);
|
await cleanupSystem(serverId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const cleanupAllBackground = async (serverId?: string) => {
|
||||||
|
Promise.allSettled(
|
||||||
|
Object.values(cleanupCommands).map(async (command) => {
|
||||||
|
try {
|
||||||
|
if (serverId) {
|
||||||
|
await execAsyncRemote(serverId, dockerSafeExec(command));
|
||||||
|
} else {
|
||||||
|
await execAsync(dockerSafeExec(command));
|
||||||
|
}
|
||||||
|
} catch (error) {}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.then((results) => {
|
||||||
|
const failed = results.filter((r) => r.status === "rejected");
|
||||||
|
if (failed.length > 0) {
|
||||||
|
console.error(`Docker cleanup: ${failed.length} operations failed`);
|
||||||
|
} else {
|
||||||
|
console.log("Docker cleanup completed successfully");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => console.error("Error in cleanup:", error));
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: "scheduled",
|
||||||
|
message: "Docker cleanup has been initiated in the background",
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export const startService = async (appName: string) => {
|
export const startService = async (appName: string) => {
|
||||||
try {
|
try {
|
||||||
await execAsync(`docker service scale ${appName}=1 `);
|
await execAsync(`docker service scale ${appName}=1 `);
|
||||||
|
|||||||
Reference in New Issue
Block a user