refactor(docker): sort container lists by name

- Add sorting to container retrieval methods in docker service
- Ensure consistent container list ordering across different container fetching functions
- Improve readability and predictability of container list results
This commit is contained in:
Mauricio Siu
2025-03-08 17:56:20 -06:00
parent c89f957133
commit 08d7c4e1c3

View File

@@ -136,7 +136,8 @@ export const getContainersByAppNameMatch = async (
result = stdout.trim().split("\n");
}
const containers = result.map((line) => {
const containers = result
.map((line) => {
const parts = line.split(" | ");
const containerId = parts[0]
? parts[0].replace("CONTAINER ID : ", "").trim()
@@ -153,7 +154,8 @@ export const getContainersByAppNameMatch = async (
name,
state,
};
});
})
.sort((a, b) => a.name.localeCompare(b.name));
return containers || [];
} catch (_error) {}
@@ -190,7 +192,8 @@ export const getStackContainersByAppName = async (
result = stdout.trim().split("\n");
}
const containers = result.map((line) => {
const containers = result
.map((line) => {
const parts = line.split(" | ");
const containerId = parts[0]
? parts[0].replace("CONTAINER ID : ", "").trim()
@@ -211,7 +214,8 @@ export const getStackContainersByAppName = async (
state,
node,
};
});
})
.sort((a, b) => a.name.localeCompare(b.name));
return containers || [];
} catch (_error) {}
@@ -249,7 +253,8 @@ export const getServiceContainersByAppName = async (
result = stdout.trim().split("\n");
}
const containers = result.map((line) => {
const containers = result
.map((line) => {
const parts = line.split(" | ");
const containerId = parts[0]
? parts[0].replace("CONTAINER ID : ", "").trim()
@@ -271,7 +276,8 @@ export const getServiceContainersByAppName = async (
state,
node,
};
});
})
.sort((a, b) => a.name.localeCompare(b.name));
return containers || [];
} catch (_error) {}
@@ -306,7 +312,8 @@ export const getContainersByAppLabel = async (
const lines = stdout.trim().split("\n");
const containers = lines.map((line) => {
const containers = lines
.map((line) => {
const parts = line.split(" | ");
const containerId = parts[0]
? parts[0].replace("CONTAINER ID : ", "").trim()
@@ -322,7 +329,8 @@ export const getContainersByAppLabel = async (
name,
state,
};
});
})
.sort((a, b) => a.name.localeCompare(b.name));
return containers || [];
} catch (_error) {}