🐳 Fix docker not loading properly
This commit is contained in:
@@ -1,23 +1,29 @@
|
|||||||
import { Alert, Stack, Title } from '@mantine/core';
|
import { Alert, Stack, Title } from '@mantine/core';
|
||||||
import { IconInfoCircle } from '@tabler/icons-react';
|
import { IconInfoCircle } from '@tabler/icons-react';
|
||||||
|
import Consola from 'consola';
|
||||||
import { ContainerInfo } from 'dockerode';
|
import { ContainerInfo } from 'dockerode';
|
||||||
import { GetServerSideProps, InferGetServerSidePropsType } from 'next';
|
import { GetServerSideProps, InferGetServerSidePropsType } from 'next';
|
||||||
import { useState } from 'react';
|
|
||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
|
import { useState } from 'react';
|
||||||
import { ManageLayout } from '~/components/layout/Templates/ManageLayout';
|
import { ManageLayout } from '~/components/layout/Templates/ManageLayout';
|
||||||
import { env } from '~/env';
|
|
||||||
import ContainerActionBar from '~/modules/Docker/ContainerActionBar';
|
import ContainerActionBar from '~/modules/Docker/ContainerActionBar';
|
||||||
import DockerTable from '~/modules/Docker/DockerTable';
|
import DockerTable from '~/modules/Docker/DockerTable';
|
||||||
|
import { dockerRouter } from '~/server/api/routers/docker/router';
|
||||||
import { getServerAuthSession } from '~/server/auth';
|
import { getServerAuthSession } from '~/server/auth';
|
||||||
|
import { prisma } from '~/server/db';
|
||||||
import { getServerSideTranslations } from '~/tools/server/getServerSideTranslations';
|
import { getServerSideTranslations } from '~/tools/server/getServerSideTranslations';
|
||||||
import { boardNamespaces } from '~/tools/server/translation-namespaces';
|
import { boardNamespaces } from '~/tools/server/translation-namespaces';
|
||||||
import { api } from '~/utils/api';
|
import { api } from '~/utils/api';
|
||||||
|
|
||||||
export default function DockerPage({
|
export default function DockerPage({
|
||||||
|
initialContainers,
|
||||||
dockerIsConfigured,
|
dockerIsConfigured,
|
||||||
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
|
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
|
||||||
const [selection, setSelection] = useState<ContainerInfo[]>([]);
|
const [selection, setSelection] = useState<ContainerInfo[]>([]);
|
||||||
const { data, refetch, isRefetching } = api.docker.containers.useQuery(undefined, {
|
const { data, refetch, isRefetching } = api.docker.containers.useQuery(undefined, {
|
||||||
|
initialData: initialContainers,
|
||||||
|
cacheTime: 60 * 1000 * 5,
|
||||||
|
staleTime: 60 * 1000 * 1,
|
||||||
enabled: dockerIsConfigured,
|
enabled: dockerIsConfigured,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -50,8 +56,6 @@ export default function DockerPage({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async ({ locale, req, res }) => {
|
export const getServerSideProps: GetServerSideProps = async ({ locale, req, res }) => {
|
||||||
const dockerIsConfigured = env.DOCKER_HOST !== undefined;
|
|
||||||
|
|
||||||
const session = await getServerAuthSession({ req, res });
|
const session = await getServerAuthSession({ req, res });
|
||||||
if (!session?.user.isAdmin) {
|
if (!session?.user.isAdmin) {
|
||||||
return {
|
return {
|
||||||
@@ -59,15 +63,36 @@ export const getServerSideProps: GetServerSideProps = async ({ locale, req, res
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const caller = dockerRouter.createCaller({
|
||||||
|
session: session,
|
||||||
|
cookies: req.cookies,
|
||||||
|
prisma: prisma,
|
||||||
|
});
|
||||||
|
|
||||||
const translations = await getServerSideTranslations(
|
const translations = await getServerSideTranslations(
|
||||||
[...boardNamespaces, 'layout/manage', 'tools/docker'],
|
[...boardNamespaces, 'layout/manage', 'tools/docker'],
|
||||||
locale,
|
locale,
|
||||||
req,
|
req,
|
||||||
res
|
res
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let containers = [];
|
||||||
|
try {
|
||||||
|
containers = await caller.containers();
|
||||||
|
} catch (error) {
|
||||||
|
Consola.error(`The docker integration failed with the following error: ${error}`);
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
dockerIsConfigured: false,
|
||||||
|
...translations,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
dockerIsConfigured: dockerIsConfigured,
|
initialContainers: containers,
|
||||||
|
dockerIsConfigured: true,
|
||||||
...translations,
|
...translations,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user