refactor(docker): improve code readability by adding braces for else statements in cleanup functions

This commit is contained in:
Mauricio Siu
2025-12-06 17:53:13 -06:00
parent ba9c2ef369
commit f91a3aab25

View File

@@ -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) => {