mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: migrate endpoints
This commit is contained in:
@@ -10,10 +10,10 @@ import {
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { nanoid } from "nanoid";
|
||||
import { z } from "zod";
|
||||
import { account } from "./account";
|
||||
import { admins } from "./admin";
|
||||
import { auth } from "./auth";
|
||||
import { certificateType } from "./shared";
|
||||
import { account } from "./account";
|
||||
/**
|
||||
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
|
||||
* database instance for multiple projects.
|
||||
|
||||
@@ -40,7 +40,7 @@ import { createTraefikConfig } from "@dokploy/server/utils/traefik/application";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { encodeBase64 } from "../utils/docker/utils";
|
||||
import { findAdminById, getDokployUrl } from "./admin";
|
||||
import { findAdminById, findUserById, getDokployUrl } from "./admin";
|
||||
import {
|
||||
createDeployment,
|
||||
createDeploymentPreview,
|
||||
@@ -185,7 +185,7 @@ export const deployApplication = async ({
|
||||
});
|
||||
|
||||
try {
|
||||
const admin = await findAdminById(application.project.adminId);
|
||||
const admin = await findUserById(application.project.userId);
|
||||
|
||||
if (admin.cleanupCacheApplications) {
|
||||
await cleanupFullDocker(application?.serverId);
|
||||
@@ -220,7 +220,7 @@ export const deployApplication = async ({
|
||||
applicationName: application.name,
|
||||
applicationType: "application",
|
||||
buildLink,
|
||||
adminId: application.project.adminId,
|
||||
userId: application.project.userId,
|
||||
domains: application.domains,
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -233,7 +233,7 @@ export const deployApplication = async ({
|
||||
// @ts-ignore
|
||||
errorMessage: error?.message || "Error building",
|
||||
buildLink,
|
||||
adminId: application.project.adminId,
|
||||
userId: application.project.userId,
|
||||
});
|
||||
|
||||
throw error;
|
||||
@@ -260,7 +260,7 @@ export const rebuildApplication = async ({
|
||||
});
|
||||
|
||||
try {
|
||||
const admin = await findAdminById(application.project.adminId);
|
||||
const admin = await findUserById(application.project.userId);
|
||||
|
||||
if (admin.cleanupCacheApplications) {
|
||||
await cleanupFullDocker(application?.serverId);
|
||||
@@ -309,7 +309,7 @@ export const deployRemoteApplication = async ({
|
||||
|
||||
try {
|
||||
if (application.serverId) {
|
||||
const admin = await findAdminById(application.project.adminId);
|
||||
const admin = await findUserById(application.project.userId);
|
||||
|
||||
if (admin.cleanupCacheApplications) {
|
||||
await cleanupFullDocker(application?.serverId);
|
||||
@@ -352,7 +352,7 @@ export const deployRemoteApplication = async ({
|
||||
applicationName: application.name,
|
||||
applicationType: "application",
|
||||
buildLink,
|
||||
adminId: application.project.adminId,
|
||||
userId: application.project.userId,
|
||||
domains: application.domains,
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -376,7 +376,7 @@ export const deployRemoteApplication = async ({
|
||||
// @ts-ignore
|
||||
errorMessage: error?.message || "Error building",
|
||||
buildLink,
|
||||
adminId: application.project.adminId,
|
||||
userId: application.project.userId,
|
||||
});
|
||||
|
||||
throw error;
|
||||
@@ -454,7 +454,7 @@ export const deployPreviewApplication = async ({
|
||||
application.env = `${application.previewEnv}\nDOKPLOY_DEPLOY_URL=${previewDeployment?.domain}`;
|
||||
application.buildArgs = application.previewBuildArgs;
|
||||
|
||||
const admin = await findAdminById(application.project.adminId);
|
||||
const admin = await findUserById(application.project.userId);
|
||||
|
||||
if (admin.cleanupCacheOnPreviews) {
|
||||
await cleanupFullDocker(application?.serverId);
|
||||
@@ -568,7 +568,7 @@ export const deployRemotePreviewApplication = async ({
|
||||
application.buildArgs = application.previewBuildArgs;
|
||||
|
||||
if (application.serverId) {
|
||||
const admin = await findAdminById(application.project.adminId);
|
||||
const admin = await findUserById(application.project.userId);
|
||||
|
||||
if (admin.cleanupCacheOnPreviews) {
|
||||
await cleanupFullDocker(application?.serverId);
|
||||
@@ -637,7 +637,7 @@ export const rebuildRemoteApplication = async ({
|
||||
|
||||
try {
|
||||
if (application.serverId) {
|
||||
const admin = await findAdminById(application.project.adminId);
|
||||
const admin = await findUserById(application.project.userId);
|
||||
|
||||
if (admin.cleanupCacheApplications) {
|
||||
await cleanupFullDocker(application?.serverId);
|
||||
|
||||
@@ -33,13 +33,13 @@ export const findCertificateById = async (certificateId: string) => {
|
||||
|
||||
export const createCertificate = async (
|
||||
certificateData: z.infer<typeof apiCreateCertificate>,
|
||||
adminId: string,
|
||||
userId: string,
|
||||
) => {
|
||||
const certificate = await db
|
||||
.insert(certificates)
|
||||
.values({
|
||||
...certificateData,
|
||||
adminId: adminId,
|
||||
userId: userId,
|
||||
})
|
||||
.returning();
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ import {
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { encodeBase64 } from "../utils/docker/utils";
|
||||
import { findAdminById, getDokployUrl } from "./admin";
|
||||
import { findAdminById, findUserById, getDokployUrl } from "./admin";
|
||||
import { createDeploymentCompose, updateDeploymentStatus } from "./deployment";
|
||||
import { validUniqueServerAppName } from "./project";
|
||||
import { cleanupFullDocker } from "./settings";
|
||||
@@ -217,7 +217,7 @@ export const deployCompose = async ({
|
||||
});
|
||||
|
||||
try {
|
||||
const admin = await findAdminById(compose.project.adminId);
|
||||
const admin = await findUserById(compose.project.userId);
|
||||
if (admin.cleanupCacheOnCompose) {
|
||||
await cleanupFullDocker(compose?.serverId);
|
||||
}
|
||||
@@ -247,7 +247,7 @@ export const deployCompose = async ({
|
||||
applicationName: compose.name,
|
||||
applicationType: "compose",
|
||||
buildLink,
|
||||
adminId: compose.project.adminId,
|
||||
userId: compose.project.userId,
|
||||
domains: compose.domains,
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -262,7 +262,7 @@ export const deployCompose = async ({
|
||||
// @ts-ignore
|
||||
errorMessage: error?.message || "Error building",
|
||||
buildLink,
|
||||
adminId: compose.project.adminId,
|
||||
userId: compose.project.userId,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
@@ -286,7 +286,7 @@ export const rebuildCompose = async ({
|
||||
});
|
||||
|
||||
try {
|
||||
const admin = await findAdminById(compose.project.adminId);
|
||||
const admin = await findUserById(compose.project.userId);
|
||||
if (admin.cleanupCacheOnCompose) {
|
||||
await cleanupFullDocker(compose?.serverId);
|
||||
}
|
||||
@@ -332,7 +332,7 @@ export const deployRemoteCompose = async ({
|
||||
});
|
||||
try {
|
||||
if (compose.serverId) {
|
||||
const admin = await findAdminById(compose.project.adminId);
|
||||
const admin = await findUserById(compose.project.userId);
|
||||
if (admin.cleanupCacheOnCompose) {
|
||||
await cleanupFullDocker(compose?.serverId);
|
||||
}
|
||||
@@ -381,7 +381,7 @@ export const deployRemoteCompose = async ({
|
||||
applicationName: compose.name,
|
||||
applicationType: "compose",
|
||||
buildLink,
|
||||
adminId: compose.project.adminId,
|
||||
userId: compose.project.userId,
|
||||
domains: compose.domains,
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -406,7 +406,7 @@ export const deployRemoteCompose = async ({
|
||||
// @ts-ignore
|
||||
errorMessage: error?.message || "Error building",
|
||||
buildLink,
|
||||
adminId: compose.project.adminId,
|
||||
userId: compose.project.userId,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
@@ -430,7 +430,7 @@ export const rebuildRemoteCompose = async ({
|
||||
});
|
||||
|
||||
try {
|
||||
const admin = await findAdminById(compose.project.adminId);
|
||||
const admin = await findUserById(compose.project.userId);
|
||||
if (admin.cleanupCacheOnCompose) {
|
||||
await cleanupFullDocker(compose?.serverId);
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ export type Destination = typeof destinations.$inferSelect;
|
||||
|
||||
export const createDestintation = async (
|
||||
input: typeof apiCreateDestination._type,
|
||||
adminId: string,
|
||||
userId: string,
|
||||
) => {
|
||||
const newDestination = await db
|
||||
.insert(destinations)
|
||||
.values({
|
||||
...input,
|
||||
adminId: adminId,
|
||||
userId: userId,
|
||||
})
|
||||
.returning()
|
||||
.then((value) => value[0]);
|
||||
@@ -46,14 +46,14 @@ export const findDestinationById = async (destinationId: string) => {
|
||||
|
||||
export const removeDestinationById = async (
|
||||
destinationId: string,
|
||||
adminId: string,
|
||||
userId: string,
|
||||
) => {
|
||||
const result = await db
|
||||
.delete(destinations)
|
||||
.where(
|
||||
and(
|
||||
eq(destinations.destinationId, destinationId),
|
||||
eq(destinations.adminId, adminId),
|
||||
eq(destinations.userId, userId),
|
||||
),
|
||||
)
|
||||
.returning();
|
||||
@@ -73,7 +73,7 @@ export const updateDestinationById = async (
|
||||
.where(
|
||||
and(
|
||||
eq(destinations.destinationId, destinationId),
|
||||
eq(destinations.adminId, destinationData.adminId || ""),
|
||||
eq(destinations.userId, destinationData.userId || ""),
|
||||
),
|
||||
)
|
||||
.returning();
|
||||
|
||||
@@ -4,7 +4,7 @@ import { manageDomain } from "@dokploy/server/utils/traefik/domain";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { type apiCreateDomain, domains } from "../db/schema";
|
||||
import { findAdmin, findAdminById } from "./admin";
|
||||
import { findAdmin, findAdminById, findUserById } from "./admin";
|
||||
import { findApplicationById } from "./application";
|
||||
import { findServerById } from "./server";
|
||||
|
||||
@@ -40,7 +40,7 @@ export const createDomain = async (input: typeof apiCreateDomain._type) => {
|
||||
|
||||
export const generateTraefikMeDomain = async (
|
||||
appName: string,
|
||||
adminId: string,
|
||||
userId: string,
|
||||
serverId?: string,
|
||||
) => {
|
||||
if (serverId) {
|
||||
@@ -57,7 +57,7 @@ export const generateTraefikMeDomain = async (
|
||||
projectName: appName,
|
||||
});
|
||||
}
|
||||
const admin = await findAdminById(adminId);
|
||||
const admin = await findUserById(userId);
|
||||
return generateRandomDomain({
|
||||
serverIp: admin?.serverIp || "",
|
||||
projectName: appName,
|
||||
|
||||
@@ -13,14 +13,14 @@ export type Gitlab = typeof gitlab.$inferSelect;
|
||||
|
||||
export const createGitlab = async (
|
||||
input: typeof apiCreateGitlab._type,
|
||||
adminId: string,
|
||||
userId: string,
|
||||
) => {
|
||||
return await db.transaction(async (tx) => {
|
||||
const newGitProvider = await tx
|
||||
.insert(gitProvider)
|
||||
.values({
|
||||
providerType: "gitlab",
|
||||
adminId: adminId,
|
||||
userId: userId,
|
||||
name: input.name,
|
||||
})
|
||||
.returning()
|
||||
|
||||
@@ -13,7 +13,7 @@ import { removeDirectoryCode } from "../utils/filesystem/directory";
|
||||
import { authGithub } from "../utils/providers/github";
|
||||
import { removeTraefikConfig } from "../utils/traefik/application";
|
||||
import { manageDomain } from "../utils/traefik/domain";
|
||||
import { findAdminById } from "./admin";
|
||||
import { findAdminById, findUserById } from "./admin";
|
||||
import { findApplicationById } from "./application";
|
||||
import {
|
||||
removeDeployments,
|
||||
@@ -158,7 +158,7 @@ export const createPreviewDeployment = async (
|
||||
application.previewWildcard || "*.traefik.me",
|
||||
appName,
|
||||
application.server?.ipAddress || "",
|
||||
application.project.adminId,
|
||||
application.project.userId,
|
||||
);
|
||||
|
||||
const octokit = authGithub(application?.github as Github);
|
||||
@@ -250,7 +250,7 @@ const generateWildcardDomain = async (
|
||||
baseDomain: string,
|
||||
appName: string,
|
||||
serverIp: string,
|
||||
adminId: string,
|
||||
userId: string,
|
||||
): Promise<string> => {
|
||||
if (!baseDomain.startsWith("*.")) {
|
||||
throw new Error('The base domain must start with "*."');
|
||||
@@ -268,7 +268,7 @@ const generateWildcardDomain = async (
|
||||
}
|
||||
|
||||
if (!ip) {
|
||||
const admin = await findAdminById(adminId);
|
||||
const admin = await findUserById(userId);
|
||||
ip = admin?.serverIp || "";
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,13 @@ export type Project = typeof projects.$inferSelect;
|
||||
|
||||
export const createProject = async (
|
||||
input: typeof apiCreateProject._type,
|
||||
adminId: string,
|
||||
userId: string,
|
||||
) => {
|
||||
const newProject = await db
|
||||
.insert(projects)
|
||||
.values({
|
||||
...input,
|
||||
adminId: adminId,
|
||||
userId: userId,
|
||||
})
|
||||
.returning()
|
||||
.then((value) => value[0]);
|
||||
|
||||
@@ -49,7 +49,7 @@ export const runMariadbBackup = async (
|
||||
projectName: project.name,
|
||||
databaseType: "mariadb",
|
||||
type: "success",
|
||||
adminId: project.adminId,
|
||||
userId: project.userId,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@@ -60,7 +60,7 @@ export const runMariadbBackup = async (
|
||||
type: "error",
|
||||
// @ts-ignore
|
||||
errorMessage: error?.message || "Error message not provided",
|
||||
adminId: project.adminId,
|
||||
userId: project.userId,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ export const runMongoBackup = async (mongo: Mongo, backup: BackupSchedule) => {
|
||||
projectName: project.name,
|
||||
databaseType: "mongodb",
|
||||
type: "success",
|
||||
adminId: project.adminId,
|
||||
userId: project.userId,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@@ -57,7 +57,7 @@ export const runMongoBackup = async (mongo: Mongo, backup: BackupSchedule) => {
|
||||
type: "error",
|
||||
// @ts-ignore
|
||||
errorMessage: error?.message || "Error message not provided",
|
||||
adminId: project.adminId,
|
||||
userId: project.userId,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ export const runMySqlBackup = async (mysql: MySql, backup: BackupSchedule) => {
|
||||
projectName: project.name,
|
||||
databaseType: "mysql",
|
||||
type: "success",
|
||||
adminId: project.adminId,
|
||||
userId: project.userId,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@@ -57,7 +57,7 @@ export const runMySqlBackup = async (mysql: MySql, backup: BackupSchedule) => {
|
||||
type: "error",
|
||||
// @ts-ignore
|
||||
errorMessage: error?.message || "Error message not provided",
|
||||
adminId: project.adminId,
|
||||
userId: project.userId,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ export const runPostgresBackup = async (
|
||||
projectName: project.name,
|
||||
databaseType: "postgres",
|
||||
type: "success",
|
||||
adminId: project.adminId,
|
||||
userId: project.userId,
|
||||
});
|
||||
} catch (error) {
|
||||
await sendDatabaseBackupNotifications({
|
||||
@@ -59,7 +59,7 @@ export const runPostgresBackup = async (
|
||||
type: "error",
|
||||
// @ts-ignore
|
||||
errorMessage: error?.message || "Error message not provided",
|
||||
adminId: project.adminId,
|
||||
userId: project.userId,
|
||||
});
|
||||
|
||||
throw error;
|
||||
|
||||
@@ -18,7 +18,7 @@ interface Props {
|
||||
applicationType: string;
|
||||
errorMessage: string;
|
||||
buildLink: string;
|
||||
adminId: string;
|
||||
userId: string;
|
||||
}
|
||||
|
||||
export const sendBuildErrorNotifications = async ({
|
||||
@@ -27,14 +27,14 @@ export const sendBuildErrorNotifications = async ({
|
||||
applicationType,
|
||||
errorMessage,
|
||||
buildLink,
|
||||
adminId,
|
||||
userId,
|
||||
}: Props) => {
|
||||
const date = new Date();
|
||||
const unixDate = ~~(Number(date) / 1000);
|
||||
const notificationList = await db.query.notifications.findMany({
|
||||
where: and(
|
||||
eq(notifications.appBuildError, true),
|
||||
eq(notifications.adminId, adminId),
|
||||
eq(notifications.userId, userId),
|
||||
),
|
||||
with: {
|
||||
email: true,
|
||||
|
||||
@@ -18,7 +18,7 @@ interface Props {
|
||||
applicationName: string;
|
||||
applicationType: string;
|
||||
buildLink: string;
|
||||
adminId: string;
|
||||
userId: string;
|
||||
domains: Domain[];
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export const sendBuildSuccessNotifications = async ({
|
||||
applicationName,
|
||||
applicationType,
|
||||
buildLink,
|
||||
adminId,
|
||||
userId,
|
||||
domains,
|
||||
}: Props) => {
|
||||
const date = new Date();
|
||||
@@ -35,7 +35,7 @@ export const sendBuildSuccessNotifications = async ({
|
||||
const notificationList = await db.query.notifications.findMany({
|
||||
where: and(
|
||||
eq(notifications.appDeploy, true),
|
||||
eq(notifications.adminId, adminId),
|
||||
eq(notifications.userId, userId),
|
||||
),
|
||||
with: {
|
||||
email: true,
|
||||
|
||||
@@ -19,13 +19,13 @@ export const sendDatabaseBackupNotifications = async ({
|
||||
databaseType,
|
||||
type,
|
||||
errorMessage,
|
||||
adminId,
|
||||
userId,
|
||||
}: {
|
||||
projectName: string;
|
||||
applicationName: string;
|
||||
databaseType: "postgres" | "mysql" | "mongodb" | "mariadb";
|
||||
type: "error" | "success";
|
||||
adminId: string;
|
||||
userId: string;
|
||||
errorMessage?: string;
|
||||
}) => {
|
||||
const date = new Date();
|
||||
@@ -33,7 +33,7 @@ export const sendDatabaseBackupNotifications = async ({
|
||||
const notificationList = await db.query.notifications.findMany({
|
||||
where: and(
|
||||
eq(notifications.databaseBackup, true),
|
||||
eq(notifications.adminId, adminId),
|
||||
eq(notifications.userId, userId),
|
||||
),
|
||||
with: {
|
||||
email: true,
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
} from "./utils";
|
||||
|
||||
export const sendDockerCleanupNotifications = async (
|
||||
adminId: string,
|
||||
userId: string,
|
||||
message = "Docker cleanup for dokploy",
|
||||
) => {
|
||||
const date = new Date();
|
||||
@@ -21,7 +21,7 @@ export const sendDockerCleanupNotifications = async (
|
||||
const notificationList = await db.query.notifications.findMany({
|
||||
where: and(
|
||||
eq(notifications.dockerCleanup, true),
|
||||
eq(notifications.adminId, adminId),
|
||||
eq(notifications.userId, userId),
|
||||
),
|
||||
with: {
|
||||
email: true,
|
||||
|
||||
@@ -18,7 +18,7 @@ interface ServerThresholdPayload {
|
||||
}
|
||||
|
||||
export const sendServerThresholdNotifications = async (
|
||||
adminId: string,
|
||||
userId: string,
|
||||
payload: ServerThresholdPayload,
|
||||
) => {
|
||||
const date = new Date(payload.Timestamp);
|
||||
@@ -27,7 +27,7 @@ export const sendServerThresholdNotifications = async (
|
||||
const notificationList = await db.query.notifications.findMany({
|
||||
where: and(
|
||||
eq(notifications.serverThreshold, true),
|
||||
eq(notifications.adminId, adminId),
|
||||
eq(notifications.userId, userId),
|
||||
),
|
||||
with: {
|
||||
email: true,
|
||||
|
||||
Reference in New Issue
Block a user