feat: add config portability — full export/import, homepage import, docker label discovery
Add a dedicated Import/Export tool page with full configuration export/import (v2.0 bundle with encrypted secrets), Homepage services.yaml import with env variable resolution, and manual Docker label discovery (moved from cron job). Support importing Homarr JSON during onboarding alongside legacy zip import. New @homarr/board-portability package handles schema, serialization, compat checks, and import planning. Shared preview UI reused across admin and onboarding. Fix xterm.js crash by removing deprecated @xterm/addon-canvas (incompatible with xterm v6). Fix Homepage env variable i18n and React 19 currentTarget bug. See docs/config-portability.md for full changelog.
This commit is contained in:
100 files changed
+13394
-56
No files matched your search
@@ -22,6 +22,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@homarr/auth": "workspace:^0.1.0",
|
||||
"@homarr/board-portability": "workspace:^0.1.0",
|
||||
"@homarr/common": "workspace:^0.1.0",
|
||||
"@homarr/core": "workspace:^0.1.0",
|
||||
"@homarr/cron-job-status": "workspace:^0.1.0",
|
||||
|
||||
@@ -28,6 +28,7 @@ export const appRouter = createTRPCRouter({
|
||||
certificates: lazy(() => import("./router/certificates/certificate-router").then((mod) => mod.certificateRouter)),
|
||||
bangs: lazy(() => import("./router/bangs/bangs-router").then((mod) => mod.bangsRouter)),
|
||||
info: lazy(() => import("./router/info").then((mod) => mod.infoRouter)),
|
||||
config: lazy(() => import("./router/config").then((mod) => mod.configRouter)),
|
||||
});
|
||||
|
||||
// export type definition of API
|
||||
|
||||
@@ -35,6 +35,12 @@ import {
|
||||
getPermissionsWithParents,
|
||||
widgetKinds,
|
||||
} from "@homarr/definitions";
|
||||
import {
|
||||
exportBoardBundleAsync,
|
||||
importBoardBundleAsync,
|
||||
importHomepageServicesAsync,
|
||||
parseBundleJson,
|
||||
} from "@homarr/board-portability";
|
||||
import { importOldmarrAsync } from "@homarr/old-import";
|
||||
import { importJsonFileSchema } from "@homarr/old-import/shared";
|
||||
import { oldmarrConfigSchema } from "@homarr/old-schema";
|
||||
@@ -43,6 +49,9 @@ import {
|
||||
boardChangeVisibilitySchema,
|
||||
boardCreateSchema,
|
||||
boardDuplicateSchema,
|
||||
boardExportBundleSchema,
|
||||
boardImportBundleSchema,
|
||||
boardNameSchema,
|
||||
boardRenameSchema,
|
||||
boardSaveLayoutsSchema,
|
||||
boardSavePartialSettingsSchema,
|
||||
@@ -54,6 +63,7 @@ import { zodUnionFromArray } from "@homarr/validation/enums";
|
||||
import type { BoardItemAdvancedOptions } from "@homarr/validation/shared";
|
||||
import { sectionSchema, sharedItemSchema } from "@homarr/validation/shared";
|
||||
|
||||
import packageJson from "../../../../package.json";
|
||||
import { createTRPCRouter, permissionRequiredProcedure, protectedProcedure, publicProcedure } from "../trpc";
|
||||
import { throwIfActionForbiddenAsync } from "./board/board-access";
|
||||
import { generateResponsiveGridFor } from "./board/grid-algorithm";
|
||||
@@ -1327,6 +1337,113 @@ export const boardRouter = createTRPCRouter({
|
||||
const oldmarr = oldmarrConfigSchema.parse(JSON.parse(content));
|
||||
await importOldmarrAsync(ctx.db, oldmarr, input.configuration);
|
||||
}),
|
||||
exportBundle: protectedProcedure.input(boardExportBundleSchema).mutation(async ({ ctx, input }) => {
|
||||
await throwIfActionForbiddenAsync(ctx, eq(boards.id, input.id), "view");
|
||||
|
||||
const result = await exportBoardBundleAsync(ctx.db, input.id, packageJson.version);
|
||||
if (!result) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Board not found",
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
filename: result.filename,
|
||||
content: result.content,
|
||||
};
|
||||
}),
|
||||
importBundle: permissionRequiredProcedure
|
||||
.requiresPermission("board-create")
|
||||
.input(boardImportBundleSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
await noBoardWithSimilarNameAsync(ctx.db, input.name);
|
||||
|
||||
const bundle = parseBundleJson(input.content);
|
||||
|
||||
const existingApps = await ctx.db.query.apps.findMany();
|
||||
const existingIntegrations = await ctx.db.query.integrations.findMany();
|
||||
|
||||
const hasAccessForAll = ctx.session.user.permissions.includes("integration-use-all");
|
||||
const integrationIdsWithAccess = hasAccessForAll
|
||||
? []
|
||||
: await ctx.db
|
||||
.selectDistinct({
|
||||
id: integrationGroupPermissions.integrationId,
|
||||
})
|
||||
.from(integrationGroupPermissions)
|
||||
.leftJoin(groupMembers, eq(integrationGroupPermissions.groupId, groupMembers.groupId))
|
||||
.where(eq(groupMembers.userId, ctx.session.user.id))
|
||||
.union(
|
||||
ctx.db
|
||||
.selectDistinct({ id: integrationUserPermissions.integrationId })
|
||||
.from(integrationUserPermissions)
|
||||
.where(eq(integrationUserPermissions.userId, ctx.session.user.id)),
|
||||
)
|
||||
.then((result) => result.map((row) => row.id));
|
||||
|
||||
const report = await importBoardBundleAsync(
|
||||
ctx.db,
|
||||
bundle,
|
||||
input.name,
|
||||
ctx.session.user.id,
|
||||
existingApps,
|
||||
existingIntegrations,
|
||||
integrationIdsWithAccess,
|
||||
hasAccessForAll,
|
||||
);
|
||||
|
||||
return {
|
||||
boardId: report.boardId,
|
||||
created: report.created,
|
||||
warnings: report.warnings,
|
||||
};
|
||||
}),
|
||||
importHomepageServices: permissionRequiredProcedure
|
||||
.requiresPermission("board-create")
|
||||
.input(
|
||||
z.object({
|
||||
content: z.string().min(1),
|
||||
boardName: boardNameSchema,
|
||||
createIntegrations: z.boolean().default(true),
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
await noBoardWithSimilarNameAsync(ctx.db, input.boardName);
|
||||
|
||||
try {
|
||||
const report = await importHomepageServicesAsync(
|
||||
ctx.db,
|
||||
input.content,
|
||||
input.boardName,
|
||||
ctx.session.user.id,
|
||||
input.createIntegrations,
|
||||
);
|
||||
|
||||
const user = await ctx.db.query.users.findFirst({
|
||||
where: eq(users.id, ctx.session.user.id),
|
||||
columns: {
|
||||
homeBoardId: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!user?.homeBoardId) {
|
||||
await ctx.db.update(users).set({ homeBoardId: report.boardId }).where(eq(users.id, ctx.session.user.id));
|
||||
}
|
||||
|
||||
return {
|
||||
boardId: report.boardId,
|
||||
created: report.created,
|
||||
warnings: report.warnings,
|
||||
unmappedWidgetTypes: report.unmappedWidgetTypes,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: error instanceof Error ? error.message : "Could not import Homepage services",
|
||||
});
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
import {
|
||||
assessBundleCompatibility,
|
||||
exportFullConfigAsync,
|
||||
importFullConfigAsync,
|
||||
previewExportFullConfigAsync,
|
||||
previewImportFullConfigAsync,
|
||||
} from "@homarr/board-portability";
|
||||
|
||||
import packageJson from "../../../../package.json";
|
||||
import { createTRPCRouter, permissionRequiredProcedure } from "../trpc";
|
||||
|
||||
export const configRouter = createTRPCRouter({
|
||||
previewExport: permissionRequiredProcedure.requiresPermission("admin").query(async ({ ctx }) => {
|
||||
return await previewExportFullConfigAsync(ctx.db);
|
||||
}),
|
||||
|
||||
previewImport: permissionRequiredProcedure
|
||||
.requiresPermission("admin")
|
||||
.input(
|
||||
z.object({
|
||||
content: z.string().min(1),
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
return await previewImportFullConfigAsync(ctx.db, input.content, packageJson.version);
|
||||
}),
|
||||
|
||||
exportFull: permissionRequiredProcedure.requiresPermission("admin").mutation(async ({ ctx }) => {
|
||||
return await exportFullConfigAsync(ctx.db, packageJson.version);
|
||||
}),
|
||||
|
||||
importFull: permissionRequiredProcedure
|
||||
.requiresPermission("admin")
|
||||
.input(
|
||||
z.object({
|
||||
content: z.string().min(1),
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(input.content);
|
||||
} catch {
|
||||
throw new TRPCError({ code: "BAD_REQUEST", message: "Invalid JSON" });
|
||||
}
|
||||
|
||||
const { bundle, compatibility } = assessBundleCompatibility(parsed, packageJson.version);
|
||||
if (!bundle || compatibility.status !== "compatible") {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: compatibility.issues.join(" "),
|
||||
});
|
||||
}
|
||||
|
||||
return await importFullConfigAsync(ctx.db, bundle, ctx.session.user.id);
|
||||
}),
|
||||
});
|
||||
@@ -3,7 +3,8 @@ import { observable } from "@trpc/server/observable";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
import type { Container, ContainerState, Docker, Port } from "@homarr/docker";
|
||||
import { DockerSingleton } from "@homarr/docker";
|
||||
import { DockerSingleton, listDiscoveredContainersAsync, syncDiscoveredServicesAsync } from "@homarr/docker";
|
||||
import { getServerSettingsAsync } from "@homarr/db/queries";
|
||||
import { dockerContainersRequestHandler } from "@homarr/request-handler/docker";
|
||||
|
||||
import { dockerMiddleware } from "../../middlewares/docker";
|
||||
@@ -104,6 +105,32 @@ export const dockerRouter = createTRPCRouter({
|
||||
const innerHandler = dockerContainersRequestHandler.handler({});
|
||||
await innerHandler.invalidateAsync();
|
||||
}),
|
||||
getDiscoveredPreview: permissionRequiredProcedure
|
||||
.requiresPermission("admin")
|
||||
.concat(dockerMiddleware())
|
||||
.query(async ({ ctx }) => {
|
||||
const serverSettings = await getServerSettingsAsync(ctx.db);
|
||||
return await listDiscoveredContainersAsync({
|
||||
readHomepageLabels: serverSettings.docker.readHomepageLabels,
|
||||
});
|
||||
}),
|
||||
syncDiscovery: permissionRequiredProcedure
|
||||
.requiresPermission("admin")
|
||||
.concat(dockerMiddleware())
|
||||
.mutation(async ({ ctx }) => {
|
||||
const serverSettings = await getServerSettingsAsync(ctx.db);
|
||||
const discovered = await listDiscoveredContainersAsync({
|
||||
readHomepageLabels: serverSettings.docker.readHomepageLabels,
|
||||
});
|
||||
|
||||
return await syncDiscoveredServicesAsync(discovered, {
|
||||
targetBoardName: serverSettings.docker.targetBoardName,
|
||||
enableStatusByDefault: serverSettings.board.enableStatusByDefault,
|
||||
forceDisableStatus: serverSettings.board.forceDisableStatus,
|
||||
defaultItemWidth: serverSettings.docker.defaultItemWidth,
|
||||
defaultItemHeight: serverSettings.docker.defaultItemHeight,
|
||||
});
|
||||
}),
|
||||
});
|
||||
|
||||
const getContainerOrDefaultAsync = async (instance: Docker, id: string) => {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
import {
|
||||
assessBundleCompatibility,
|
||||
importFullConfigAsync,
|
||||
previewImportFullConfigAsync,
|
||||
} from "@homarr/board-portability";
|
||||
import { analyseOldmarrImportForRouterAsync, analyseOldmarrImportInputSchema } from "@homarr/old-import/analyse";
|
||||
import {
|
||||
ensureValidTokenOrThrow,
|
||||
@@ -7,6 +13,7 @@ import {
|
||||
importInitialOldmarrInputSchema,
|
||||
} from "@homarr/old-import/import";
|
||||
|
||||
import packageJson from "../../../../../package.json";
|
||||
import { createTRPCRouter, onboardingProcedure } from "../../trpc";
|
||||
import { nextOnboardingStepAsync } from "../onboard/onboard-queries";
|
||||
|
||||
@@ -40,4 +47,40 @@ export const importRouter = createTRPCRouter({
|
||||
await importInitialOldmarrAsync(ctx.db, input);
|
||||
await nextOnboardingStepAsync(ctx.db, undefined);
|
||||
}),
|
||||
previewInitialConfigImport: onboardingProcedure
|
||||
.requiresStep("import")
|
||||
.input(
|
||||
z.object({
|
||||
content: z.string().min(1),
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
return await previewImportFullConfigAsync(ctx.db, input.content, packageJson.version);
|
||||
}),
|
||||
importInitialConfigImport: onboardingProcedure
|
||||
.requiresStep("import")
|
||||
.input(
|
||||
z.object({
|
||||
content: z.string().min(1),
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(input.content);
|
||||
} catch {
|
||||
throw new TRPCError({ code: "BAD_REQUEST", message: "Invalid JSON" });
|
||||
}
|
||||
|
||||
const { bundle, compatibility } = assessBundleCompatibility(parsed, packageJson.version);
|
||||
if (!bundle || compatibility.status !== "compatible") {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
message: compatibility.issues.join(" "),
|
||||
});
|
||||
}
|
||||
|
||||
await importFullConfigAsync(ctx.db, bundle, null);
|
||||
await nextOnboardingStepAsync(ctx.db, undefined);
|
||||
}),
|
||||
});
|
||||
@@ -42,6 +42,20 @@ vi.mock("@homarr/docker/env", () => ({
|
||||
ENABLE_DOCKER: true,
|
||||
},
|
||||
}));
|
||||
vi.mock("@homarr/docker", async (importOriginal) => {
|
||||
const original = await importOriginal<typeof import("@homarr/docker")>();
|
||||
return {
|
||||
...original,
|
||||
listDiscoveredContainersAsync: async () => [],
|
||||
syncDiscoveredServicesAsync: async () => ({ created: 0, updated: 0, skipped: 0 }),
|
||||
};
|
||||
});
|
||||
vi.mock("@homarr/db/queries", () => ({
|
||||
getServerSettingsAsync: async () => ({
|
||||
docker: { targetBoardName: null, readHomepageLabels: true, pruneRemoved: false },
|
||||
board: { enableStatusByDefault: true, forceDisableStatus: false },
|
||||
}),
|
||||
}));
|
||||
|
||||
const createSessionWithPermissions = (...permissions: GroupPermissionKey[]) =>
|
||||
({
|
||||
@@ -65,6 +79,8 @@ const validInputs: {
|
||||
restartAll: { ids: ["1"] },
|
||||
removeAll: { ids: ["1"] },
|
||||
invalidate: undefined,
|
||||
getDiscoveredPreview: undefined,
|
||||
syncDiscovery: undefined,
|
||||
};
|
||||
|
||||
describe("All procedures should only be accessible for users with admin permission", () => {
|
||||
|
||||
Reference in new issue
Block a user