mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: prettify json of each setting
This commit is contained in:
@@ -166,6 +166,84 @@ export const applicationsRelations = relations(
|
||||
}),
|
||||
);
|
||||
|
||||
const HealthCheckSwarmSchema = z
|
||||
.object({
|
||||
Test: z.array(z.string()).optional(),
|
||||
Interval: z.number().optional(),
|
||||
Timeout: z.number().optional(),
|
||||
StartPeriod: z.number().optional(),
|
||||
Retries: z.number().optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const RestartPolicySwarmSchema = z
|
||||
.object({
|
||||
Condition: z.string().optional(),
|
||||
Delay: z.number().optional(),
|
||||
MaxAttempts: z.number().optional(),
|
||||
Window: z.number().optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const PreferenceSchema = z
|
||||
.object({
|
||||
Spread: z.object({
|
||||
SpreadDescriptor: z.string(),
|
||||
}),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const PlatformSchema = z
|
||||
.object({
|
||||
Architecture: z.string(),
|
||||
OS: z.string(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const PlacementSwarmSchema = z
|
||||
.object({
|
||||
Constraints: z.array(z.string()).optional(),
|
||||
Preferences: z.array(PreferenceSchema).optional(),
|
||||
MaxReplicas: z.number().optional(),
|
||||
Platforms: z.array(PlatformSchema).optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const UpdateConfigSwarmSchema = z
|
||||
.object({
|
||||
Parallelism: z.number(),
|
||||
Delay: z.number().optional(),
|
||||
FailureAction: z.string().optional(),
|
||||
Monitor: z.number().optional(),
|
||||
MaxFailureRatio: z.number().optional(),
|
||||
Order: z.string(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const ReplicatedSchema = z
|
||||
.object({
|
||||
Replicas: z.number().optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const ReplicatedJobSchema = z
|
||||
.object({
|
||||
MaxConcurrent: z.number().optional(),
|
||||
TotalCompletions: z.number().optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const ServiceModeSwarmSchema = z
|
||||
.object({
|
||||
Replicated: ReplicatedSchema.optional(),
|
||||
Global: z.object({}).optional(),
|
||||
ReplicatedJob: ReplicatedJobSchema.optional(),
|
||||
GlobalJob: z.object({}).optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
const LabelsSwarmSchema = z.record(z.string());
|
||||
|
||||
const createSchema = createInsertSchema(applications, {
|
||||
appName: z.string(),
|
||||
createdAt: z.string(),
|
||||
@@ -202,6 +280,68 @@ const createSchema = createInsertSchema(applications, {
|
||||
"nixpacks",
|
||||
]),
|
||||
owner: z.string(),
|
||||
healthCheckSwarm: HealthCheckSwarmSchema.nullable(),
|
||||
restartPolicySwarm: RestartPolicySwarmSchema.nullable(),
|
||||
placementSwarm: PlacementSwarmSchema.nullable(),
|
||||
updateConfigSwarm: UpdateConfigSwarmSchema.nullable(),
|
||||
rollbackConfigSwarm: UpdateConfigSwarmSchema.nullable(),
|
||||
modeSwarm: ServiceModeSwarmSchema.nullable(),
|
||||
labelsSwarm: LabelsSwarmSchema.nullable(),
|
||||
// restartPolicySwarm: z
|
||||
// .object({
|
||||
// Condition: z.string().optional(),
|
||||
// Delay: z.number().optional(),
|
||||
// MaxAttempts: z.number().optional(),
|
||||
// Window: z.number().optional(),
|
||||
// })
|
||||
// .strict()
|
||||
// .nullable(),
|
||||
// placementSwarm: z
|
||||
// .object({
|
||||
// Constraints: z.array(z.string()).optional(),
|
||||
// Preferences: z.array(PreferenceSchema).optional(),
|
||||
// MaxReplicas: z.number().optional(),
|
||||
// Platforms: z.array(PlatformSchema).optional(),
|
||||
// })
|
||||
// .strict()
|
||||
// .nullable(),
|
||||
// updateConfigSwarm: z
|
||||
// .object({
|
||||
// Parallelism: z.number(),
|
||||
// Delay: z.number().optional(),
|
||||
// FailureAction: z.string().optional(),
|
||||
// Monitor: z.number().optional(),
|
||||
// MaxFailureRatio: z.number().optional(),
|
||||
// Order: z.string(),
|
||||
// })
|
||||
// .strict()
|
||||
// .nullable(),
|
||||
// rollbackConfigSwarm: z
|
||||
// .object({
|
||||
// Parallelism: z.number(),
|
||||
// Delay: z.number().optional(),
|
||||
// FailureAction: z.string().optional(),
|
||||
// Monitor: z.number().optional(),
|
||||
// MaxFailureRatio: z.number().optional(),
|
||||
// Order: z.string(),
|
||||
// })
|
||||
// .strict()
|
||||
// .nullable(),
|
||||
// modeSwarm: z
|
||||
// .object({
|
||||
// Replicated: ReplicatedSchema.optional(),
|
||||
// Global: z.object({}).optional(),
|
||||
// ReplicatedJob: ReplicatedJobSchema.optional(),
|
||||
// GlobalJob: z.object({}).optional(),
|
||||
// })
|
||||
// .strict()
|
||||
// .nullable(),
|
||||
// labelsSwarm: z
|
||||
// .object({
|
||||
|
||||
// })
|
||||
// .strict()
|
||||
// .nullable(),
|
||||
});
|
||||
|
||||
export const apiCreateApplication = createSchema.pick({
|
||||
|
||||
@@ -100,8 +100,6 @@ export const mechanizeDockerContainer = async (
|
||||
|
||||
const registry = application.registry;
|
||||
|
||||
console.log(Labels);
|
||||
|
||||
let image =
|
||||
sourceType === "docker"
|
||||
? dockerImage || "ERROR-NO-IMAGE-PROVIDED"
|
||||
@@ -139,7 +137,6 @@ export const mechanizeDockerContainer = async (
|
||||
Networks: [{ Target: "dokploy-network" }],
|
||||
RestartPolicy,
|
||||
Placement,
|
||||
|
||||
Resources: {
|
||||
...resources,
|
||||
},
|
||||
|
||||
@@ -200,30 +200,17 @@ export const calculateResources = ({
|
||||
};
|
||||
|
||||
export const generateConfigContainer = (application: ApplicationNested) => {
|
||||
const { replicas, mounts } = application;
|
||||
|
||||
const healthCheckSwarm = JSON.parse(
|
||||
(application.healthCheckSwarm as string) || "{}",
|
||||
);
|
||||
const restartPolicySwarm = JSON.parse(
|
||||
(application.restartPolicySwarm as string) || "{}",
|
||||
);
|
||||
const placementSwarm = JSON.parse(
|
||||
(application.placementSwarm as string) || "{}",
|
||||
);
|
||||
|
||||
const updateConfigSwarm = JSON.parse(
|
||||
(application.updateConfigSwarm as unknown as string) || "{}",
|
||||
);
|
||||
|
||||
const rollbackConfigSwarm = JSON.parse(
|
||||
(application.rollbackConfigSwarm as unknown as string) || "{}",
|
||||
);
|
||||
const modeSwarm = JSON.parse((application.modeSwarm as string) || "{}");
|
||||
|
||||
const labelsSwarm = JSON.parse(
|
||||
(application.labelsSwarm as unknown as string) || "{}",
|
||||
);
|
||||
const {
|
||||
healthCheckSwarm,
|
||||
restartPolicySwarm,
|
||||
placementSwarm,
|
||||
updateConfigSwarm,
|
||||
rollbackConfigSwarm,
|
||||
modeSwarm,
|
||||
labelsSwarm,
|
||||
replicas,
|
||||
mounts,
|
||||
} = application;
|
||||
|
||||
const haveMounts = mounts.length > 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user