mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-10 23:38:46 +00:00
Merge branch 'main' into kubernetes
This commit is contained in:
commit
e15ba1c82c
86 changed files with 3221 additions and 583 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,
|
||||
});
|
||||
|
@ -31,18 +32,44 @@ export default async function handler(req, res) {
|
|||
const containerNames = containers.map((container) => container.Names[0].replace(/^\//, ""));
|
||||
const containerExists = containerNames.includes(containerName);
|
||||
|
||||
if (!containerExists) {
|
||||
res.status(200).send({
|
||||
error: "not found",
|
||||
if (containerExists) {
|
||||
const container = docker.getContainer(containerName);
|
||||
const stats = await container.stats({ stream: false });
|
||||
|
||||
res.status(200).json({
|
||||
stats,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const container = docker.getContainer(containerName);
|
||||
const stats = await container.stats({ stream: false });
|
||||
// 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(() => []);
|
||||
|
||||
res.status(200).json({
|
||||
stats,
|
||||
// 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({
|
||||
error: "not found",
|
||||
});
|
||||
} catch {
|
||||
res.status(500).send({
|
||||
|
|
|
@ -13,7 +13,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,
|
||||
});
|
||||
|
@ -29,18 +30,43 @@ export default async function handler(req, res) {
|
|||
const containerNames = containers.map((container) => container.Names[0].replace(/^\//, ""));
|
||||
const containerExists = containerNames.includes(containerName);
|
||||
|
||||
if (!containerExists) {
|
||||
return res.status(200).send({
|
||||
error: "not found",
|
||||
if (containerExists) {
|
||||
const container = docker.getContainer(containerName);
|
||||
const info = await container.inspect();
|
||||
|
||||
return res.status(200).json({
|
||||
status: info.State.Status,
|
||||
health: info.State.Health?.Status,
|
||||
});
|
||||
}
|
||||
|
||||
const container = docker.getContainer(containerName);
|
||||
const info = await container.inspect();
|
||||
if (dockerArgs.swarm) {
|
||||
const tasks = await docker.listTasks({
|
||||
filters: {
|
||||
service: [containerName],
|
||||
// A service can have several offline containers, we only look for an active one.
|
||||
"desired-state": ["running"],
|
||||
},
|
||||
})
|
||||
.catch(() => []);
|
||||
|
||||
return res.status(200).json({
|
||||
status: info.State.Status,
|
||||
health: info.State.Health?.Status
|
||||
// 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,
|
||||
health: info.State.Health?.Status,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return res.status(200).send({
|
||||
error: "not found",
|
||||
});
|
||||
} catch {
|
||||
return res.status(500).send({
|
||||
|
|
6
src/pages/api/releases.js
Normal file
6
src/pages/api/releases.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
import cachedFetch from "utils/proxy/cached-fetch";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const releasesURL = "https://api.github.com/repos/benphelps/homepage/releases";
|
||||
return res.send(await cachedFetch(releasesURL, 5));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue