mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-19 10:25:20 +00:00
Merge pull request #2300 from Dokploy/2259-file-mounts-not-updating
feat(mount): refactor updateMount logic and add updateFileMount funct…
This commit is contained in:
@@ -2,18 +2,22 @@ import path from "node:path";
|
|||||||
import { paths } from "@dokploy/server/constants";
|
import { paths } from "@dokploy/server/constants";
|
||||||
import { db } from "@dokploy/server/db";
|
import { db } from "@dokploy/server/db";
|
||||||
import {
|
import {
|
||||||
type ServiceType,
|
|
||||||
type apiCreateMount,
|
type apiCreateMount,
|
||||||
mounts,
|
mounts,
|
||||||
|
type ServiceType,
|
||||||
} from "@dokploy/server/db/schema";
|
} from "@dokploy/server/db/schema";
|
||||||
import {
|
import {
|
||||||
createFile,
|
createFile,
|
||||||
|
encodeBase64,
|
||||||
getCreateFileCommand,
|
getCreateFileCommand,
|
||||||
} from "@dokploy/server/utils/docker/utils";
|
} from "@dokploy/server/utils/docker/utils";
|
||||||
import { removeFileOrDirectory } from "@dokploy/server/utils/filesystem/directory";
|
import { removeFileOrDirectory } from "@dokploy/server/utils/filesystem/directory";
|
||||||
import { execAsyncRemote } from "@dokploy/server/utils/process/execAsync";
|
import {
|
||||||
|
execAsync,
|
||||||
|
execAsyncRemote,
|
||||||
|
} from "@dokploy/server/utils/process/execAsync";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { type SQL, eq, sql } from "drizzle-orm";
|
import { eq, type SQL, sql } from "drizzle-orm";
|
||||||
|
|
||||||
export type Mount = typeof mounts.$inferSelect;
|
export type Mount = typeof mounts.$inferSelect;
|
||||||
|
|
||||||
@@ -123,7 +127,7 @@ export const updateMount = async (
|
|||||||
mountId: string,
|
mountId: string,
|
||||||
mountData: Partial<Mount>,
|
mountData: Partial<Mount>,
|
||||||
) => {
|
) => {
|
||||||
return await db.transaction(async (tx) => {
|
const mount = await db.transaction(async (tx) => {
|
||||||
const mount = await tx
|
const mount = await tx
|
||||||
.update(mounts)
|
.update(mounts)
|
||||||
.set({
|
.set({
|
||||||
@@ -140,13 +144,13 @@ export const updateMount = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mount.type === "file") {
|
|
||||||
await deleteFileMount(mountId);
|
|
||||||
await createFileMount(mountId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await findMountById(mountId);
|
return await findMountById(mountId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (mount.type === "file") {
|
||||||
|
await updateFileMount(mountId);
|
||||||
|
}
|
||||||
|
return mount;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const findMountsByApplicationId = async (
|
export const findMountsByApplicationId = async (
|
||||||
@@ -198,6 +202,26 @@ export const deleteMount = async (mountId: string) => {
|
|||||||
return deletedMount[0];
|
return deletedMount[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const updateFileMount = async (mountId: string) => {
|
||||||
|
const mount = await findMountById(mountId);
|
||||||
|
if (!mount || !mount.filePath) return;
|
||||||
|
const basePath = await getBaseFilesPath(mountId);
|
||||||
|
const fullPath = path.join(basePath, mount.filePath);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const serverId = await getServerId(mount);
|
||||||
|
const encodedContent = encodeBase64(mount.content || "");
|
||||||
|
const command = `echo "${encodedContent}" | base64 -d > ${fullPath}`;
|
||||||
|
if (serverId) {
|
||||||
|
await execAsyncRemote(serverId, command);
|
||||||
|
} else {
|
||||||
|
await execAsync(command);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
console.log("Error updating file mount");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const deleteFileMount = async (mountId: string) => {
|
export const deleteFileMount = async (mountId: string) => {
|
||||||
const mount = await findMountById(mountId);
|
const mount = await findMountById(mountId);
|
||||||
if (!mount.filePath) return;
|
if (!mount.filePath) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user