mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat: add network swarm json
This commit is contained in:
@@ -109,6 +109,16 @@ const ServiceModeSwarmSchema = z
|
|||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
|
const NetworkSwarmSchema = z.array(
|
||||||
|
z
|
||||||
|
.object({
|
||||||
|
Target: z.string().optional(),
|
||||||
|
Aliases: z.array(z.string()).optional(),
|
||||||
|
DriverOpts: z.object({}).optional(),
|
||||||
|
})
|
||||||
|
.strict(),
|
||||||
|
);
|
||||||
|
|
||||||
const LabelsSwarmSchema = z.record(z.string());
|
const LabelsSwarmSchema = z.record(z.string());
|
||||||
|
|
||||||
const createStringToJSONSchema = (schema: z.ZodTypeAny) => {
|
const createStringToJSONSchema = (schema: z.ZodTypeAny) => {
|
||||||
@@ -165,6 +175,7 @@ const addSwarmSettings = z.object({
|
|||||||
).nullable(),
|
).nullable(),
|
||||||
modeSwarm: createStringToJSONSchema(ServiceModeSwarmSchema).nullable(),
|
modeSwarm: createStringToJSONSchema(ServiceModeSwarmSchema).nullable(),
|
||||||
labelsSwarm: createStringToJSONSchema(LabelsSwarmSchema).nullable(),
|
labelsSwarm: createStringToJSONSchema(LabelsSwarmSchema).nullable(),
|
||||||
|
networkSwarm: createStringToJSONSchema(NetworkSwarmSchema).nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
type AddSwarmSettings = z.infer<typeof addSwarmSettings>;
|
type AddSwarmSettings = z.infer<typeof addSwarmSettings>;
|
||||||
@@ -195,6 +206,7 @@ export const AddSwarmSettings = ({ applicationId }: Props) => {
|
|||||||
rollbackConfigSwarm: null,
|
rollbackConfigSwarm: null,
|
||||||
modeSwarm: null,
|
modeSwarm: null,
|
||||||
labelsSwarm: null,
|
labelsSwarm: null,
|
||||||
|
networkSwarm: null,
|
||||||
},
|
},
|
||||||
resolver: zodResolver(addSwarmSettings),
|
resolver: zodResolver(addSwarmSettings),
|
||||||
});
|
});
|
||||||
@@ -223,6 +235,9 @@ export const AddSwarmSettings = ({ applicationId }: Props) => {
|
|||||||
labelsSwarm: data.labelsSwarm
|
labelsSwarm: data.labelsSwarm
|
||||||
? JSON.stringify(data.labelsSwarm, null, 2)
|
? JSON.stringify(data.labelsSwarm, null, 2)
|
||||||
: null,
|
: null,
|
||||||
|
networkSwarm: data.networkSwarm
|
||||||
|
? JSON.stringify(data.networkSwarm, null, 2)
|
||||||
|
: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [form, form.reset, data]);
|
}, [form, form.reset, data]);
|
||||||
@@ -237,6 +252,7 @@ export const AddSwarmSettings = ({ applicationId }: Props) => {
|
|||||||
rollbackConfigSwarm: data.rollbackConfigSwarm,
|
rollbackConfigSwarm: data.rollbackConfigSwarm,
|
||||||
modeSwarm: data.modeSwarm,
|
modeSwarm: data.modeSwarm,
|
||||||
labelsSwarm: data.labelsSwarm,
|
labelsSwarm: data.labelsSwarm,
|
||||||
|
networkSwarm: data.networkSwarm,
|
||||||
})
|
})
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
toast.success("Swarm settings updated");
|
toast.success("Swarm settings updated");
|
||||||
@@ -618,12 +634,69 @@ export const AddSwarmSettings = ({ applicationId }: Props) => {
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="networkSwarm"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem className="relative max-lg:px-4 lg:pl-6 ">
|
||||||
|
<FormLabel>Network</FormLabel>
|
||||||
|
<TooltipProvider delayDuration={0}>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<FormDescription className="break-all w-fit flex flex-row gap-1 items-center">
|
||||||
|
Check the interface
|
||||||
|
<HelpCircle className="size-4 text-muted-foreground" />
|
||||||
|
</FormDescription>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent
|
||||||
|
className="w-full z-[999]"
|
||||||
|
align="start"
|
||||||
|
side="bottom"
|
||||||
|
>
|
||||||
|
<code>
|
||||||
|
<pre>
|
||||||
|
{`[
|
||||||
|
{
|
||||||
|
"Target" : string | undefined;
|
||||||
|
"Aliases" : string[] | undefined;
|
||||||
|
"DriverOpts" : { [key: string]: string } | undefined;
|
||||||
|
}
|
||||||
|
]`}
|
||||||
|
</pre>
|
||||||
|
</code>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
<FormControl>
|
||||||
|
<Textarea
|
||||||
|
className="font-mono [field-sizing:content;] min-h-[18.5rem]"
|
||||||
|
placeholder={`[
|
||||||
|
{
|
||||||
|
"Target" : "dokploy-network",
|
||||||
|
"Aliases" : ["dokploy-network"],
|
||||||
|
"DriverOpts" : {
|
||||||
|
"com.docker.network.driver.mtu" : "1500",
|
||||||
|
"com.docker.network.driver.host_binding" : "true",
|
||||||
|
"com.docker.network.driver.mtu" : "1500",
|
||||||
|
"com.docker.network.driver.host_binding" : "true"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]`}
|
||||||
|
{...field}
|
||||||
|
value={field?.value || ""}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<pre>
|
||||||
|
<FormMessage />
|
||||||
|
</pre>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="labelsSwarm"
|
name="labelsSwarm"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem className="relative max-lg:px-4 lg:pl-6 ">
|
<FormItem className="relative max-lg:px-4 lg:pr-6 ">
|
||||||
<FormLabel>Labels</FormLabel>
|
<FormLabel>Labels</FormLabel>
|
||||||
<TooltipProvider delayDuration={0}>
|
<TooltipProvider delayDuration={0}>
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
@@ -650,7 +723,7 @@ export const AddSwarmSettings = ({ applicationId }: Props) => {
|
|||||||
</TooltipProvider>
|
</TooltipProvider>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Textarea
|
<Textarea
|
||||||
className="font-mono [field-sizing:content;]"
|
className="font-mono [field-sizing:content;] min-h-[18.5rem]"
|
||||||
placeholder={`{
|
placeholder={`{
|
||||||
"com.example.app.name" : "my-app",
|
"com.example.app.name" : "my-app",
|
||||||
"com.example.app.version" : "1.0.0"
|
"com.example.app.version" : "1.0.0"
|
||||||
|
|||||||
1
drizzle/0013_blushing_starjammers.sql
Normal file
1
drizzle/0013_blushing_starjammers.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "application" ADD COLUMN "networkSwarm" json;
|
||||||
2392
drizzle/meta/0013_snapshot.json
Normal file
2392
drizzle/meta/0013_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -92,6 +92,13 @@
|
|||||||
"when": 1716015716708,
|
"when": 1716015716708,
|
||||||
"tag": "0012_chubby_umar",
|
"tag": "0012_chubby_umar",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 13,
|
||||||
|
"version": "6",
|
||||||
|
"when": 1716076179443,
|
||||||
|
"tag": "0013_blushing_starjammers",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -79,6 +79,12 @@ interface ServiceModeSwarm {
|
|||||||
GlobalJob?: {} | undefined;
|
GlobalJob?: {} | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface NetworkSwarm {
|
||||||
|
Target?: string | undefined;
|
||||||
|
Aliases?: string[] | undefined;
|
||||||
|
DriverOpts?: { [key: string]: string } | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
interface LabelsSwarm {
|
interface LabelsSwarm {
|
||||||
[name: string]: string;
|
[name: string]: string;
|
||||||
}
|
}
|
||||||
@@ -129,6 +135,7 @@ export const applications = pgTable("application", {
|
|||||||
rollbackConfigSwarm: json("rollbackConfigSwarm").$type<UpdateConfigSwarm>(),
|
rollbackConfigSwarm: json("rollbackConfigSwarm").$type<UpdateConfigSwarm>(),
|
||||||
modeSwarm: json("modeSwarm").$type<ServiceModeSwarm>(),
|
modeSwarm: json("modeSwarm").$type<ServiceModeSwarm>(),
|
||||||
labelsSwarm: json("labelsSwarm").$type<LabelsSwarm>(),
|
labelsSwarm: json("labelsSwarm").$type<LabelsSwarm>(),
|
||||||
|
networkSwarm: json("networkSwarm").$type<NetworkSwarm[]>(),
|
||||||
//
|
//
|
||||||
replicas: integer("replicas").default(1).notNull(),
|
replicas: integer("replicas").default(1).notNull(),
|
||||||
applicationStatus: applicationStatus("applicationStatus")
|
applicationStatus: applicationStatus("applicationStatus")
|
||||||
@@ -242,6 +249,16 @@ const ServiceModeSwarmSchema = z
|
|||||||
})
|
})
|
||||||
.strict();
|
.strict();
|
||||||
|
|
||||||
|
const NetworkSwarmSchema = z.array(
|
||||||
|
z
|
||||||
|
.object({
|
||||||
|
Target: z.string().optional(),
|
||||||
|
Aliases: z.array(z.string()).optional(),
|
||||||
|
DriverOpts: z.object({}).optional(),
|
||||||
|
})
|
||||||
|
.strict(),
|
||||||
|
);
|
||||||
|
|
||||||
const LabelsSwarmSchema = z.record(z.string());
|
const LabelsSwarmSchema = z.record(z.string());
|
||||||
|
|
||||||
const createSchema = createInsertSchema(applications, {
|
const createSchema = createInsertSchema(applications, {
|
||||||
@@ -287,61 +304,7 @@ const createSchema = createInsertSchema(applications, {
|
|||||||
rollbackConfigSwarm: UpdateConfigSwarmSchema.nullable(),
|
rollbackConfigSwarm: UpdateConfigSwarmSchema.nullable(),
|
||||||
modeSwarm: ServiceModeSwarmSchema.nullable(),
|
modeSwarm: ServiceModeSwarmSchema.nullable(),
|
||||||
labelsSwarm: LabelsSwarmSchema.nullable(),
|
labelsSwarm: LabelsSwarmSchema.nullable(),
|
||||||
// restartPolicySwarm: z
|
networkSwarm: NetworkSwarmSchema.nullable(),
|
||||||
// .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({
|
export const apiCreateApplication = createSchema.pick({
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ export const mechanizeDockerContainer = async (
|
|||||||
cpuReservation,
|
cpuReservation,
|
||||||
command,
|
command,
|
||||||
ports,
|
ports,
|
||||||
|
networkSwarm,
|
||||||
} = application;
|
} = application;
|
||||||
|
|
||||||
const resources = calculateResources({
|
const resources = calculateResources({
|
||||||
@@ -92,6 +93,7 @@ export const mechanizeDockerContainer = async (
|
|||||||
Mode,
|
Mode,
|
||||||
RollbackConfig,
|
RollbackConfig,
|
||||||
UpdateConfig,
|
UpdateConfig,
|
||||||
|
Networks,
|
||||||
} = generateConfigContainer(application);
|
} = generateConfigContainer(application);
|
||||||
|
|
||||||
const bindsMount = generateBindMounts(mounts);
|
const bindsMount = generateBindMounts(mounts);
|
||||||
@@ -134,7 +136,7 @@ export const mechanizeDockerContainer = async (
|
|||||||
: {}),
|
: {}),
|
||||||
Labels,
|
Labels,
|
||||||
},
|
},
|
||||||
Networks: [{ Target: "dokploy-network" }],
|
Networks,
|
||||||
RestartPolicy,
|
RestartPolicy,
|
||||||
Placement,
|
Placement,
|
||||||
Resources: {
|
Resources: {
|
||||||
|
|||||||
@@ -210,6 +210,7 @@ export const generateConfigContainer = (application: ApplicationNested) => {
|
|||||||
labelsSwarm,
|
labelsSwarm,
|
||||||
replicas,
|
replicas,
|
||||||
mounts,
|
mounts,
|
||||||
|
networkSwarm,
|
||||||
} = application;
|
} = application;
|
||||||
|
|
||||||
const haveMounts = mounts.length > 0;
|
const haveMounts = mounts.length > 0;
|
||||||
@@ -265,6 +266,13 @@ export const generateConfigContainer = (application: ApplicationNested) => {
|
|||||||
Order: "start-first",
|
Order: "start-first",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
...(networkSwarm
|
||||||
|
? {
|
||||||
|
Networks: networkSwarm,
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
Networks: [{ Target: "dokploy-network" }],
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user