mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(multi-server): add docker cleanup cron
This commit is contained in:
parent
82588f3e16
commit
ff482ffe28
@ -29,9 +29,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const SetupServer = ({ serverId }: Props) => {
|
export const SetupServer = ({ serverId }: Props) => {
|
||||||
const utils = api.useUtils();
|
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const url = useUrl();
|
|
||||||
const { data: server } = api.server.one.useQuery(
|
const { data: server } = api.server.one.useQuery(
|
||||||
{
|
{
|
||||||
serverId,
|
serverId,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { db } from "@/server/db";
|
import { db } from "@/server/db";
|
||||||
import { type apiCreateServer, server } from "@/server/db/schema";
|
import { type apiCreateServer, server } from "@/server/db/schema";
|
||||||
import { generatePassword } from "@/templates/utils";
|
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
|
||||||
@ -15,7 +14,6 @@ export const createServer = async (
|
|||||||
.values({
|
.values({
|
||||||
...input,
|
...input,
|
||||||
adminId: adminId,
|
adminId: adminId,
|
||||||
redisPassword: generatePassword(12),
|
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@ -72,3 +70,8 @@ export const updateServerById = async (
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getAllServers = async () => {
|
||||||
|
const servers = await db.query.server.findMany();
|
||||||
|
return servers;
|
||||||
|
};
|
||||||
|
@ -10,6 +10,7 @@ import { runMariadbBackup } from "./mariadb";
|
|||||||
import { runMongoBackup } from "./mongo";
|
import { runMongoBackup } from "./mongo";
|
||||||
import { runMySqlBackup } from "./mysql";
|
import { runMySqlBackup } from "./mysql";
|
||||||
import { runPostgresBackup } from "./postgres";
|
import { runPostgresBackup } from "./postgres";
|
||||||
|
import { getAllServers } from "@/server/api/services/server";
|
||||||
|
|
||||||
export const initCronJobs = async () => {
|
export const initCronJobs = async () => {
|
||||||
console.log("Setting up cron jobs....");
|
console.log("Setting up cron jobs....");
|
||||||
@ -27,6 +28,22 @@ export const initCronJobs = async () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const servers = await getAllServers();
|
||||||
|
|
||||||
|
for (const server of servers) {
|
||||||
|
const { appName, serverId } = server;
|
||||||
|
if (serverId) {
|
||||||
|
scheduleJob(serverId, "0 0 * * *", async () => {
|
||||||
|
console.log(
|
||||||
|
`SERVER-BACKUP[${new Date().toLocaleString()}] Running Cleanup ${appName}`,
|
||||||
|
);
|
||||||
|
await cleanUpUnusedImages(serverId);
|
||||||
|
await cleanUpDockerBuilder(serverId);
|
||||||
|
await cleanUpSystemPrune(serverId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const pgs = await db.query.postgres.findMany({
|
const pgs = await db.query.postgres.findMany({
|
||||||
with: {
|
with: {
|
||||||
backups: {
|
backups: {
|
||||||
|
Loading…
Reference in New Issue
Block a user