mirror of
https://github.com/andwati/dokploy.git
synced 2026-10-18 03:02:56 +00: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 {
|
import {
|
||||||
applicationStatus,
|
applicationStatus,
|
||||||
certificateType,
|
certificateType,
|
||||||
|
type EndpointSpecSwarm,
|
||||||
|
EndpointSpecSwarmSchema,
|
||||||
type HealthCheckSwarm,
|
type HealthCheckSwarm,
|
||||||
HealthCheckSwarmSchema,
|
HealthCheckSwarmSchema,
|
||||||
type LabelsSwarm,
|
type LabelsSwarm,
|
||||||
@@ -167,6 +169,7 @@ export const applications = pgTable("application", {
|
|||||||
labelsSwarm: json("labelsSwarm").$type<LabelsSwarm>(),
|
labelsSwarm: json("labelsSwarm").$type<LabelsSwarm>(),
|
||||||
networkSwarm: json("networkSwarm").$type<NetworkSwarm[]>(),
|
networkSwarm: json("networkSwarm").$type<NetworkSwarm[]>(),
|
||||||
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "bigint" }),
|
stopGracePeriodSwarm: bigint("stopGracePeriodSwarm", { mode: "bigint" }),
|
||||||
|
endpointSpecSwarm: json("endpointSpecSwarm").$type<EndpointSpecSwarm>(),
|
||||||
//
|
//
|
||||||
replicas: integer("replicas").default(1).notNull(),
|
replicas: integer("replicas").default(1).notNull(),
|
||||||
applicationStatus: applicationStatus("applicationStatus")
|
applicationStatus: applicationStatus("applicationStatus")
|
||||||
@@ -318,6 +321,7 @@ const createSchema = createInsertSchema(applications, {
|
|||||||
previewLabels: z.array(z.string()).optional(),
|
previewLabels: z.array(z.string()).optional(),
|
||||||
cleanCache: z.boolean().optional(),
|
cleanCache: z.boolean().optional(),
|
||||||
stopGracePeriodSwarm: z.bigint().nullable(),
|
stopGracePeriodSwarm: z.bigint().nullable(),
|
||||||
|
endpointSpecSwarm: EndpointSpecSwarmSchema.nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiCreateApplication = createSchema.pick({
|
export const apiCreateApplication = createSchema.pick({
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ export const mechanizeDockerContainer = async (
|
|||||||
UpdateConfig,
|
UpdateConfig,
|
||||||
Networks,
|
Networks,
|
||||||
StopGracePeriod,
|
StopGracePeriod,
|
||||||
|
EndpointSpec,
|
||||||
} = generateConfigContainer(application);
|
} = generateConfigContainer(application);
|
||||||
|
|
||||||
const bindsMount = generateBindMounts(mounts);
|
const bindsMount = generateBindMounts(mounts);
|
||||||
@@ -183,14 +184,16 @@ export const mechanizeDockerContainer = async (
|
|||||||
},
|
},
|
||||||
Mode,
|
Mode,
|
||||||
RollbackConfig,
|
RollbackConfig,
|
||||||
EndpointSpec: {
|
EndpointSpec: EndpointSpec
|
||||||
Ports: ports.map((port) => ({
|
? EndpointSpec
|
||||||
PublishMode: port.publishMode,
|
: {
|
||||||
Protocol: port.protocol,
|
Ports: ports.map((port) => ({
|
||||||
TargetPort: port.targetPort,
|
PublishMode: port.publishMode,
|
||||||
PublishedPort: port.publishedPort,
|
Protocol: port.protocol,
|
||||||
})),
|
TargetPort: port.targetPort,
|
||||||
},
|
PublishedPort: port.publishedPort,
|
||||||
|
})),
|
||||||
|
},
|
||||||
UpdateConfig,
|
UpdateConfig,
|
||||||
...(StopGracePeriod !== undefined &&
|
...(StopGracePeriod !== undefined &&
|
||||||
StopGracePeriod !== null && { StopGracePeriod }),
|
StopGracePeriod !== null && { StopGracePeriod }),
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
calculateResources,
|
calculateResources,
|
||||||
generateBindMounts,
|
generateBindMounts,
|
||||||
generateConfigContainer,
|
generateConfigContainer,
|
||||||
generateEndpointSpec,
|
|
||||||
generateFileMounts,
|
generateFileMounts,
|
||||||
generateVolumeMounts,
|
generateVolumeMounts,
|
||||||
prepareEnvironmentVariables,
|
prepareEnvironmentVariables,
|
||||||
@@ -47,6 +46,7 @@ export const buildMariadb = async (mariadb: MariadbNested) => {
|
|||||||
UpdateConfig,
|
UpdateConfig,
|
||||||
Networks,
|
Networks,
|
||||||
StopGracePeriod,
|
StopGracePeriod,
|
||||||
|
EndpointSpec,
|
||||||
} = generateConfigContainer(mariadb);
|
} = generateConfigContainer(mariadb);
|
||||||
const resources = calculateResources({
|
const resources = calculateResources({
|
||||||
memoryLimit,
|
memoryLimit,
|
||||||
@@ -90,7 +90,21 @@ export const buildMariadb = async (mariadb: MariadbNested) => {
|
|||||||
},
|
},
|
||||||
Mode,
|
Mode,
|
||||||
RollbackConfig,
|
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,
|
UpdateConfig,
|
||||||
...(StopGracePeriod !== undefined &&
|
...(StopGracePeriod !== undefined &&
|
||||||
StopGracePeriod !== null && { StopGracePeriod }),
|
StopGracePeriod !== null && { StopGracePeriod }),
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
calculateResources,
|
calculateResources,
|
||||||
generateBindMounts,
|
generateBindMounts,
|
||||||
generateConfigContainer,
|
generateConfigContainer,
|
||||||
generateEndpointSpec,
|
|
||||||
generateFileMounts,
|
generateFileMounts,
|
||||||
generateVolumeMounts,
|
generateVolumeMounts,
|
||||||
prepareEnvironmentVariables,
|
prepareEnvironmentVariables,
|
||||||
@@ -93,6 +92,7 @@ ${command ?? "wait $MONGOD_PID"}`;
|
|||||||
UpdateConfig,
|
UpdateConfig,
|
||||||
Networks,
|
Networks,
|
||||||
StopGracePeriod,
|
StopGracePeriod,
|
||||||
|
EndpointSpec,
|
||||||
} = generateConfigContainer(mongo);
|
} = generateConfigContainer(mongo);
|
||||||
|
|
||||||
const resources = calculateResources({
|
const resources = calculateResources({
|
||||||
@@ -143,7 +143,21 @@ ${command ?? "wait $MONGOD_PID"}`;
|
|||||||
},
|
},
|
||||||
Mode,
|
Mode,
|
||||||
RollbackConfig,
|
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,
|
UpdateConfig,
|
||||||
...(StopGracePeriod !== undefined &&
|
...(StopGracePeriod !== undefined &&
|
||||||
StopGracePeriod !== null && { StopGracePeriod }),
|
StopGracePeriod !== null && { StopGracePeriod }),
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
calculateResources,
|
calculateResources,
|
||||||
generateBindMounts,
|
generateBindMounts,
|
||||||
generateConfigContainer,
|
generateConfigContainer,
|
||||||
generateEndpointSpec,
|
|
||||||
generateFileMounts,
|
generateFileMounts,
|
||||||
generateVolumeMounts,
|
generateVolumeMounts,
|
||||||
prepareEnvironmentVariables,
|
prepareEnvironmentVariables,
|
||||||
@@ -53,6 +52,7 @@ export const buildMysql = async (mysql: MysqlNested) => {
|
|||||||
UpdateConfig,
|
UpdateConfig,
|
||||||
Networks,
|
Networks,
|
||||||
StopGracePeriod,
|
StopGracePeriod,
|
||||||
|
EndpointSpec,
|
||||||
} = generateConfigContainer(mysql);
|
} = generateConfigContainer(mysql);
|
||||||
const resources = calculateResources({
|
const resources = calculateResources({
|
||||||
memoryLimit,
|
memoryLimit,
|
||||||
@@ -96,7 +96,21 @@ export const buildMysql = async (mysql: MysqlNested) => {
|
|||||||
},
|
},
|
||||||
Mode,
|
Mode,
|
||||||
RollbackConfig,
|
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,
|
UpdateConfig,
|
||||||
...(StopGracePeriod !== undefined &&
|
...(StopGracePeriod !== undefined &&
|
||||||
StopGracePeriod !== null && { StopGracePeriod }),
|
StopGracePeriod !== null && { StopGracePeriod }),
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
calculateResources,
|
calculateResources,
|
||||||
generateBindMounts,
|
generateBindMounts,
|
||||||
generateConfigContainer,
|
generateConfigContainer,
|
||||||
generateEndpointSpec,
|
|
||||||
generateFileMounts,
|
generateFileMounts,
|
||||||
generateVolumeMounts,
|
generateVolumeMounts,
|
||||||
prepareEnvironmentVariables,
|
prepareEnvironmentVariables,
|
||||||
@@ -46,6 +45,7 @@ export const buildPostgres = async (postgres: PostgresNested) => {
|
|||||||
UpdateConfig,
|
UpdateConfig,
|
||||||
Networks,
|
Networks,
|
||||||
StopGracePeriod,
|
StopGracePeriod,
|
||||||
|
EndpointSpec,
|
||||||
} = generateConfigContainer(postgres);
|
} = generateConfigContainer(postgres);
|
||||||
const resources = calculateResources({
|
const resources = calculateResources({
|
||||||
memoryLimit,
|
memoryLimit,
|
||||||
@@ -89,7 +89,21 @@ export const buildPostgres = async (postgres: PostgresNested) => {
|
|||||||
},
|
},
|
||||||
Mode,
|
Mode,
|
||||||
RollbackConfig,
|
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,
|
UpdateConfig,
|
||||||
...(StopGracePeriod !== undefined &&
|
...(StopGracePeriod !== undefined &&
|
||||||
StopGracePeriod !== null && { StopGracePeriod }),
|
StopGracePeriod !== null && { StopGracePeriod }),
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
calculateResources,
|
calculateResources,
|
||||||
generateBindMounts,
|
generateBindMounts,
|
||||||
generateConfigContainer,
|
generateConfigContainer,
|
||||||
generateEndpointSpec,
|
|
||||||
generateFileMounts,
|
generateFileMounts,
|
||||||
generateVolumeMounts,
|
generateVolumeMounts,
|
||||||
prepareEnvironmentVariables,
|
prepareEnvironmentVariables,
|
||||||
@@ -44,6 +43,7 @@ export const buildRedis = async (redis: RedisNested) => {
|
|||||||
UpdateConfig,
|
UpdateConfig,
|
||||||
Networks,
|
Networks,
|
||||||
StopGracePeriod,
|
StopGracePeriod,
|
||||||
|
EndpointSpec,
|
||||||
} = generateConfigContainer(redis);
|
} = generateConfigContainer(redis);
|
||||||
const resources = calculateResources({
|
const resources = calculateResources({
|
||||||
memoryLimit,
|
memoryLimit,
|
||||||
@@ -86,7 +86,21 @@ export const buildRedis = async (redis: RedisNested) => {
|
|||||||
},
|
},
|
||||||
Mode,
|
Mode,
|
||||||
RollbackConfig,
|
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,
|
UpdateConfig,
|
||||||
...(StopGracePeriod !== undefined &&
|
...(StopGracePeriod !== undefined &&
|
||||||
StopGracePeriod !== null && { StopGracePeriod }),
|
StopGracePeriod !== null && { StopGracePeriod }),
|
||||||
|
|||||||
@@ -395,6 +395,7 @@ export const generateConfigContainer = (
|
|||||||
mounts,
|
mounts,
|
||||||
networkSwarm,
|
networkSwarm,
|
||||||
stopGracePeriodSwarm,
|
stopGracePeriodSwarm,
|
||||||
|
endpointSpecSwarm,
|
||||||
} = application;
|
} = application;
|
||||||
|
|
||||||
const sanitizedStopGracePeriodSwarm =
|
const sanitizedStopGracePeriodSwarm =
|
||||||
@@ -408,11 +409,9 @@ export const generateConfigContainer = (
|
|||||||
...(healthCheckSwarm && {
|
...(healthCheckSwarm && {
|
||||||
HealthCheck: healthCheckSwarm,
|
HealthCheck: healthCheckSwarm,
|
||||||
}),
|
}),
|
||||||
...(restartPolicySwarm
|
...(restartPolicySwarm && {
|
||||||
? {
|
RestartPolicy: restartPolicySwarm,
|
||||||
RestartPolicy: restartPolicySwarm,
|
}),
|
||||||
}
|
|
||||||
: {}),
|
|
||||||
...(placementSwarm
|
...(placementSwarm
|
||||||
? {
|
? {
|
||||||
Placement: placementSwarm,
|
Placement: placementSwarm,
|
||||||
@@ -461,42 +460,18 @@ export const generateConfigContainer = (
|
|||||||
: {
|
: {
|
||||||
Networks: [{ Target: "dokploy-network" }],
|
Networks: [{ Target: "dokploy-network" }],
|
||||||
}),
|
}),
|
||||||
};
|
...(endpointSpecSwarm && {
|
||||||
};
|
EndpointSpec: {
|
||||||
|
...(endpointSpecSwarm.Mode && { Mode: endpointSpecSwarm.Mode }),
|
||||||
export const generateEndpointSpec = (
|
Ports:
|
||||||
database: Partial<
|
endpointSpecSwarm.Ports?.map((port) => ({
|
||||||
PostgresNested | MysqlNested | MariadbNested | MongoNested | RedisNested
|
Protocol: (port.Protocol || "tcp") as "tcp" | "udp" | "sctp",
|
||||||
>,
|
TargetPort: port.TargetPort || 0,
|
||||||
defaultTargetPort: number,
|
PublishedPort: port.PublishedPort || 0,
|
||||||
) => {
|
PublishMode: (port.PublishMode || "host") as "ingress" | "host",
|
||||||
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,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: [],
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user