From f91a3aab252d76afaf00f563bc68433f39f77054 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Sat, 6 Dec 2025 17:53:13 -0600 Subject: [PATCH] refactor(docker): improve code readability by adding braces for else statements in cleanup functions --- packages/server/src/utils/docker/utils.ts | 41 +++++++---------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/packages/server/src/utils/docker/utils.ts b/packages/server/src/utils/docker/utils.ts index 66ec23824..c5f894b4d 100644 --- a/packages/server/src/utils/docker/utils.ts +++ b/packages/server/src/utils/docker/utils.ts @@ -177,7 +177,9 @@ export const cleanupContainers = async (serverId?: string) => { if (serverId) { await execAsyncRemote(serverId, dockerSafeExec(command)); - } else await execAsync(dockerSafeExec(command)); + } else { + await execAsync(dockerSafeExec(command)); + } } catch (error) { console.error(error); @@ -205,7 +207,9 @@ export const cleanupVolumes = async (serverId?: string) => { if (serverId) { await execAsyncRemote(serverId, dockerSafeExec(command)); - } else await execAsync(dockerSafeExec(command)); + } else { + await execAsync(dockerSafeExec(command)); + } } catch (error) { console.error(error); @@ -219,7 +223,9 @@ export const cleanupBuilders = async (serverId?: string) => { if (serverId) { await execAsyncRemote(serverId, dockerSafeExec(command)); - } else await execAsync(dockerSafeExec(command)); + } else { + await execAsync(dockerSafeExec(command)); + } } catch (error) { console.error(error); @@ -233,7 +239,9 @@ export const cleanupSystem = async (serverId?: string) => { if (serverId) { await execAsyncRemote(serverId, dockerSafeExec(command)); - } else await execAsync(dockerSafeExec(command)); + } else { + await execAsync(dockerSafeExec(command)); + } } catch (error) { console.error(error); @@ -241,37 +249,12 @@ export const cleanupSystem = async (serverId?: string) => { } }; -export const cleanupInactiveContainers = async () => { - try { - const containers = await docker.listContainers({ all: true }); - const inactiveContainers = containers.filter( - (container) => container.State !== "running", - ); - - for (const container of inactiveContainers) { - await docker.getContainer(container.Id).remove({ force: true }); - console.log(`Cleaning up inactive container: ${container.Id}`); - } - } catch (error) { - console.error("Error cleaning up inactive containers:", error); - throw error; - } -}; - export const cleanupAll = async (serverId?: string) => { await cleanupContainers(serverId); await cleanupImages(serverId); await cleanupVolumes(serverId); await cleanupBuilders(serverId); await cleanupSystem(serverId); - - /** - * This wasn't being used. If it's ready, it should be used here. - * - * https://github.com/Dokploy/dokploy/pull/3064 - * https://github.com/fir4tozden - */ - // await cleanupInactiveContainers(); }; export const startService = async (appName: string) => {