|
|
@ -29,17 +29,38 @@ export default async function handler(req, res) {
|
|
|
|
const containerNames = containers.map((container) => container.Names[0].replace(/^\//, ""));
|
|
|
|
const containerNames = containers.map((container) => container.Names[0].replace(/^\//, ""));
|
|
|
|
const containerExists = containerNames.includes(containerName);
|
|
|
|
const containerExists = containerNames.includes(containerName);
|
|
|
|
|
|
|
|
|
|
|
|
if (!containerExists) {
|
|
|
|
if (containerExists) {
|
|
|
|
return res.status(200).send({
|
|
|
|
const container = docker.getContainer(containerName);
|
|
|
|
error: "not found",
|
|
|
|
const info = await container.inspect();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json({
|
|
|
|
|
|
|
|
status: info.State.Status,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const container = docker.getContainer(containerName);
|
|
|
|
const tasks = await docker.listTasks({
|
|
|
|
const info = await container.inspect();
|
|
|
|
filters: {
|
|
|
|
|
|
|
|
service: [containerName],
|
|
|
|
|
|
|
|
// A service can have several offline containers, 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 info = await container.inspect();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json({
|
|
|
|
|
|
|
|
status: info.State.Status,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return res.status(200).json({
|
|
|
|
return res.status(200).send({
|
|
|
|
status: info.State.Status,
|
|
|
|
error: "not found",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch {
|
|
|
|
} catch {
|
|
|
|
return res.status(500).send({
|
|
|
|
return res.status(500).send({
|
|
|
|