72 lines
2.2 KiB
TypeScript
Raw Normal View History

2022-02-10 15:47:44 +01:00
import { dev } from '$app/env';
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-02-11 21:04:48 +01:00
import { defaultProxyImageHttp, defaultProxyImageTcp } from '$lib/haproxy';
2022-02-10 15:47:44 +01:00
export default async function () {
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) {
await asyncExecShell(`DOCKER_HOST=${host} docker rmi ${images}`);
}
2022-03-02 14:53:43 +01:00
} catch (error) {
console.log(error);
}
try {
await asyncExecShell(`DOCKER_HOST=${host} docker container prune -f`);
} catch (error) {
console.log(error);
}
try {
await asyncExecShell(`DOCKER_HOST=${host} docker image prune -f`);
} catch (error) {
console.log(error);
}
2022-02-24 10:11:48 +01:00
// Tagging images with labels
2022-03-01 11:10:10 +01:00
// try {
// const images = [
// `coollabsio/${defaultProxyImageTcp}`,
// `coollabsio/${defaultProxyImageHttp}`,
// 'certbot/certbot:latest',
// 'node:16.14.0-alpine',
// 'alpine:latest',
// 'nginx:stable-alpine',
// 'node:lts',
// 'php:apache',
// 'rust:latest'
// ];
// for (const image of images) {
// try {
// await asyncExecShell(`DOCKER_HOST=${host} docker image inspect ${image}`);
// } catch (error) {
// await asyncExecShell(
// `DOCKER_HOST=${host} docker pull ${image} && echo "FROM ${image}" | docker build --label coolify.image="true" -t "${image}" -`
// );
// }
// }
// } catch (error) {}
// if (!dev) {
// // Cleanup images that are not managed by coolify
// try {
// await asyncExecShell(
// `DOCKER_HOST=${host} docker image prune --filter 'label!=coolify.image=true' -a -f`
// );
// } catch (error) {
// console.log(error);
// }
// // Cleanup old images >3 days
// try {
// await asyncExecShell(`DOCKER_HOST=${host} docker image prune --filter "until=72h" -a -f`);
// } catch (error) {
// console.log(error);
// }
// }
2022-02-10 15:47:44 +01:00
}
}