added yaml file variable for swarm mode checks

This commit is contained in:
Vinay Dawani 2022-12-11 03:03:20 -05:00
parent f51e755216
commit fb883c7b27
4 changed files with 54 additions and 46 deletions

View file

@ -14,7 +14,8 @@ export default async function handler(req, res) {
}
try {
const docker = new Docker(getDockerArguments(containerServer));
const dockerArgs = getDockerArguments(containerServer)
const docker = new Docker(dockerArgs.conn);
const containers = await docker.listContainers({
all: true,
});
@ -41,27 +42,30 @@ export default async function handler(req, res) {
return;
}
// Try with a service deployed in Docker Swarm
const tasks = await docker.listTasks({
filters: {
service: [containerName],
// A service can have several offline containers, so we only look for an active one.
'desired-state': ['running']
// Try with a service deployed in Docker Swarm, if enabled
if (dockerArgs.swarm) {
const tasks = await docker.listTasks({
filters: {
service: [containerName],
// A service can have several offline containers, so we only look for an active one.
"desired-state": ["running"],
},
})
.catch(() => []);
// For now we are only interested in the first one (in case replicas > 1).
// TODO: Show the result for all replicas/containers?
const taskContainerId = tasks.at(0)?.Status?.ContainerStatus?.ContainerID;
if (taskContainerId) {
const container = docker.getContainer(taskContainerId);
const stats = await container.stats({ stream: false });
res.status(200).json({
stats,
});
return;
}
}).catch(() => []);
// For now we are only interested in the first one (in case replicas > 1).
// TODO: Show the result for all replicas/containers?
const taskContainerId = tasks.at(0)?.Status?.ContainerStatus?.ContainerID
if (taskContainerId) {
const container = docker.getContainer(taskContainerId);
const stats = await container.stats({ stream: false });
res.status(200).json({
stats,
});
return;
}
res.status(200).send({