refactor: streamline container parsing logic in Docker service functions

This commit is contained in:
Mauricio Siu
2025-03-15 20:43:22 -06:00
parent 31164c9798
commit 8d9d00d0c6

View File

@@ -136,8 +136,7 @@ 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()
@@ -154,8 +153,7 @@ export const getContainersByAppNameMatch = async (
name,
state,
};
})
.sort((a, b) => a.name.localeCompare(b.name));
});
return containers || [];
} catch (_error) {}
@@ -192,8 +190,7 @@ 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()
@@ -214,8 +211,7 @@ export const getStackContainersByAppName = async (
state,
node,
};
})
.sort((a, b) => a.name.localeCompare(b.name));
});
return containers || [];
} catch (_error) {}
@@ -253,8 +249,7 @@ 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()
@@ -276,8 +271,7 @@ export const getServiceContainersByAppName = async (
state,
node,
};
})
.sort((a, b) => a.name.localeCompare(b.name));
});
return containers || [];
} catch (_error) {}
@@ -318,8 +312,7 @@ 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()
@@ -335,8 +328,7 @@ export const getContainersByAppLabel = async (
name,
state,
};
})
.sort((a, b) => a.name.localeCompare(b.name));
});
return containers || [];
} catch (_error) {}