mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
fix: fixed/improved handling of app names in api
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { generatePassword } from "@dokploy/server/templates/utils";
|
||||||
import { faker } from "@faker-js/faker";
|
import { faker } from "@faker-js/faker";
|
||||||
import { customAlphabet } from "nanoid";
|
import { customAlphabet } from "nanoid";
|
||||||
|
|
||||||
@@ -13,3 +14,17 @@ export const generateAppName = (type: string) => {
|
|||||||
const nanoidPart = customNanoid();
|
const nanoidPart = customNanoid();
|
||||||
return `${type}-${randomFakerElement}-${nanoidPart}`;
|
return `${type}-${randomFakerElement}-${nanoidPart}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const cleanAppName = (appName?: string) => {
|
||||||
|
if (!appName) {
|
||||||
|
return appName;
|
||||||
|
}
|
||||||
|
return appName.trim().replace(/ /g, "-");
|
||||||
|
};
|
||||||
|
|
||||||
|
export const buildAppName = (type: string, baseAppName?: string) => {
|
||||||
|
if (baseAppName) {
|
||||||
|
return `${cleanAppName(baseAppName)}-${generatePassword(6)}`;
|
||||||
|
}
|
||||||
|
return generateAppName(type);
|
||||||
|
};
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { db } from "@dokploy/server/db";
|
|||||||
import {
|
import {
|
||||||
type apiCreateApplication,
|
type apiCreateApplication,
|
||||||
applications,
|
applications,
|
||||||
|
buildAppName,
|
||||||
|
cleanAppName,
|
||||||
} from "@dokploy/server/db/schema";
|
} from "@dokploy/server/db/schema";
|
||||||
import { generateAppName } from "@dokploy/server/db/schema";
|
|
||||||
import { getAdvancedStats } from "@dokploy/server/monitoring/utilts";
|
import { getAdvancedStats } from "@dokploy/server/monitoring/utilts";
|
||||||
import { generatePassword } from "@dokploy/server/templates/utils";
|
|
||||||
import {
|
import {
|
||||||
buildApplication,
|
buildApplication,
|
||||||
getBuildCommand,
|
getBuildCommand,
|
||||||
@@ -46,34 +46,31 @@ import {
|
|||||||
createDeploymentPreview,
|
createDeploymentPreview,
|
||||||
updateDeploymentStatus,
|
updateDeploymentStatus,
|
||||||
} from "./deployment";
|
} from "./deployment";
|
||||||
import { validUniqueServerAppName } from "./project";
|
import { type Domain, getDomainHost } from "./domain";
|
||||||
import {
|
|
||||||
findPreviewDeploymentById,
|
|
||||||
updatePreviewDeployment,
|
|
||||||
} from "./preview-deployment";
|
|
||||||
import {
|
import {
|
||||||
createPreviewDeploymentComment,
|
createPreviewDeploymentComment,
|
||||||
getIssueComment,
|
getIssueComment,
|
||||||
issueCommentExists,
|
issueCommentExists,
|
||||||
updateIssueComment,
|
updateIssueComment,
|
||||||
} from "./github";
|
} from "./github";
|
||||||
import { type Domain, getDomainHost } from "./domain";
|
import {
|
||||||
|
findPreviewDeploymentById,
|
||||||
|
updatePreviewDeployment,
|
||||||
|
} from "./preview-deployment";
|
||||||
|
import { validUniqueServerAppName } from "./project";
|
||||||
export type Application = typeof applications.$inferSelect;
|
export type Application = typeof applications.$inferSelect;
|
||||||
|
|
||||||
export const createApplication = async (
|
export const createApplication = async (
|
||||||
input: typeof apiCreateApplication._type,
|
input: typeof apiCreateApplication._type,
|
||||||
) => {
|
) => {
|
||||||
input.appName =
|
const appName = buildAppName("app", input.appName);
|
||||||
`${input.appName}-${generatePassword(6)}` || generateAppName("app");
|
|
||||||
if (input.appName) {
|
|
||||||
const valid = await validUniqueServerAppName(input.appName);
|
|
||||||
|
|
||||||
if (!valid) {
|
const valid = await validUniqueServerAppName(appName);
|
||||||
throw new TRPCError({
|
if (!valid) {
|
||||||
code: "CONFLICT",
|
throw new TRPCError({
|
||||||
message: "Application with this 'AppName' already exists",
|
code: "CONFLICT",
|
||||||
});
|
message: "Application with this 'AppName' already exists",
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return await db.transaction(async (tx) => {
|
return await db.transaction(async (tx) => {
|
||||||
@@ -81,6 +78,7 @@ export const createApplication = async (
|
|||||||
.insert(applications)
|
.insert(applications)
|
||||||
.values({
|
.values({
|
||||||
...input,
|
...input,
|
||||||
|
appName,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -144,6 +142,7 @@ export const updateApplication = async (
|
|||||||
.update(applications)
|
.update(applications)
|
||||||
.set({
|
.set({
|
||||||
...applicationData,
|
...applicationData,
|
||||||
|
appName: cleanAppName(applicationData.appName),
|
||||||
})
|
})
|
||||||
.where(eq(applications.applicationId, applicationId))
|
.where(eq(applications.applicationId, applicationId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { join } 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 { type apiCreateCompose, compose } from "@dokploy/server/db/schema";
|
import { type apiCreateCompose, compose } from "@dokploy/server/db/schema";
|
||||||
import { generateAppName } from "@dokploy/server/db/schema";
|
import { buildAppName, cleanAppName } from "@dokploy/server/db/schema";
|
||||||
import { generatePassword } from "@dokploy/server/templates/utils";
|
import { generatePassword } from "@dokploy/server/templates/utils";
|
||||||
import {
|
import {
|
||||||
buildCompose,
|
buildCompose,
|
||||||
@@ -52,17 +52,14 @@ import { validUniqueServerAppName } from "./project";
|
|||||||
export type Compose = typeof compose.$inferSelect;
|
export type Compose = typeof compose.$inferSelect;
|
||||||
|
|
||||||
export const createCompose = async (input: typeof apiCreateCompose._type) => {
|
export const createCompose = async (input: typeof apiCreateCompose._type) => {
|
||||||
input.appName =
|
const appName = buildAppName("compose", input.appName);
|
||||||
`${input.appName}-${generatePassword(6)}` || generateAppName("compose");
|
|
||||||
if (input.appName) {
|
|
||||||
const valid = await validUniqueServerAppName(input.appName);
|
|
||||||
|
|
||||||
if (!valid) {
|
const valid = await validUniqueServerAppName(appName);
|
||||||
throw new TRPCError({
|
if (!valid) {
|
||||||
code: "CONFLICT",
|
throw new TRPCError({
|
||||||
message: "Service with this 'AppName' already exists",
|
code: "CONFLICT",
|
||||||
});
|
message: "Service with this 'AppName' already exists",
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const newDestination = await db
|
const newDestination = await db
|
||||||
@@ -70,6 +67,7 @@ export const createCompose = async (input: typeof apiCreateCompose._type) => {
|
|||||||
.values({
|
.values({
|
||||||
...input,
|
...input,
|
||||||
composeFile: "",
|
composeFile: "",
|
||||||
|
appName,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -87,8 +85,9 @@ export const createCompose = async (input: typeof apiCreateCompose._type) => {
|
|||||||
export const createComposeByTemplate = async (
|
export const createComposeByTemplate = async (
|
||||||
input: typeof compose.$inferInsert,
|
input: typeof compose.$inferInsert,
|
||||||
) => {
|
) => {
|
||||||
if (input.appName) {
|
const appName = cleanAppName(input.appName);
|
||||||
const valid = await validUniqueServerAppName(input.appName);
|
if (appName) {
|
||||||
|
const valid = await validUniqueServerAppName(appName);
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -101,6 +100,7 @@ export const createComposeByTemplate = async (
|
|||||||
.insert(compose)
|
.insert(compose)
|
||||||
.values({
|
.values({
|
||||||
...input,
|
...input,
|
||||||
|
appName,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -188,6 +188,7 @@ export const updateCompose = async (
|
|||||||
.update(compose)
|
.update(compose)
|
||||||
.set({
|
.set({
|
||||||
...composeData,
|
...composeData,
|
||||||
|
appName: cleanAppName(composeData.appName),
|
||||||
})
|
})
|
||||||
.where(eq(compose.composeId, composeId))
|
.where(eq(compose.composeId, composeId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ import { type Server, findServerById } from "./server";
|
|||||||
|
|
||||||
import { execAsyncRemote } from "@dokploy/server/utils/process/execAsync";
|
import { execAsyncRemote } from "@dokploy/server/utils/process/execAsync";
|
||||||
import {
|
import {
|
||||||
findPreviewDeploymentById,
|
|
||||||
type PreviewDeployment,
|
type PreviewDeployment,
|
||||||
|
findPreviewDeploymentById,
|
||||||
updatePreviewDeployment,
|
updatePreviewDeployment,
|
||||||
} from "./preview-deployment";
|
} from "./preview-deployment";
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
backups,
|
backups,
|
||||||
mariadb,
|
mariadb,
|
||||||
} from "@dokploy/server/db/schema";
|
} from "@dokploy/server/db/schema";
|
||||||
import { generateAppName } from "@dokploy/server/db/schema";
|
import { buildAppName, cleanAppName } from "@dokploy/server/db/schema";
|
||||||
import { generatePassword } from "@dokploy/server/templates/utils";
|
import { generatePassword } from "@dokploy/server/templates/utils";
|
||||||
import { buildMariadb } from "@dokploy/server/utils/databases/mariadb";
|
import { buildMariadb } from "@dokploy/server/utils/databases/mariadb";
|
||||||
import { pullImage } from "@dokploy/server/utils/docker/utils";
|
import { pullImage } from "@dokploy/server/utils/docker/utils";
|
||||||
@@ -17,17 +17,14 @@ import { execAsyncRemote } from "@dokploy/server/utils/process/execAsync";
|
|||||||
export type Mariadb = typeof mariadb.$inferSelect;
|
export type Mariadb = typeof mariadb.$inferSelect;
|
||||||
|
|
||||||
export const createMariadb = async (input: typeof apiCreateMariaDB._type) => {
|
export const createMariadb = async (input: typeof apiCreateMariaDB._type) => {
|
||||||
input.appName =
|
const appName = buildAppName("mariadb", input.appName);
|
||||||
`${input.appName}-${generatePassword(6)}` || generateAppName("mariadb");
|
|
||||||
if (input.appName) {
|
|
||||||
const valid = await validUniqueServerAppName(input.appName);
|
|
||||||
|
|
||||||
if (!valid) {
|
const valid = await validUniqueServerAppName(input.appName);
|
||||||
throw new TRPCError({
|
if (!valid) {
|
||||||
code: "CONFLICT",
|
throw new TRPCError({
|
||||||
message: "Service with this 'AppName' already exists",
|
code: "CONFLICT",
|
||||||
});
|
message: "Service with this 'AppName' already exists",
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const newMariadb = await db
|
const newMariadb = await db
|
||||||
@@ -40,6 +37,7 @@ export const createMariadb = async (input: typeof apiCreateMariaDB._type) => {
|
|||||||
databaseRootPassword: input.databaseRootPassword
|
databaseRootPassword: input.databaseRootPassword
|
||||||
? input.databaseRootPassword
|
? input.databaseRootPassword
|
||||||
: generatePassword(),
|
: generatePassword(),
|
||||||
|
appName,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -86,6 +84,7 @@ export const updateMariadbById = async (
|
|||||||
.update(mariadb)
|
.update(mariadb)
|
||||||
.set({
|
.set({
|
||||||
...mariadbData,
|
...mariadbData,
|
||||||
|
appName: cleanAppName(mariadbData.appName),
|
||||||
})
|
})
|
||||||
.where(eq(mariadb.mariadbId, mariadbId))
|
.where(eq(mariadb.mariadbId, mariadbId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { db } from "@dokploy/server/db";
|
import { db } from "@dokploy/server/db";
|
||||||
import { type apiCreateMongo, backups, mongo } from "@dokploy/server/db/schema";
|
import { type apiCreateMongo, backups, mongo } from "@dokploy/server/db/schema";
|
||||||
import { generateAppName } from "@dokploy/server/db/schema";
|
import { buildAppName, cleanAppName } from "@dokploy/server/db/schema";
|
||||||
import { generatePassword } from "@dokploy/server/templates/utils";
|
import { generatePassword } from "@dokploy/server/templates/utils";
|
||||||
import { buildMongo } from "@dokploy/server/utils/databases/mongo";
|
import { buildMongo } from "@dokploy/server/utils/databases/mongo";
|
||||||
import { pullImage } from "@dokploy/server/utils/docker/utils";
|
import { pullImage } from "@dokploy/server/utils/docker/utils";
|
||||||
@@ -13,17 +13,14 @@ import { execAsyncRemote } from "@dokploy/server/utils/process/execAsync";
|
|||||||
export type Mongo = typeof mongo.$inferSelect;
|
export type Mongo = typeof mongo.$inferSelect;
|
||||||
|
|
||||||
export const createMongo = async (input: typeof apiCreateMongo._type) => {
|
export const createMongo = async (input: typeof apiCreateMongo._type) => {
|
||||||
input.appName =
|
const appName = buildAppName("mongo", input.appName);
|
||||||
`${input.appName}-${generatePassword(6)}` || generateAppName("mongo");
|
|
||||||
if (input.appName) {
|
|
||||||
const valid = await validUniqueServerAppName(input.appName);
|
|
||||||
|
|
||||||
if (!valid) {
|
const valid = await validUniqueServerAppName(appName);
|
||||||
throw new TRPCError({
|
if (!valid) {
|
||||||
code: "CONFLICT",
|
throw new TRPCError({
|
||||||
message: "Service with this 'AppName' already exists",
|
code: "CONFLICT",
|
||||||
});
|
message: "Service with this 'AppName' already exists",
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const newMongo = await db
|
const newMongo = await db
|
||||||
@@ -33,6 +30,7 @@ export const createMongo = async (input: typeof apiCreateMongo._type) => {
|
|||||||
databasePassword: input.databasePassword
|
databasePassword: input.databasePassword
|
||||||
? input.databasePassword
|
? input.databasePassword
|
||||||
: generatePassword(),
|
: generatePassword(),
|
||||||
|
appName,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -78,6 +76,7 @@ export const updateMongoById = async (
|
|||||||
.update(mongo)
|
.update(mongo)
|
||||||
.set({
|
.set({
|
||||||
...mongoData,
|
...mongoData,
|
||||||
|
appName: cleanAppName(mongoData.appName),
|
||||||
})
|
})
|
||||||
.where(eq(mongo.mongoId, mongoId))
|
.where(eq(mongo.mongoId, mongoId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { db } from "@dokploy/server/db";
|
import { db } from "@dokploy/server/db";
|
||||||
import { type apiCreateMySql, backups, mysql } from "@dokploy/server/db/schema";
|
import { type apiCreateMySql, backups, mysql } from "@dokploy/server/db/schema";
|
||||||
import { generateAppName } from "@dokploy/server/db/schema";
|
import { buildAppName, cleanAppName } from "@dokploy/server/db/schema";
|
||||||
import { generatePassword } from "@dokploy/server/templates/utils";
|
import { generatePassword } from "@dokploy/server/templates/utils";
|
||||||
import { buildMysql } from "@dokploy/server/utils/databases/mysql";
|
import { buildMysql } from "@dokploy/server/utils/databases/mysql";
|
||||||
import { pullImage } from "@dokploy/server/utils/docker/utils";
|
import { pullImage } from "@dokploy/server/utils/docker/utils";
|
||||||
@@ -13,18 +13,14 @@ import { execAsyncRemote } from "@dokploy/server/utils/process/execAsync";
|
|||||||
export type MySql = typeof mysql.$inferSelect;
|
export type MySql = typeof mysql.$inferSelect;
|
||||||
|
|
||||||
export const createMysql = async (input: typeof apiCreateMySql._type) => {
|
export const createMysql = async (input: typeof apiCreateMySql._type) => {
|
||||||
input.appName =
|
const appName = buildAppName("mysql", input.appName);
|
||||||
`${input.appName}-${generatePassword(6)}` || generateAppName("mysql");
|
|
||||||
|
|
||||||
if (input.appName) {
|
const valid = await validUniqueServerAppName(appName);
|
||||||
const valid = await validUniqueServerAppName(input.appName);
|
if (!valid) {
|
||||||
|
throw new TRPCError({
|
||||||
if (!valid) {
|
code: "CONFLICT",
|
||||||
throw new TRPCError({
|
message: "Service with this 'AppName' already exists",
|
||||||
code: "CONFLICT",
|
});
|
||||||
message: "Service with this 'AppName' already exists",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const newMysql = await db
|
const newMysql = await db
|
||||||
@@ -37,6 +33,7 @@ export const createMysql = async (input: typeof apiCreateMySql._type) => {
|
|||||||
databaseRootPassword: input.databaseRootPassword
|
databaseRootPassword: input.databaseRootPassword
|
||||||
? input.databaseRootPassword
|
? input.databaseRootPassword
|
||||||
: generatePassword(),
|
: generatePassword(),
|
||||||
|
appName,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -83,6 +80,7 @@ export const updateMySqlById = async (
|
|||||||
.update(mysql)
|
.update(mysql)
|
||||||
.set({
|
.set({
|
||||||
...mysqlData,
|
...mysqlData,
|
||||||
|
appName: cleanAppName(mysqlData.appName),
|
||||||
})
|
})
|
||||||
.where(eq(mysql.mysqlId, mysqlId))
|
.where(eq(mysql.mysqlId, mysqlId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
backups,
|
backups,
|
||||||
postgres,
|
postgres,
|
||||||
} from "@dokploy/server/db/schema";
|
} from "@dokploy/server/db/schema";
|
||||||
import { generateAppName } from "@dokploy/server/db/schema";
|
import { buildAppName, cleanAppName } from "@dokploy/server/db/schema";
|
||||||
import { generatePassword } from "@dokploy/server/templates/utils";
|
import { generatePassword } from "@dokploy/server/templates/utils";
|
||||||
import { buildPostgres } from "@dokploy/server/utils/databases/postgres";
|
import { buildPostgres } from "@dokploy/server/utils/databases/postgres";
|
||||||
import { pullImage } from "@dokploy/server/utils/docker/utils";
|
import { pullImage } from "@dokploy/server/utils/docker/utils";
|
||||||
@@ -17,17 +17,14 @@ import { execAsyncRemote } from "@dokploy/server/utils/process/execAsync";
|
|||||||
export type Postgres = typeof postgres.$inferSelect;
|
export type Postgres = typeof postgres.$inferSelect;
|
||||||
|
|
||||||
export const createPostgres = async (input: typeof apiCreatePostgres._type) => {
|
export const createPostgres = async (input: typeof apiCreatePostgres._type) => {
|
||||||
input.appName =
|
const appName = buildAppName("postgres", input.appName);
|
||||||
`${input.appName}-${generatePassword(6)}` || generateAppName("postgres");
|
|
||||||
if (input.appName) {
|
|
||||||
const valid = await validUniqueServerAppName(input.appName);
|
|
||||||
|
|
||||||
if (!valid) {
|
const valid = await validUniqueServerAppName(appName);
|
||||||
throw new TRPCError({
|
if (!valid) {
|
||||||
code: "CONFLICT",
|
throw new TRPCError({
|
||||||
message: "Service with this 'AppName' already exists",
|
code: "CONFLICT",
|
||||||
});
|
message: "Service with this 'AppName' already exists",
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const newPostgres = await db
|
const newPostgres = await db
|
||||||
@@ -37,6 +34,7 @@ export const createPostgres = async (input: typeof apiCreatePostgres._type) => {
|
|||||||
databasePassword: input.databasePassword
|
databasePassword: input.databasePassword
|
||||||
? input.databasePassword
|
? input.databasePassword
|
||||||
: generatePassword(),
|
: generatePassword(),
|
||||||
|
appName,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -100,6 +98,7 @@ export const updatePostgresById = async (
|
|||||||
.update(postgres)
|
.update(postgres)
|
||||||
.set({
|
.set({
|
||||||
...postgresData,
|
...postgresData,
|
||||||
|
appName: cleanAppName(postgresData.appName),
|
||||||
})
|
})
|
||||||
.where(eq(postgres.postgresId, postgresId))
|
.where(eq(postgres.postgresId, postgresId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
@@ -7,20 +7,20 @@ import {
|
|||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { and, desc, eq } from "drizzle-orm";
|
import { and, desc, eq } from "drizzle-orm";
|
||||||
import { slugify } from "../setup/server-setup";
|
import { slugify } from "../setup/server-setup";
|
||||||
import { findApplicationById } from "./application";
|
|
||||||
import { createDomain } from "./domain";
|
|
||||||
import { generatePassword, generateRandomDomain } from "../templates/utils";
|
import { generatePassword, generateRandomDomain } from "../templates/utils";
|
||||||
|
import { removeService } from "../utils/docker/utils";
|
||||||
|
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 { manageDomain } from "../utils/traefik/domain";
|
||||||
|
import { findAdminById } from "./admin";
|
||||||
|
import { findApplicationById } from "./application";
|
||||||
import {
|
import {
|
||||||
removeDeployments,
|
removeDeployments,
|
||||||
removeDeploymentsByPreviewDeploymentId,
|
removeDeploymentsByPreviewDeploymentId,
|
||||||
} from "./deployment";
|
} from "./deployment";
|
||||||
import { removeDirectoryCode } from "../utils/filesystem/directory";
|
import { createDomain } from "./domain";
|
||||||
import { removeTraefikConfig } from "../utils/traefik/application";
|
import { type Github, getIssueComment } from "./github";
|
||||||
import { removeService } from "../utils/docker/utils";
|
|
||||||
import { authGithub } from "../utils/providers/github";
|
|
||||||
import { getIssueComment, type Github } from "./github";
|
|
||||||
import { findAdminById } from "./admin";
|
|
||||||
|
|
||||||
export type PreviewDeployment = typeof previewDeployments.$inferSelect;
|
export type PreviewDeployment = typeof previewDeployments.$inferSelect;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { db } from "@dokploy/server/db";
|
import { db } from "@dokploy/server/db";
|
||||||
import { type apiCreateRedis, redis } from "@dokploy/server/db/schema";
|
import { type apiCreateRedis, redis } from "@dokploy/server/db/schema";
|
||||||
import { generateAppName } from "@dokploy/server/db/schema";
|
import { buildAppName, cleanAppName } from "@dokploy/server/db/schema";
|
||||||
import { generatePassword } from "@dokploy/server/templates/utils";
|
import { generatePassword } from "@dokploy/server/templates/utils";
|
||||||
import { buildRedis } from "@dokploy/server/utils/databases/redis";
|
import { buildRedis } from "@dokploy/server/utils/databases/redis";
|
||||||
import { pullImage } from "@dokploy/server/utils/docker/utils";
|
import { pullImage } from "@dokploy/server/utils/docker/utils";
|
||||||
@@ -14,17 +14,14 @@ export type Redis = typeof redis.$inferSelect;
|
|||||||
|
|
||||||
// https://github.com/drizzle-team/drizzle-orm/discussions/1483#discussioncomment-7523881
|
// https://github.com/drizzle-team/drizzle-orm/discussions/1483#discussioncomment-7523881
|
||||||
export const createRedis = async (input: typeof apiCreateRedis._type) => {
|
export const createRedis = async (input: typeof apiCreateRedis._type) => {
|
||||||
input.appName =
|
const appName = buildAppName("redis", input.appName);
|
||||||
`${input.appName}-${generatePassword(6)}` || generateAppName("redis");
|
|
||||||
if (input.appName) {
|
|
||||||
const valid = await validUniqueServerAppName(input.appName);
|
|
||||||
|
|
||||||
if (!valid) {
|
const valid = await validUniqueServerAppName(appName);
|
||||||
throw new TRPCError({
|
if (!valid) {
|
||||||
code: "CONFLICT",
|
throw new TRPCError({
|
||||||
message: "Service with this 'AppName' already exists",
|
code: "CONFLICT",
|
||||||
});
|
message: "Service with this 'AppName' already exists",
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const newRedis = await db
|
const newRedis = await db
|
||||||
@@ -34,6 +31,7 @@ export const createRedis = async (input: typeof apiCreateRedis._type) => {
|
|||||||
databasePassword: input.databasePassword
|
databasePassword: input.databasePassword
|
||||||
? input.databasePassword
|
? input.databasePassword
|
||||||
: generatePassword(),
|
: generatePassword(),
|
||||||
|
appName,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -74,6 +72,7 @@ export const updateRedisById = async (
|
|||||||
.update(redis)
|
.update(redis)
|
||||||
.set({
|
.set({
|
||||||
...redisData,
|
...redisData,
|
||||||
|
appName: cleanAppName(redisData.appName),
|
||||||
})
|
})
|
||||||
.where(eq(redis.redisId, redisId))
|
.where(eq(redis.redisId, redisId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
Reference in New Issue
Block a user