From 7d08646a2902b6fb89e399d2ee5e84a8256257f0 Mon Sep 17 00:00:00 2001 From: Noan Date: Mon, 22 Aug 2022 21:51:23 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=94=A7=20add=20configuration=20to=20d?= =?UTF-8?q?ocker=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/configs/default.json | 37 ++++++++++++++++------- src/modules/docker/ContainerActionBar.tsx | 11 +++++-- src/modules/docker/DockerModule.tsx | 14 ++++++--- src/modules/docker/DockerTable.tsx | 4 ++- 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/data/configs/default.json b/data/configs/default.json index 3f2acea0d..9597d620c 100644 --- a/data/configs/default.json +++ b/data/configs/default.json @@ -1,20 +1,35 @@ { "name": "default", - "services": [ - { - "name": "example", - "id": "09c45847-8afc-4c1a-9697-f03192de948a", - "type": "Other", - "icon": "https://c.tenor.com/o656qFKDzeUAAAAC/rick-astley-never-gonna-give-you-up.gif", - "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ" - } - ], + "services": [], "settings": { - "searchUrl": "https://google.com/search?q=" + "searchUrl": "https://google.com/search?q=", + "appCardWidth": 0.8 }, "modules": { "Search Bar": { "enabled": true + }, + "Docker": { + "enabled": true, + "options": { + "endpoint": { + "value": "http://192.168.1.56:2376" + } + } + }, + "Weather": { + "enabled": true, + "options": { + "location": { + "value": "Perros-Guirec" + } + } + }, + "Download Speed": { + "enabled": false + }, + "Ping Services": { + "enabled": true } } -} \ No newline at end of file +} diff --git a/src/modules/docker/ContainerActionBar.tsx b/src/modules/docker/ContainerActionBar.tsx index 0ae7e2ed1..b25c03c11 100644 --- a/src/modules/docker/ContainerActionBar.tsx +++ b/src/modules/docker/ContainerActionBar.tsx @@ -11,9 +11,9 @@ import { } from '@tabler/icons'; import axios from 'axios'; import Dockerode from 'dockerode'; +import { useState } from 'react'; import { tryMatchService } from '../../tools/addToHomarr'; import { AddAppShelfItemForm } from '../../components/AppShelf/AddAppShelfItem'; -import { useState } from 'react'; function sendDockerCommand( action: string, @@ -30,7 +30,7 @@ function sendDockerCommand( disallowClose: true, }); axios - .get(`/api/docker/container/${containerId}?action=${action}`) + .get(`localhost:2375/containers/${containerId}/${action}`) .then((res) => { updateNotification({ id: containerId, @@ -88,6 +88,7 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction variant="light" color="orange" radius="md" + disabled={selected.length === 0} > Restart @@ -103,6 +104,7 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction variant="light" color="red" radius="md" + disabled={selected.length === 0} > Stop @@ -118,10 +120,11 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction variant="light" color="green" radius="md" + disabled={selected.length === 0} > Start - @@ -156,6 +160,7 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction ) ) } + disabled={selected.length === 0} > Remove diff --git a/src/modules/docker/DockerModule.tsx b/src/modules/docker/DockerModule.tsx index caca75306..3981b36ca 100644 --- a/src/modules/docker/DockerModule.tsx +++ b/src/modules/docker/DockerModule.tsx @@ -1,4 +1,4 @@ -import { ActionIcon, Drawer, Group, LoadingOverlay, Text, Tooltip } from '@mantine/core'; +import { ActionIcon, Drawer, Text, Tooltip } from '@mantine/core'; import axios from 'axios'; import { useEffect, useState } from 'react'; import Docker from 'dockerode'; @@ -14,6 +14,12 @@ export const DockerModule: IModule = { description: 'Allows you to easily manage your torrents', icon: IconBrandDocker, component: DockerMenuButton, + options: { + endpoint: { + name: 'Docker Api endpoint entry', + value: '', + }, + }, }; export default function DockerMenuButton(props: any) { @@ -21,6 +27,7 @@ export default function DockerMenuButton(props: any) { const [containers, setContainers] = useState([]); const [selection, setSelection] = useState([]); const { config } = useConfig(); + const dockerApi = (config?.modules?.[DockerModule.title]?.options?.endpoint?.value as string) ?? ''; // http://192.168.1.56:2376 const moduleEnabled = config.modules?.[DockerModule.title]?.enabled ?? false; useEffect(() => { @@ -33,7 +40,7 @@ export default function DockerMenuButton(props: any) { } setTimeout(() => { axios - .get('/api/docker/containers') + .get(`${dockerApi}/v1.41/containers/json`) .then((res) => { setContainers(res.data); setSelection([]); @@ -54,8 +61,7 @@ export default function DockerMenuButton(props: any) { if (!exists) { return null; } - // Check if the user has at least one container - if (containers.length < 1) return null; + // Always allow user to see DockerTable component through ActionIcon in order to set Docker's settings return ( <> } value={search} onChange={handleSearchChange} + disabled={usedContainers.length === 0} /> @@ -106,9 +107,10 @@ export default function DockerTable({ From 67bd4cffc8a02a010596fd2f59f181720d7e1f42 Mon Sep 17 00:00:00 2001 From: Noan Date: Mon, 22 Aug 2022 22:51:42 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20Fix=20port=20in=20Service=20?= =?UTF-8?q?URL=20for=20Docker=20Module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tools/addToHomarr.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/addToHomarr.ts b/src/tools/addToHomarr.ts index 3c3c24cce..da421dd4e 100644 --- a/src/tools/addToHomarr.ts +++ b/src/tools/addToHomarr.ts @@ -24,12 +24,12 @@ export function tryMatchService(container: Dockerode.ContainerInfo | undefined) if (container === undefined) return {}; const name = container.Names[0].substring(1); const type = tryMatchType(container.Image); - const port = tryMatchPort(type.toLowerCase()); + const port = tryMatchPort(type.toLowerCase())?.value ?? container.Ports[0]?.PublicPort; return { name, id: container.Id, type: tryMatchType(container.Image), - url: `localhost${port ? `:${port.value}` : ''}`, + url: `localhost${port ? `:${port}` : ''}`, icon: `https://cdn.jsdelivr.net/gh/walkxhub/dashboard-icons/png/${name .replace(/\s+/g, '-') .toLowerCase()}.png`, From 684e3cb2e8074a83f9ed0d3ef6f6264418790688 Mon Sep 17 00:00:00 2001 From: Noan Date: Mon, 22 Aug 2022 22:55:07 +0200 Subject: [PATCH 3/4] Revert default.json --- data/configs/default.json | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/data/configs/default.json b/data/configs/default.json index 9597d620c..07dfe37b0 100644 --- a/data/configs/default.json +++ b/data/configs/default.json @@ -1,35 +1,20 @@ { "name": "default", - "services": [], + "services": [ + { + "name": "example", + "id": "09c45847-8afc-4c1a-9697-f03192de948a", + "type": "Other", + "icon": "https://c.tenor.com/o656qFKDzeUAAAAC/rick-astley-never-gonna-give-you-up.gif", + "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ" + } + ], "settings": { - "searchUrl": "https://google.com/search?q=", - "appCardWidth": 0.8 + "searchUrl": "https://google.com/search?q=" }, "modules": { "Search Bar": { "enabled": true - }, - "Docker": { - "enabled": true, - "options": { - "endpoint": { - "value": "http://192.168.1.56:2376" - } - } - }, - "Weather": { - "enabled": true, - "options": { - "location": { - "value": "Perros-Guirec" - } - } - }, - "Download Speed": { - "enabled": false - }, - "Ping Services": { - "enabled": true } } } From 5ab2f2a6f4d3673d3c1e93fe36b67730d3259c76 Mon Sep 17 00:00:00 2001 From: Noan Date: Mon, 22 Aug 2022 23:01:47 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=90=9B=20Fix=20port=20in=20Service=20?= =?UTF-8?q?URL=20for=20Docker=20Module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/configs/default.json | 2 +- src/modules/docker/ContainerActionBar.tsx | 11 +++-------- src/modules/docker/DockerModule.tsx | 14 ++++---------- src/modules/docker/DockerTable.tsx | 4 +--- 4 files changed, 9 insertions(+), 22 deletions(-) diff --git a/data/configs/default.json b/data/configs/default.json index 07dfe37b0..3f2acea0d 100644 --- a/data/configs/default.json +++ b/data/configs/default.json @@ -17,4 +17,4 @@ "enabled": true } } -} +} \ No newline at end of file diff --git a/src/modules/docker/ContainerActionBar.tsx b/src/modules/docker/ContainerActionBar.tsx index b25c03c11..0ae7e2ed1 100644 --- a/src/modules/docker/ContainerActionBar.tsx +++ b/src/modules/docker/ContainerActionBar.tsx @@ -11,9 +11,9 @@ import { } from '@tabler/icons'; import axios from 'axios'; import Dockerode from 'dockerode'; -import { useState } from 'react'; import { tryMatchService } from '../../tools/addToHomarr'; import { AddAppShelfItemForm } from '../../components/AppShelf/AddAppShelfItem'; +import { useState } from 'react'; function sendDockerCommand( action: string, @@ -30,7 +30,7 @@ function sendDockerCommand( disallowClose: true, }); axios - .get(`localhost:2375/containers/${containerId}/${action}`) + .get(`/api/docker/container/${containerId}?action=${action}`) .then((res) => { updateNotification({ id: containerId, @@ -88,7 +88,6 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction variant="light" color="orange" radius="md" - disabled={selected.length === 0} > Restart @@ -104,7 +103,6 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction variant="light" color="red" radius="md" - disabled={selected.length === 0} > Stop @@ -120,11 +118,10 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction variant="light" color="green" radius="md" - disabled={selected.length === 0} > Start - @@ -160,7 +156,6 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction ) ) } - disabled={selected.length === 0} > Remove diff --git a/src/modules/docker/DockerModule.tsx b/src/modules/docker/DockerModule.tsx index 3981b36ca..caca75306 100644 --- a/src/modules/docker/DockerModule.tsx +++ b/src/modules/docker/DockerModule.tsx @@ -1,4 +1,4 @@ -import { ActionIcon, Drawer, Text, Tooltip } from '@mantine/core'; +import { ActionIcon, Drawer, Group, LoadingOverlay, Text, Tooltip } from '@mantine/core'; import axios from 'axios'; import { useEffect, useState } from 'react'; import Docker from 'dockerode'; @@ -14,12 +14,6 @@ export const DockerModule: IModule = { description: 'Allows you to easily manage your torrents', icon: IconBrandDocker, component: DockerMenuButton, - options: { - endpoint: { - name: 'Docker Api endpoint entry', - value: '', - }, - }, }; export default function DockerMenuButton(props: any) { @@ -27,7 +21,6 @@ export default function DockerMenuButton(props: any) { const [containers, setContainers] = useState([]); const [selection, setSelection] = useState([]); const { config } = useConfig(); - const dockerApi = (config?.modules?.[DockerModule.title]?.options?.endpoint?.value as string) ?? ''; // http://192.168.1.56:2376 const moduleEnabled = config.modules?.[DockerModule.title]?.enabled ?? false; useEffect(() => { @@ -40,7 +33,7 @@ export default function DockerMenuButton(props: any) { } setTimeout(() => { axios - .get(`${dockerApi}/v1.41/containers/json`) + .get('/api/docker/containers') .then((res) => { setContainers(res.data); setSelection([]); @@ -61,7 +54,8 @@ export default function DockerMenuButton(props: any) { if (!exists) { return null; } - // Always allow user to see DockerTable component through ActionIcon in order to set Docker's settings + // Check if the user has at least one container + if (containers.length < 1) return null; return ( <> } value={search} onChange={handleSearchChange} - disabled={usedContainers.length === 0} />
0} indeterminate={selection.length > 0 && selection.length !== usedContainers.length} transitionDuration={0} + disabled={usedContainers.length === 0} /> Name
@@ -107,10 +106,9 @@ export default function DockerTable({
0} + checked={selection.length === usedContainers.length} indeterminate={selection.length > 0 && selection.length !== usedContainers.length} transitionDuration={0} - disabled={usedContainers.length === 0} /> Name