2022-02-10 15:47:44 +01:00
|
|
|
import { dev } from '$app/env';
|
|
|
|
import { asyncExecShell, getEngine } from '$lib/common';
|
|
|
|
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 () {
|
|
|
|
if (!dev) {
|
|
|
|
const destinationDockers = await prisma.destinationDocker.findMany();
|
|
|
|
for (const destinationDocker of destinationDockers) {
|
|
|
|
const host = getEngine(destinationDocker.engine);
|
2022-02-11 21:04:48 +01:00
|
|
|
// Tagging images with labels
|
2022-02-10 15:47:44 +01:00
|
|
|
try {
|
2022-02-11 21:04:48 +01:00
|
|
|
const images = [
|
|
|
|
`coollabsio/${defaultProxyImageTcp}`,
|
|
|
|
`coollabsio/${defaultProxyImageHttp}`,
|
|
|
|
'certbot/certbot:latest',
|
2022-02-11 21:06:48 +01:00
|
|
|
'alpine:latest',
|
|
|
|
'nginx:stable-alpine',
|
|
|
|
'node:lts',
|
|
|
|
'php:apache',
|
|
|
|
'rust:latest'
|
2022-02-11 21:04:48 +01:00
|
|
|
];
|
|
|
|
for (const image of images) {
|
|
|
|
await asyncExecShell(
|
|
|
|
`DOCKER_HOST=${host} docker pull ${image} && echo "FROM ${image}" | docker build --label coolify.managed="true" -t "${image}" -`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (error) {}
|
|
|
|
try {
|
|
|
|
await asyncExecShell(`DOCKER_HOST=${host} docker container prune -f`);
|
2022-02-10 15:47:44 +01:00
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
2022-02-11 21:04:48 +01:00
|
|
|
// Cleanup images that are not managed by coolify
|
2022-02-10 15:47:44 +01:00
|
|
|
try {
|
2022-02-11 21:04:48 +01:00
|
|
|
await asyncExecShell(
|
|
|
|
`DOCKER_HOST=${host} docker image prune --filter 'label!=coolify.managed=true' -a -f`
|
|
|
|
);
|
2022-02-10 15:47:44 +01:00
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|