Skip to content

Commit e6fc3db

Browse files
fix: add docker cleanup toggle to remote server creation (Dokploy#4559)
* fix: add docker cleanup toggle to remote server creation and update forms * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 57ef96a commit e6fc3db

5 files changed

Lines changed: 108 additions & 5 deletions

File tree

‎apps/dokploy/components/dashboard/application/advanced/cluster/swarm-forms/health-check-form.tsx‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,12 @@ export const HealthCheckForm = ({ id, type }: HealthCheckFormProps) => {
200200
Time between health checks (e.g., 10000000000 for 10 seconds)
201201
</FormDescription>
202202
<FormControl>
203-
<Input type="number" placeholder="10000000000" {...field} value={field.value ?? ""} />
203+
<Input
204+
type="number"
205+
placeholder="10000000000"
206+
{...field}
207+
value={field.value ?? ""}
208+
/>
204209
</FormControl>
205210
<FormMessage />
206211
</FormItem>
@@ -217,7 +222,12 @@ export const HealthCheckForm = ({ id, type }: HealthCheckFormProps) => {
217222
Maximum time to wait for health check response
218223
</FormDescription>
219224
<FormControl>
220-
<Input type="number" placeholder="10000000000" {...field} value={field.value ?? ""} />
225+
<Input
226+
type="number"
227+
placeholder="10000000000"
228+
{...field}
229+
value={field.value ?? ""}
230+
/>
221231
</FormControl>
222232
<FormMessage />
223233
</FormItem>
@@ -234,7 +244,12 @@ export const HealthCheckForm = ({ id, type }: HealthCheckFormProps) => {
234244
Initial grace period before health checks begin
235245
</FormDescription>
236246
<FormControl>
237-
<Input type="number" placeholder="10000000000" {...field} value={field.value ?? ""} />
247+
<Input
248+
type="number"
249+
placeholder="10000000000"
250+
{...field}
251+
value={field.value ?? ""}
252+
/>
238253
</FormControl>
239254
<FormMessage />
240255
</FormItem>
@@ -252,7 +267,12 @@ export const HealthCheckForm = ({ id, type }: HealthCheckFormProps) => {
252267
unhealthy
253268
</FormDescription>
254269
<FormControl>
255-
<Input type="number" placeholder="3" {...field} value={field.value ?? ""} />
270+
<Input
271+
type="number"
272+
placeholder="3"
273+
{...field}
274+
value={field.value ?? ""}
275+
/>
256276
</FormControl>
257277
<FormMessage />
258278
</FormItem>

‎apps/dokploy/components/dashboard/settings/servers/handle-servers.tsx‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
SelectTrigger,
3737
SelectValue,
3838
} from "@/components/ui/select";
39+
import { Switch } from "@/components/ui/switch";
3940
import { Textarea } from "@/components/ui/textarea";
4041
import { api } from "@/utils/api";
4142

@@ -53,6 +54,7 @@ const Schema = z.object({
5354
message: "SSH Key is required",
5455
}),
5556
serverType: z.enum(["deploy", "build"]).default("deploy"),
57+
enableDockerCleanup: z.boolean().default(true),
5658
});
5759

5860
type Schema = z.infer<typeof Schema>;
@@ -90,6 +92,7 @@ export const HandleServers = ({ serverId, asButton = false }: Props) => {
9092
username: "root",
9193
sshKeyId: "",
9294
serverType: "deploy",
95+
enableDockerCleanup: true,
9396
},
9497
resolver: zodResolver(Schema),
9598
});
@@ -103,6 +106,7 @@ export const HandleServers = ({ serverId, asButton = false }: Props) => {
103106
username: data?.username || "root",
104107
sshKeyId: data?.sshKeyId || "",
105108
serverType: data?.serverType || "deploy",
109+
enableDockerCleanup: data?.enableDockerCleanup ?? true,
106110
});
107111
}, [form, form.reset, form.formState.isSubmitSuccessful, data]);
108112

