mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-16 04:35:24 +02:00
Enhance application schema and database utilities: Add 'endpointSpecSwarm' to application schema, update Docker container configuration to handle 'EndpointSpec' more flexibly across various database implementations, and remove deprecated 'generateEndpointSpec' function to streamline codebase.
This commit is contained in:
@@ -28,6 +28,8 @@ import { server } from "./server";
|
||||
import {
|
||||
applicationStatus,
|
||||
certificateType,
|
||||
type EndpointSpecSwarm,
|
||||
EndpointSpecSwarmSchema,
|
||||
type HealthCheckSwarm,
|
||||
HealthCheckSwarmSchema,
|
||||
type LabelsSwarm,
|
||||
@@ -167,6 +169,7 @@ export const applications = pgTable("application", {
|
||||
labelsSwarm: json("labelsSwarm").$type<LabelsSwarm>(),
|
||||
networkSwarm: json("networkSwarm").$type<NetworkSwarm[]>(),
|
||||
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "bigint" }),
|
||||
endpointSpecSwarm: json("endpointSpecSwarm").$type<EndpointSpecSwarm>(),
|
||||
//
|
||||
replicas: integer("replicas").default(1).notNull(),
|
||||
applicationStatus: applicationStatus("applicationStatus")
|
||||
@@ -318,6 +321,7 @@ const createSchema = createInsertSchema(applications, {
|
||||
previewLabels: z.array(z.string()).optional(),
|
||||
cleanCache: z.boolean().optional(),
|
||||
stopGracePeriodSwarm: z.bigint().nullable(),
|
||||
endpointSpecSwarm: EndpointSpecSwarmSchema.nullable(),
|
||||
});
|
||||
|
||||
export const apiCreateApplication = createSchema.pick({
|
||||
|
||||
@@ -143,6 +143,7 @@ export const mechanizeDockerContainer = async (
|
||||
UpdateConfig,
|
||||
Networks,
|
||||
StopGracePeriod,
|
||||
EndpointSpec,
|
||||
} = generateConfigContainer(application);
|
||||
|
||||
const bindsMount = generateBindMounts(mounts);
|
||||
@@ -183,14 +184,16 @@ export const mechanizeDockerContainer = async (
|
||||
},
|
||||
Mode,
|
||||
RollbackConfig,
|
||||
EndpointSpec: {
|
||||
Ports: ports.map((port) => ({
|
||||
PublishMode: port.publishMode,
|
||||
Protocol: port.protocol,
|
||||
TargetPort: port.targetPort,
|
||||
PublishedPort: port.publishedPort,
|
||||
})),
|
||||
},
|
||||
EndpointSpec: EndpointSpec
|
||||
? EndpointSpec
|
||||
: {
|
||||
Ports: ports.map((port) => ({
|
||||
PublishMode: port.publishMode,
|
||||
Protocol: port.protocol,
|
||||
TargetPort: port.targetPort,
|
||||
PublishedPort: port.publishedPort,
|
||||
})),
|
||||
},
|
||||
UpdateConfig,
|
||||
...(StopGracePeriod !== undefined &&
|
||||
StopGracePeriod !== null && { StopGracePeriod }),
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
calculateResources,
|
||||
generateBindMounts,
|
||||
generateConfigContainer,
|
||||
generateEndpointSpec,
|
||||
generateFileMounts,
|
||||
generateVolumeMounts,
|
||||
prepareEnvironmentVariables,
|
||||
@@ -47,6 +46,7 @@ export const buildMariadb = async (mariadb: MariadbNested) => {
|
||||
UpdateConfig,
|
||||
Networks,
|
||||
StopGracePeriod,
|
||||
EndpointSpec,
|
||||
} = generateConfigContainer(mariadb);
|
||||
const resources = calculateResources({
|
||||
memoryLimit,
|
||||
@@ -90,7 +90,21 @@ export const buildMariadb = async (mariadb: MariadbNested) => {
|
||||
},
|
||||
Mode,
|
||||
RollbackConfig,
|
||||
EndpointSpec: generateEndpointSpec(mariadb, 3306),
|
||||
EndpointSpec: EndpointSpec
|
||||
? EndpointSpec
|
||||
: {
|
||||
Mode: "dnsrr" as const,
|
||||
Ports: externalPort
|
||||
? [
|
||||
{
|
||||
Protocol: "tcp" as const,
|
||||
TargetPort: 3306,
|
||||
PublishedPort: externalPort,
|
||||
PublishMode: "host" as const,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
},
|
||||
UpdateConfig,
|
||||
...(StopGracePeriod !== undefined &&
|
||||
StopGracePeriod !== null && { StopGracePeriod }),
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
calculateResources,
|
||||
generateBindMounts,
|
||||
generateConfigContainer,
|
||||
generateEndpointSpec,
|
||||
generateFileMounts,
|
||||
generateVolumeMounts,
|
||||
prepareEnvironmentVariables,
|
||||
@@ -93,6 +92,7 @@ ${command ?? "wait $MONGOD_PID"}`;
|
||||
UpdateConfig,
|
||||
Networks,
|
||||
StopGracePeriod,
|
||||
EndpointSpec,
|
||||
} = generateConfigContainer(mongo);
|
||||
|
||||
const resources = calculateResources({
|
||||
@@ -143,7 +143,21 @@ ${command ?? "wait $MONGOD_PID"}`;
|
||||
},
|
||||
Mode,
|
||||
RollbackConfig,
|
||||
EndpointSpec: generateEndpointSpec(mongo, 27017),
|
||||
EndpointSpec: EndpointSpec
|
||||
? EndpointSpec
|
||||
: {
|
||||
Mode: "dnsrr" as const,
|
||||
Ports: externalPort
|
||||
? [
|
||||
{
|
||||
Protocol: "tcp" as const,
|
||||
TargetPort: 27017,
|
||||
PublishedPort: externalPort,
|
||||
PublishMode: "host" as const,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
},
|
||||
UpdateConfig,
|
||||
...(StopGracePeriod !== undefined &&
|
||||
StopGracePeriod !== null && { StopGracePeriod }),
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
calculateResources,
|
||||
generateBindMounts,
|
||||
generateConfigContainer,
|
||||
generateEndpointSpec,
|
||||
generateFileMounts,
|
||||
generateVolumeMounts,
|
||||
prepareEnvironmentVariables,
|
||||
@@ -53,6 +52,7 @@ export const buildMysql = async (mysql: MysqlNested) => {
|
||||
UpdateConfig,
|
||||
Networks,
|
||||
StopGracePeriod,
|
||||
EndpointSpec,
|
||||
} = generateConfigContainer(mysql);
|
||||
const resources = calculateResources({
|
||||
memoryLimit,
|
||||
@@ -96,7 +96,21 @@ export const buildMysql = async (mysql: MysqlNested) => {
|
||||
},
|
||||
Mode,
|
||||
RollbackConfig,
|
||||
EndpointSpec: generateEndpointSpec(mysql, 3306),
|
||||
EndpointSpec: EndpointSpec
|
||||
? EndpointSpec
|
||||
: {
|
||||
Mode: "dnsrr" as const,
|
||||
Ports: externalPort
|
||||
? [
|
||||
{
|
||||
Protocol: "tcp" as const,
|
||||
TargetPort: 3306,
|
||||
PublishedPort: externalPort,
|
||||
PublishMode: "host" as const,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
},
|
||||
UpdateConfig,
|
||||
...(StopGracePeriod !== undefined &&
|
||||
StopGracePeriod !== null && { StopGracePeriod }),
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
calculateResources,
|
||||
generateBindMounts,
|
||||
generateConfigContainer,
|
||||
generateEndpointSpec,
|
||||
generateFileMounts,
|
||||
generateVolumeMounts,
|
||||
prepareEnvironmentVariables,
|
||||
@@ -46,6 +45,7 @@ export const buildPostgres = async (postgres: PostgresNested) => {
|
||||
UpdateConfig,
|
||||
Networks,
|
||||
StopGracePeriod,
|
||||
EndpointSpec,
|
||||
} = generateConfigContainer(postgres);
|
||||
const resources = calculateResources({
|
||||
memoryLimit,
|
||||
@@ -89,7 +89,21 @@ export const buildPostgres = async (postgres: PostgresNested) => {
|
||||
},
|
||||
Mode,
|
||||
RollbackConfig,
|
||||
EndpointSpec: generateEndpointSpec(postgres, 5432),
|
||||
EndpointSpec: EndpointSpec
|
||||
? EndpointSpec
|
||||
: {
|
||||
Mode: "dnsrr" as const,
|
||||
Ports: externalPort
|
||||
? [
|
||||
{
|
||||
Protocol: "tcp" as const,
|
||||
TargetPort: 5432,
|
||||
PublishedPort: externalPort,
|
||||
PublishMode: "host" as const,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
},
|
||||
UpdateConfig,
|
||||
...(StopGracePeriod !== undefined &&
|
||||
StopGracePeriod !== null && { StopGracePeriod }),
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
calculateResources,
|
||||
generateBindMounts,
|
||||
generateConfigContainer,
|
||||
generateEndpointSpec,
|
||||
generateFileMounts,
|
||||
generateVolumeMounts,
|
||||
prepareEnvironmentVariables,
|
||||
@@ -44,6 +43,7 @@ export const buildRedis = async (redis: RedisNested) => {
|
||||
UpdateConfig,
|
||||
Networks,
|
||||
StopGracePeriod,
|
||||
EndpointSpec,
|
||||
} = generateConfigContainer(redis);
|
||||
const resources = calculateResources({
|
||||
memoryLimit,
|
||||
@@ -86,7 +86,21 @@ export const buildRedis = async (redis: RedisNested) => {
|
||||
},
|
||||
Mode,
|
||||
RollbackConfig,
|
||||
EndpointSpec: generateEndpointSpec(redis, 6379),
|
||||
EndpointSpec: EndpointSpec
|
||||
? EndpointSpec
|
||||
: {
|
||||
Mode: "dnsrr" as const,
|
||||
Ports: externalPort
|
||||
? [
|
||||
{
|
||||
Protocol: "tcp" as const,
|
||||
TargetPort: 6379,
|
||||
PublishedPort: externalPort,
|
||||
PublishMode: "host" as const,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
},
|
||||
UpdateConfig,
|
||||
...(StopGracePeriod !== undefined &&
|
||||
StopGracePeriod !== null && { StopGracePeriod }),
|
||||
|
||||
@@ -395,6 +395,7 @@ export const generateConfigContainer = (
|
||||
mounts,
|
||||
networkSwarm,
|
||||
stopGracePeriodSwarm,
|
||||
endpointSpecSwarm,
|
||||
} = application;
|
||||
|
||||
const sanitizedStopGracePeriodSwarm =
|
||||
@@ -408,11 +409,9 @@ export const generateConfigContainer = (
|
||||
...(healthCheckSwarm && {
|
||||
HealthCheck: healthCheckSwarm,
|
||||
}),
|
||||
...(restartPolicySwarm
|
||||
? {
|
||||
RestartPolicy: restartPolicySwarm,
|
||||
}
|
||||
: {}),
|
||||
...(restartPolicySwarm && {
|
||||
RestartPolicy: restartPolicySwarm,
|
||||
}),
|
||||
...(placementSwarm
|
||||
? {
|
||||
Placement: placementSwarm,
|
||||
@@ -461,42 +460,18 @@ export const generateConfigContainer = (
|
||||
: {
|
||||
Networks: [{ Target: "dokploy-network" }],
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
export const generateEndpointSpec = (
|
||||
database: Partial<
|
||||
PostgresNested | MysqlNested | MariadbNested | MongoNested | RedisNested
|
||||
>,
|
||||
defaultTargetPort: number,
|
||||
) => {
|
||||
const { endpointSpecSwarm, externalPort } = database;
|
||||
|
||||
if (endpointSpecSwarm) {
|
||||
return {
|
||||
...(endpointSpecSwarm.Mode && { Mode: endpointSpecSwarm.Mode }),
|
||||
Ports:
|
||||
endpointSpecSwarm.Ports?.map((port) => ({
|
||||
Protocol: (port.Protocol || "tcp") as "tcp" | "udp" | "sctp",
|
||||
TargetPort: port.TargetPort,
|
||||
PublishedPort: port.PublishedPort || 0,
|
||||
PublishMode: (port.PublishMode || "host") as "ingress" | "host",
|
||||
})) || [],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
Mode: "dnsrr" as const,
|
||||
Ports: externalPort
|
||||
? [
|
||||
{
|
||||
Protocol: "tcp" as const,
|
||||
TargetPort: defaultTargetPort,
|
||||
PublishedPort: externalPort,
|
||||
PublishMode: "host" as const,
|
||||
},
|
||||
]
|
||||
: [],
|
||||
...(endpointSpecSwarm && {
|
||||
EndpointSpec: {
|
||||
...(endpointSpecSwarm.Mode && { Mode: endpointSpecSwarm.Mode }),
|
||||
Ports:
|
||||
endpointSpecSwarm.Ports?.map((port) => ({
|
||||
Protocol: (port.Protocol || "tcp") as "tcp" | "udp" | "sctp",
|
||||
TargetPort: port.TargetPort || 0,
|
||||
PublishedPort: port.PublishedPort || 0,
|
||||
PublishMode: (port.PublishMode || "host") as "ingress" | "host",
|
||||
})) || [],
|
||||
},
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user