37 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-03-02 14:53:43 +01:00
import { asyncExecShell, getEngine, version } from '$lib/common';
2022-02-10 15:47:44 +01:00
import { prisma } from '$lib/database';
2022-04-06 21:01:47 +02:00
export default async function (): Promise<void> {
2022-02-24 10:11:48 +01:00
const destinationDockers = await prisma.destinationDocker.findMany();
for (const destinationDocker of destinationDockers) {
const host = getEngine(destinationDocker.engine);
2022-03-02 15:52:06 +01:00
// Cleanup old coolify images
2022-03-02 14:53:43 +01:00
try {
2022-03-02 20:57:28 +01:00
let { stdout: images } = await asyncExecShell(
2022-03-02 21:08:36 +01:00
`DOCKER_HOST=${host} docker images coollabsio/coolify --filter before="coollabsio/coolify:${version}" -q | xargs `
2022-03-02 14:53:43 +01:00
);
2022-03-02 20:57:28 +01:00
images = images.trim();
2022-03-02 15:52:06 +01:00
if (images) {
2022-03-02 21:14:53 +01:00
await asyncExecShell(`DOCKER_HOST=${host} docker rmi -f ${images}`);
2022-03-02 15:52:06 +01:00
}
2022-03-02 14:53:43 +01:00
} catch (error) {
2022-04-12 20:57:49 +02:00
//console.log(error);
2022-03-02 14:53:43 +01:00
}
try {
await asyncExecShell(`DOCKER_HOST=${host} docker container prune -f`);
} catch (error) {
2022-04-12 20:57:49 +02:00
//console.log(error);
2022-03-02 14:53:43 +01:00
}
try {
2022-03-25 15:34:14 +01:00
await asyncExecShell(`DOCKER_HOST=${host} docker image prune -f --filter "until=2h"`);
2022-03-02 14:53:43 +01:00
} catch (error) {
2022-04-12 20:57:49 +02:00
//console.log(error);
}
// Cleanup old images older than a day
try {
await asyncExecShell(`DOCKER_HOST=${host} docker image prune --filter "until=24h" -a -f`);
} catch (error) {
//console.log(error);
2022-03-02 14:53:43 +01:00
}
2022-02-10 15:47:44 +01:00
}
}