@@ -119,6 +123,7 @@ export const HandleServers = ({ serverId, asButton = false }: Props) => {
119123
username: data.username || "root",
120124
sshKeyId: data.sshKeyId || "",
121125
serverType: data.serverType || "deploy",
126+
enableDockerCleanup: data.enableDockerCleanup,
122127
serverId: serverId || "",
123128
})
124129
.then(async (_data) => {
@@ -418,6 +423,27 @@ export const HandleServers = ({ serverId, asButton = false }: Props) => {
418423
</FormItem>
419424
)}
420425
/>
426+
<FormField
427+
control={form.control}
428+
name="enableDockerCleanup"
429+
render={({ field }) => (
430+
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-3">
431+
<div className="space-y-0.5">
432+
<FormLabel>Enable Docker Cleanup</FormLabel>
433+
<FormDescription>
434+
Automatically prune unused Docker images daily. Keeps disk
435+
usage in check on this remote server.
436+
</FormDescription>
437+
</div>
438+
<FormControl>
439+
<Switch
440+
checked={field.value}
441+
onCheckedChange={field.onChange}
442+
/>
443+
</FormControl>
444+
</FormItem>
445+
)}
446+
/>
421447
</form>
422448

423449
<DialogFooter>

‎apps/dokploy/server/api/routers/server.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
redis,
4646
server,
4747
} from "@/server/db/schema";
48+
import { applyDockerCleanupSchedule } from "@/server/utils/docker-cleanup";
4849

4950
export const serverRouter = createTRPCRouter({
5051
create: withPermission("server", "create")
@@ -63,6 +64,11 @@ export const serverRouter = createTRPCRouter({
6364
input,
6465
ctx.session.activeOrganizationId,
6566
);
67+
await applyDockerCleanupSchedule(
68+
project.serverId,
69+
ctx.session.activeOrganizationId,
70+
input.enableDockerCleanup,
71+
);
6672
await audit(ctx, {
6773
action: "create",
6874
resourceType: "server",
@@ -456,6 +462,12 @@ export const serverRouter = createTRPCRouter({
456462
...input,
457463
});
458464

465+
await applyDockerCleanupSchedule(
466+
input.serverId,
467+
ctx.session.activeOrganizationId,
468+
input.enableDockerCleanup,
469+
);
470+
459471
await audit(ctx, {
460472
action: "update",
461473
resourceType: "server",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {
2+
CLEANUP_CRON_JOB,
3+
cleanupAll,
4+
IS_CLOUD,
5+
sendDockerCleanupNotifications,
6+
} from "@dokploy/server";
7+
import { scheduledJobs, scheduleJob } from "node-schedule";
8+
import { removeJob, schedule } from "./backup";
9+
10+
export const applyDockerCleanupSchedule = async (
11+
serverId: string,
12+
organizationId: string,
13+
enable: boolean,
14+
) => {
15+
if (enable) {
16+
if (IS_CLOUD) {
17+
await schedule({
18+
cronSchedule: CLEANUP_CRON_JOB,
19+
serverId,
20+
type: "server",
21+
});
22+
} else {
23+
scheduleJob(serverId, CLEANUP_CRON_JOB, async () => {
24+
await cleanupAll(serverId);
25+
await sendDockerCleanupNotifications(organizationId);
26+
});
27+
}
28+
} else {
29+
if (IS_CLOUD) {
30+
await removeJob({
31+
cronSchedule: CLEANUP_CRON_JOB,
32+
serverId,
33+
type: "server",
34+
});
35+
} else {
36+
scheduledJobs[serverId]?.cancel();
37+
}
38+
}
39+
};

‎packages/server/src/db/schema/server.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,12 @@ export const apiCreateServer = createSchema
147147
username: true,
148148
sshKeyId: true,
149149
serverType: true,
150+
enableDockerCleanup: true,
150151
})
151-
.required();
152+
.required()
153+
.extend({
154+
enableDockerCleanup: z.boolean().default(true),
155+
});
152156

153157
export const apiFindOneServer = z.object({
154158
serverId: z.string().min(1),
@@ -170,10 +174,12 @@ export const apiUpdateServer = createSchema
170174
username: true,
171175
sshKeyId: true,
172176
serverType: true,
177+
enableDockerCleanup: true,
173178
})
174179
.required()
175180
.extend({
176181
command: z.string().optional(),
182+
enableDockerCleanup: z.boolean().default(true),
177183
});
178184

179185
export const apiUpdateServerMonitoring = createSchema

0 commit comments

Comments
 (0)