Merge branch 'dev' into postgres

This commit is contained in:
miloschwartz
2025-06-04 12:04:28 -04:00
26 changed files with 4320 additions and 2090 deletions

View File

@@ -1,9 +1,8 @@
"use client";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { ArrowRight, InfoIcon, ShieldCheck, ShieldOff } from "lucide-react";
import { InfoIcon, ShieldCheck, ShieldOff } from "lucide-react";
import { useResourceContext } from "@app/hooks/useResourceContext";
import { Separator } from "@app/components/ui/separator";
import CopyToClipboard from "@app/components/CopyToClipboard";
import {
InfoSection,
@@ -11,13 +10,17 @@ import {
InfoSections,
InfoSectionTitle
} from "@app/components/InfoSection";
import Link from "next/link";
import { Switch } from "@app/components/ui/switch";
import { createApiClient } from "@app/lib/api";
import { useEnvContext } from "@app/hooks/useEnvContext";
import { useDockerSocket } from "@app/hooks/useDockerSocket";
type ResourceInfoBoxType = {};
export default function ResourceInfoBox({}: ResourceInfoBoxType) {
const { resource, authInfo } = useResourceContext();
const { resource, authInfo, site } = useResourceContext();
const api = createApiClient(useEnvContext());
const { isEnabled, isAvailable } = useDockerSocket(resource.siteId);
let fullUrl = `${resource.ssl ? "https" : "http"}://${resource.fullDomain}`;
@@ -28,7 +31,7 @@ export default function ResourceInfoBox({}: ResourceInfoBoxType) {
Resource Information
</AlertTitle>
<AlertDescription className="mt-4">
<InfoSections cols={4}>
<InfoSections cols={isEnabled ? 5 : 4}>
{resource.http ? (
<>
<InfoSection>
@@ -67,6 +70,24 @@ export default function ResourceInfoBox({}: ResourceInfoBoxType) {
{resource.siteName}
</InfoSectionContent>
</InfoSection>
{isEnabled && (
<InfoSection>
<InfoSectionTitle>Socket</InfoSectionTitle>
<InfoSectionContent>
{isAvailable ? (
<span className="text-green-500 flex items-center space-x-2">
<div className="w-2 h-2 bg-green-500 rounded-full"></div>
<span>Online</span>
</span>
) : (
<span className="text-neutral-500 flex items-center space-x-2">
<div className="w-2 h-2 bg-gray-500 rounded-full"></div>
<span>Offline</span>
</span>
)}
</InfoSectionContent>
</InfoSection>
)}
</>
) : (
<>
@@ -92,7 +113,9 @@ export default function ResourceInfoBox({}: ResourceInfoBoxType) {
<InfoSection>
<InfoSectionTitle>Visibility</InfoSectionTitle>
<InfoSectionContent>
<span>{resource.enabled ? "Enabled" : "Disabled"}</span>
<span>
{resource.enabled ? "Enabled" : "Disabled"}
</span>
</InfoSectionContent>
</InfoSection>
</InfoSections>

View File

@@ -13,15 +13,7 @@ import { GetOrgResponse } from "@server/routers/org";
import OrgProvider from "@app/providers/OrgProvider";
import { cache } from "react";
import ResourceInfoBox from "./ResourceInfoBox";
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator
} from "@app/components/ui/breadcrumb";
import Link from "next/link";
import { GetSiteResponse } from "@server/routers/site";
interface ResourceLayoutProps {
children: React.ReactNode;
@@ -35,6 +27,7 @@ export default async function ResourceLayout(props: ResourceLayoutProps) {
let authInfo = null;
let resource = null;
let site = null;
try {
const res = await internal.get<AxiosResponse<GetResourceResponse>>(
`/resource/${params.resourceId}`,
@@ -49,6 +42,19 @@ export default async function ResourceLayout(props: ResourceLayoutProps) {
redirect(`/${params.orgId}/settings/resources`);
}
// Fetch site info
if (resource.siteId) {
try {
const res = await internal.get<AxiosResponse<GetSiteResponse>>(
`/site/${resource.siteId}`,
await authCookieHeader()
);
site = res.data.data;
} catch {
redirect(`/${params.orgId}/settings/resources`);
}
}
try {
const res = await internal.get<
AxiosResponse<GetResourceAuthInfoResponse>
@@ -110,7 +116,11 @@ export default async function ResourceLayout(props: ResourceLayoutProps) {
/>
<OrgProvider org={org}>
<ResourceProvider resource={resource} authInfo={authInfo}>
<ResourceProvider
site={site}
resource={resource}
authInfo={authInfo}
>
<div className="space-y-6">
<ResourceInfoBox />
<HorizontalTabs items={navItems}>

View File

@@ -41,7 +41,6 @@ import {
TableBody,
TableCaption,
TableCell,
TableContainer,
TableHead,
TableHeader,
TableRow
@@ -73,6 +72,7 @@ import {
CollapsibleContent,
CollapsibleTrigger
} from "@app/components/ui/collapsible";
import { ContainersSelector } from "@app/components/ContainersSelector";
const addTargetSchema = z.object({
ip: z.string().refine(isTargetValid),
@@ -163,6 +163,9 @@ export default function ReverseProxyTargets(props: {
} as z.infer<typeof addTargetSchema>
});
const watchedIp = addTargetForm.watch("ip");
const watchedPort = addTargetForm.watch("port");
const tlsSettingsForm = useForm<TlsSettingsValues>({
resolver: zodResolver(tlsSettingsSchema),
defaultValues: {
@@ -767,12 +770,32 @@ export default function ReverseProxyTargets(props: {
control={addTargetForm.control}
name="ip"
render={({ field }) => (
<FormItem>
<FormItem className="relative">
<FormLabel>IP / Hostname</FormLabel>
<FormControl>
<Input id="ip" {...field} />
</FormControl>
<FormMessage />
{site && (
<ContainersSelector
site={site}
onContainerSelect={(
hostname,
port
) => {
addTargetForm.setValue(
"ip",
hostname
);
if (port) {
addTargetForm.setValue(
"port",
port
);
}
}}
/>
)}
</FormItem>
)}
/>
@@ -798,12 +821,7 @@ export default function ReverseProxyTargets(props: {
type="submit"
variant="outlinePrimary"
className="mt-6"
disabled={
!(
addTargetForm.getValues("ip") &&
addTargetForm.getValues("port")
)
}
disabled={!(watchedIp && watchedPort)}
>
Add Target
</Button>

View File

@@ -268,7 +268,7 @@ PersistentKeepalive = 5`
- NEWT_ID=${siteDefaults?.newtId}
- NEWT_SECRET=${siteDefaults?.newtSecret}`;
const newtConfigDockerRun = `docker run -it fosrl/newt --id ${siteDefaults?.newtId} --secret ${siteDefaults?.newtSecret} --endpoint ${env.app.dashboardUrl}`;
const newtConfigDockerRun = `docker run -dit fosrl/newt --id ${siteDefaults?.newtId} --secret ${siteDefaults?.newtSecret} --endpoint ${env.app.dashboardUrl}`;
return loadingPage ? (
<LoaderPlaceholder height="300px" />

View File

@@ -31,9 +31,11 @@ import { formatAxiosError } from "@app/lib/api";
import { createApiClient } from "@app/lib/api";
import { useEnvContext } from "@app/hooks/useEnvContext";
import { useState } from "react";
import { SwitchInput } from "@app/components/SwitchInput";
const GeneralFormSchema = z.object({
name: z.string().nonempty("Name is required")
name: z.string().nonempty("Name is required"),
dockerSocketEnabled: z.boolean().optional()
});
type GeneralFormValues = z.infer<typeof GeneralFormSchema>;
@@ -50,7 +52,8 @@ export default function GeneralPage() {
const form = useForm<GeneralFormValues>({
resolver: zodResolver(GeneralFormSchema),
defaultValues: {
name: site?.name
name: site?.name,
dockerSocketEnabled: site?.dockerSocketEnabled ?? false
},
mode: "onChange"
});
@@ -60,7 +63,8 @@ export default function GeneralPage() {
await api
.post(`/site/${site?.siteId}`, {
name: data.name
name: data.name,
dockerSocketEnabled: data.dockerSocketEnabled
})
.catch((e) => {
toast({
@@ -73,7 +77,10 @@ export default function GeneralPage() {
});
});
updateSite({ name: data.name });
updateSite({
name: data.name,
dockerSocketEnabled: data.dockerSocketEnabled
});
toast({
title: "Site updated",
@@ -102,7 +109,7 @@ export default function GeneralPage() {
<Form {...form}>
<form
onSubmit={form.handleSubmit(onSubmit)}
className="space-y-4"
className="space-y-6"
id="general-settings-form"
>
<FormField
@@ -122,6 +129,31 @@ export default function GeneralPage() {
</FormItem>
)}
/>
<FormField
control={form.control}
name="dockerSocketEnabled"
render={({ field }) => (
<FormItem>
<FormControl>
<SwitchInput
id="docker-socket-enabled"
label="Enable Docker Socket"
defaultChecked={field.value}
onCheckedChange={
field.onChange
}
/>
</FormControl>
<FormMessage />
<FormDescription>
Enable Docker Socket discovery
for populating container
information, useful in resource
targets.
</FormDescription>
</FormItem>
)}
/>
</form>
</Form>
</SettingsSectionForm>

View File

@@ -257,7 +257,7 @@ PersistentKeepalive = 5`;
- NEWT_SECRET=${secret}`
],
"Docker Run": [
`docker run -it fosrl/newt --id ${id} --secret ${secret} --endpoint ${endpoint}`
`docker run -dit fosrl/newt --id ${id} --secret ${secret} --endpoint ${endpoint}`
]
},
podman: {
@@ -280,7 +280,7 @@ Restart=always
WantedBy=default.target`
],
"Podman Run": [
`podman run -it docker.io/fosrl/newt --id ${id} --secret ${secret} --endpoint ${endpoint}`
`podman run -dit docker.io/fosrl/newt --id ${id} --secret ${secret} --endpoint ${endpoint}`
]
}
};