Skip to content

Commit

Permalink
v0.8.0 Docker πŸ‹ and Dash. βš™ integrations !
Browse files Browse the repository at this point in the history
<!-- Small release message -->

- ✨ Add support for lists in module option by @ajnart in #280
- πŸ”¨ Fix Readarr default port number by @Moohan in #287
- ✨ Add dash. Integration by @MauriceNino in #277
- ✨ Add Docker integration by @ajnart in #289

- Dash. (Pronounced Dashdot) is another self-hosted service, made by @MauriceNino that provides a simple way to see stats about your PC in a sleek way
- Docker integration provides a simple way to start, stop, restart and delete containers. To get started, simply mount your docker socket by adding `-v /var/run/docker.sock:/var/run/docker.sock` to your Homarr container !

* @Moohan made their first contribution in #287
* @MauriceNino made their first contribution in #277

**Full Changelog**: v0.7.2...v0.8.0
  • Loading branch information
ajnart committed Jul 20, 2022
2 parents aab1492 + 5c1a171 commit ce0f27b
Show file tree
Hide file tree
Showing 31 changed files with 1,397 additions and 255 deletions.
2 changes: 1 addition & 1 deletion data/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const REPO_URL = 'ajnart/homarr';
export const CURRENT_VERSION = 'v0.7.2';
export const CURRENT_VERSION = 'v0.8.0';
4 changes: 1 addition & 3 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ module.exports = withBundleAnalyzer({
eslint: {
ignoreDuringBuilds: true,
},
experimental: {
outputStandalone: true,
},
output: 'standalone',
basePath: env.BASE_URL,
});
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homarr",
"version": "0.7.2",
"version": "0.8.0",
"description": "Homarr - A homepage for your server.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -43,11 +43,12 @@
"@nivo/line": "^0.79.1",
"@tabler/icons": "^1.68.0",
"axios": "^0.27.2",
"cookies-next": "^2.0.4",
"cookies-next": "^2.1.1",
"dayjs": "^1.11.3",
"dockerode": "^3.3.2",
"framer-motion": "^6.3.1",
"js-file-download": "^0.4.12",
"next": "12.1.6",
"next": "^12.2.0",
"prism-react-renderer": "^1.3.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
Expand All @@ -56,9 +57,10 @@
},
"devDependencies": {
"@babel/core": "^7.17.8",
"@next/bundle-analyzer": "^12.1.4",
"@next/eslint-plugin-next": "^12.1.4",
"@next/bundle-analyzer": "^12.2.0",
"@next/eslint-plugin-next": "^12.2.0",
"@storybook/react": "^6.5.4",
"@types/dockerode": "^3.3.9",
"@types/node": "^17.0.23",
"@types/react": "17.0.43",
"@types/uuid": "^8.3.4",
Expand Down
52 changes: 25 additions & 27 deletions src/components/AppShelf/AddAppShelfItem.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import {
Modal,
ActionIcon,
Anchor,
Button,
Center,
Group,
TextInput,
Image,
Button,
Select,
LoadingOverlay,
ActionIcon,
Tooltip,
Title,
Anchor,
Text,
Tabs,
Modal,
MultiSelect,
ScrollArea,
Select,
Switch,
Tabs,
Text,
TextInput,
Title,
Tooltip,
} from '@mantine/core';
import { useForm } from '@mantine/form';
import { useEffect, useState } from 'react';
import { useDebouncedValue } from '@mantine/hooks';
import { IconApps as Apps } from '@tabler/icons';
import { useEffect, useState } from 'react';
import { v4 as uuidv4 } from 'uuid';
import { useDebouncedValue } from '@mantine/hooks';
import { useConfig } from '../../tools/state';
import { ServiceTypeList, StatusCodes } from '../../tools/types';
import Tip from '../layout/Tip';

export function AddItemShelfButton(props: any) {
const [opened, setOpened] = useState(false);
Expand Down Expand Up @@ -58,7 +59,8 @@ function MatchIcon(name: string, form: any) {
fetch(
`https://cdn.jsdelivr.net/gh/walkxhub/dashboard-icons/png/${name
.replace(/\s+/g, '-')
.toLowerCase()}.png`
.toLowerCase()
.replace(/^dash\.$/, 'dashdot')}.png`
).then((res) => {
if (res.ok) {
form.setFieldValue('icon', res.url);
Expand All @@ -81,9 +83,10 @@ function MatchPort(name: string, form: any) {
{ name: 'sonarr', value: '8989' },
{ name: 'radarr', value: '7878' },
{ name: 'lidarr', value: '8686' },
{ name: 'readarr', value: '8686' },
{ name: 'readarr', value: '8787' },
{ name: 'deluge', value: '8112' },
{ name: 'transmission', value: '9091' },
{ name: 'dash.', value: '3001' },
];
// Match name with portmap key
const port = portmap.find((p) => p.name === name.toLowerCase());
Expand All @@ -92,6 +95,8 @@ function MatchPort(name: string, form: any) {
}
}

const DEFAULT_ICON = '/favicon.svg';

export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & any) {
const { setOpened } = props;
const { config, setConfig } = useConfig();
Expand All @@ -111,7 +116,7 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
type: props.type ?? 'Other',
category: props.category ?? undefined,
name: props.name ?? '',
icon: props.icon ?? '/favicon.svg',
icon: props.icon ?? DEFAULT_ICON,
url: props.url ?? '',
apiKey: props.apiKey ?? (undefined as unknown as string),
username: props.username ?? (undefined as unknown as string),
Expand Down Expand Up @@ -146,7 +151,7 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &

const [debounced, cancel] = useDebouncedValue(form.values.name, 250);
useEffect(() => {
if (form.values.name !== debounced || props.name || props.type) return;
if (form.values.name !== debounced || form.values.icon !== DEFAULT_ICON) return;
MatchIcon(form.values.name, form);
MatchService(form.values.name, form);
MatchPort(form.values.name, form);
Expand Down Expand Up @@ -219,7 +224,7 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
<TextInput
required
label="Icon URL"
placeholder="/favicon.svg"
placeholder={DEFAULT_ICON}
{...form.getInputProps('icon')}
/>
<TextInput
Expand Down Expand Up @@ -273,15 +278,8 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
}}
error={form.errors.apiKey && 'Invalid API key'}
/>
<Text
style={{
alignSelf: 'center',
fontSize: '0.75rem',
textAlign: 'center',
color: 'gray',
}}
>
Tip: Get your API key{' '}
<Tip>
Get your API key{' '}
<Anchor
target="_blank"
weight="bold"
Expand All @@ -290,7 +288,7 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } &
>
here.
</Anchor>
</Text>
</Tip>
</>
)}
{form.values.type === 'qBittorrent' && (
Expand Down
3 changes: 3 additions & 0 deletions src/components/AppShelf/AppShelf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const AppShelf = (props: any) => {
const noCategory = config.services.filter(
(e) => e.category === undefined || e.category === null
);
const downloadEnabled = config.modules?.[DownloadsModule.title]?.enabled ?? false;
// Create an item with 0: true, 1: true, 2: true... For each category
return (
// Return one item for each category
Expand All @@ -176,6 +177,7 @@ const AppShelf = (props: any) => {
{item()}
</Accordion.Item>
) : null}
{downloadEnabled ? (
<Accordion.Item key="Downloads" label="Your downloads">
<Paper
p="lg"
Expand All @@ -191,6 +193,7 @@ const AppShelf = (props: any) => {
<DownloadComponent />
</Paper>
</Accordion.Item>
) : null}
</Accordion>
</Group>
);
Expand Down
182 changes: 182 additions & 0 deletions src/components/Docker/ContainerActionBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import { Button, Group, Modal, Title } from '@mantine/core';
import { useBooleanToggle } from '@mantine/hooks';
import { showNotification, updateNotification } from '@mantine/notifications';
import {
IconCheck,
IconPlayerPlay,
IconPlayerStop,
IconPlus,
IconRefresh,
IconRotateClockwise,
IconTrash,
IconX,
} from '@tabler/icons';
import axios from 'axios';
import Dockerode from 'dockerode';
import { tryMatchService } from '../../tools/addToHomarr';
import { useConfig } from '../../tools/state';
import { AddAppShelfItemForm } from '../AppShelf/AddAppShelfItem';

function sendDockerCommand(action: string, containerId: string, containerName: string) {
showNotification({
id: containerId,
loading: true,
title: `${action}ing container ${containerName.substring(1)}`,
message: undefined,
autoClose: false,
disallowClose: true,
});
axios.get(`/api/docker/container/${containerId}?action=${action}`).then((res) => {
setTimeout(() => {
if (res.data.success === true) {
updateNotification({
id: containerId,
title: `Container ${containerName} ${action}ed`,
message: `Your container was successfully ${action}ed`,
icon: <IconCheck />,
autoClose: 2000,
});
}
if (res.data.success === false) {
updateNotification({
id: containerId,
color: 'red',
title: 'There was an error with your container.',
message: undefined,
icon: <IconX />,
autoClose: 2000,
});
}
}, 500);
});
}

export interface ContainerActionBarProps {
selected: Dockerode.ContainerInfo[];
reload: () => void;
}

export default function ContainerActionBar({ selected, reload }: ContainerActionBarProps) {
const { config, setConfig } = useConfig();
const [opened, setOpened] = useBooleanToggle(false);
return (
<Group>
<Modal
size="xl"
radius="md"
opened={opened}
onClose={() => setOpened(false)}
title="Add service"
>
<AddAppShelfItemForm
setOpened={setOpened}
{...tryMatchService(selected.at(0))}
message="Add service to homarr"
/>
</Modal>
<Button
leftIcon={<IconRotateClockwise />}
onClick={() =>
Promise.all(
selected.map((container) =>
sendDockerCommand('restart', container.Id, container.Names[0].substring(1))
)
).then(() => reload())
}
variant="light"
color="orange"
radius="md"
>
Restart
</Button>
<Button
leftIcon={<IconPlayerStop />}
onClick={() =>
Promise.all(
selected.map((container) => {
if (
container.State === 'stopped' ||
container.State === 'created' ||
container.State === 'exited'
) {
return showNotification({
id: container.Id,
title: `Failed to stop ${container.Names[0].substring(1)}`,
message: "You can't stop a stopped container",
autoClose: 1000,
});
}
return sendDockerCommand('stop', container.Id, container.Names[0].substring(1));
})
).then(() => reload())
}
variant="light"
color="red"
radius="md"
>
Stop
</Button>
<Button
leftIcon={<IconPlayerPlay />}
onClick={() =>
Promise.all(
selected.map((container) =>
sendDockerCommand('start', container.Id, container.Names[0].substring(1))
)
).then(() => reload())
}
variant="light"
color="green"
radius="md"
>
Start
</Button>
<Button leftIcon={<IconRefresh />} onClick={() => reload()} variant="light" radius="md">
Refresh data
</Button>
<Button
leftIcon={<IconPlus />}
color="indigo"
variant="light"
radius="md"
onClick={() => {
if (selected.length !== 1) {
showNotification({
autoClose: 5000,
title: <Title order={4}>Please only add one service at a time!</Title>,
color: 'red',
message: undefined,
});
} else {
setOpened(true);
}
}}
>
Add to Homarr
</Button>
<Button
leftIcon={<IconTrash />}
color="red"
variant="light"
radius="md"
onClick={() =>
Promise.all(
selected.map((container) => {
if (container.State === 'running') {
return showNotification({
id: container.Id,
title: `Failed to delete ${container.Names[0].substring(1)}`,
message: "You can't delete a running container",
autoClose: 1000,
});
}
return sendDockerCommand('remove', container.Id, container.Names[0].substring(1));
})
).then(() => reload())
}
>
Remove
</Button>
</Group>
);
}
Loading

0 comments on commit ce0f27b

Please sign in to comment.