mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-10 15:28:47 +00:00
added yaml file variable for swarm mode checks
This commit is contained in:
parent
f51e755216
commit
fb883c7b27
4 changed files with 54 additions and 46 deletions
|
@ -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({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue