feat(docker): hide containers with label homarr.hide (#4506)
Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
This commit is contained in:
@@ -8,3 +8,4 @@ export type { Docker };
|
|||||||
export const containerStates = ["created", "running", "paused", "restarting", "exited", "removing", "dead"] as const;
|
export const containerStates = ["created", "running", "paused", "restarting", "exited", "removing", "dead"] as const;
|
||||||
|
|
||||||
export type ContainerState = (typeof containerStates)[number];
|
export type ContainerState = (typeof containerStates)[number];
|
||||||
|
export * from "./labels";
|
||||||
|
|||||||
4
packages/docker/src/labels.ts
Normal file
4
packages/docker/src/labels.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export const dockerLabels = {
|
||||||
|
// Label to hide a container from Homarrs docker integration
|
||||||
|
hide: "homarr.hide",
|
||||||
|
} as const;
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
"@homarr/common": "workspace:^0.1.0",
|
"@homarr/common": "workspace:^0.1.0",
|
||||||
"@homarr/db": "workspace:^0.1.0",
|
"@homarr/db": "workspace:^0.1.0",
|
||||||
"@homarr/definitions": "workspace:^0.1.0",
|
"@homarr/definitions": "workspace:^0.1.0",
|
||||||
|
"@homarr/docker": "workspace:^0.1.0",
|
||||||
"@homarr/integrations": "workspace:^0.1.0",
|
"@homarr/integrations": "workspace:^0.1.0",
|
||||||
"@homarr/log": "workspace:^0.1.0",
|
"@homarr/log": "workspace:^0.1.0",
|
||||||
"@homarr/redis": "workspace:^0.1.0",
|
"@homarr/redis": "workspace:^0.1.0",
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import type { ContainerInfo, ContainerStats } from "dockerode";
|
|||||||
|
|
||||||
import { db, like, or } from "@homarr/db";
|
import { db, like, or } from "@homarr/db";
|
||||||
import { icons } from "@homarr/db/schema";
|
import { icons } from "@homarr/db/schema";
|
||||||
|
import type { ContainerState } from "@homarr/docker";
|
||||||
|
import { dockerLabels, DockerSingleton } from "@homarr/docker";
|
||||||
|
|
||||||
import type { ContainerState } from "../../docker/src";
|
|
||||||
import { DockerSingleton } from "../../docker/src";
|
|
||||||
import { createCachedWidgetRequestHandler } from "./lib/cached-widget-request-handler";
|
import { createCachedWidgetRequestHandler } from "./lib/cached-widget-request-handler";
|
||||||
|
|
||||||
export const dockerContainersRequestHandler = createCachedWidgetRequestHandler({
|
export const dockerContainersRequestHandler = createCachedWidgetRequestHandler({
|
||||||
@@ -27,13 +27,11 @@ async function getContainersWithStatsAsync() {
|
|||||||
const containers = await Promise.all(
|
const containers = await Promise.all(
|
||||||
dockerInstances.map(async ({ instance, host }) => {
|
dockerInstances.map(async ({ instance, host }) => {
|
||||||
const instanceContainers = await instance.listContainers({ all: true });
|
const instanceContainers = await instance.listContainers({ all: true });
|
||||||
return instanceContainers.map((container) => ({
|
return instanceContainers
|
||||||
...container,
|
.filter((container) => dockerLabels.hide in container.Labels === false)
|
||||||
instance: host,
|
.map((container) => ({ ...container, instance: host }));
|
||||||
}));
|
|
||||||
}),
|
}),
|
||||||
).then((res) => res.flat());
|
).then((res) => res.flat());
|
||||||
|
|
||||||
const likeQueries = containers.map((container) => like(icons.name, `%${extractImage(container)}%`));
|
const likeQueries = containers.map((container) => like(icons.name, `%${extractImage(container)}%`));
|
||||||
|
|
||||||
const dbIcons =
|
const dbIcons =
|
||||||
|
|||||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -1895,6 +1895,9 @@ importers:
|
|||||||
'@homarr/definitions':
|
'@homarr/definitions':
|
||||||
specifier: workspace:^0.1.0
|
specifier: workspace:^0.1.0
|
||||||
version: link:../definitions
|
version: link:../definitions
|
||||||
|
'@homarr/docker':
|
||||||
|
specifier: workspace:^0.1.0
|
||||||
|
version: link:../docker
|
||||||
'@homarr/integrations':
|
'@homarr/integrations':
|
||||||
specifier: workspace:^0.1.0
|
specifier: workspace:^0.1.0
|
||||||
version: link:../integrations
|
version: link:../integrations
|
||||||
|
|||||||
Reference in New Issue
Block a user