Skip to content

Commit 60ab98a

Browse files
feat(docker): hide containers with label homarr.hide (#4506)
Co-authored-by: Meier Lukas <[email protected]>
1 parent 9a3feb4 commit 60ab98a

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

packages/docker/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export type { Docker };
88
export const containerStates = ["created", "running", "paused", "restarting", "exited", "removing", "dead"] as const;
99

1010
export type ContainerState = (typeof containerStates)[number];
11+
export * from "./labels";

packages/docker/src/labels.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const dockerLabels = {
2+
// Label to hide a container from Homarrs docker integration
3+
hide: "homarr.hide",
4+
} as const;

packages/request-handler/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@homarr/common": "workspace:^0.1.0",
2727
"@homarr/db": "workspace:^0.1.0",
2828
"@homarr/definitions": "workspace:^0.1.0",
29+
"@homarr/docker": "workspace:^0.1.0",
2930
"@homarr/integrations": "workspace:^0.1.0",
3031
"@homarr/log": "workspace:^0.1.0",
3132
"@homarr/redis": "workspace:^0.1.0",

packages/request-handler/src/docker.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import type { ContainerInfo, ContainerStats } from "dockerode";
33

44
import { db, like, or } from "@homarr/db";
55
import { icons } from "@homarr/db/schema";
6+
import type { ContainerState } from "@homarr/docker";
7+
import { dockerLabels, DockerSingleton } from "@homarr/docker";
68

7-
import type { ContainerState } from "../../docker/src";
8-
import { DockerSingleton } from "../../docker/src";
99
import { createCachedWidgetRequestHandler } from "./lib/cached-widget-request-handler";
1010

1111
export const dockerContainersRequestHandler = createCachedWidgetRequestHandler({
@@ -27,13 +27,11 @@ async function getContainersWithStatsAsync() {
2727
const containers = await Promise.all(
2828
dockerInstances.map(async ({ instance, host }) => {
2929
const instanceContainers = await instance.listContainers({ all: true });
30-
return instanceContainers.map((container) => ({
31-
...container,
32-
instance: host,
33-
}));
30+
return instanceContainers
31+
.filter((container) => dockerLabels.hide in container.Labels === false)
32+
.map((container) => ({ ...container, instance: host }));
3433
}),
3534
).then((res) => res.flat());
36-
3735
const likeQueries = containers.map((container) => like(icons.name, `%${extractImage(container)}%`));
3836

3937
const dbIcons =

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)