fix: cleanupStorage
This commit is contained in:
@@ -1,20 +1,21 @@
|
|||||||
import { parentPort } from 'node:worker_threads';
|
import { parentPort } from 'node:worker_threads';
|
||||||
import { asyncExecShell, cleanupDockerStorage, isDev, prisma, version } from '../lib/common';
|
import { asyncExecShell, cleanupDockerStorage, executeDockerCmd, isDev, prisma, version } from '../lib/common';
|
||||||
import { getEngine } from '../lib/docker';
|
import { getEngine } from '../lib/docker';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
if (parentPort) {
|
if (parentPort) {
|
||||||
const destinationDockers = await prisma.destinationDocker.findMany();
|
const destinationDockers = await prisma.destinationDocker.findMany();
|
||||||
const engines = [...new Set(destinationDockers.map(({ engine }) => engine))];
|
let enginesDone = new Set()
|
||||||
for (const engine of engines) {
|
for (const destination of destinationDockers) {
|
||||||
|
if (enginesDone.has(destination.engine) || enginesDone.has(destination.remoteIpAddress)) return
|
||||||
|
if (destination.engine) enginesDone.add(destination.engine)
|
||||||
|
if (destination.remoteIpAddress) enginesDone.add(destination.remoteIpAddress)
|
||||||
|
|
||||||
let lowDiskSpace = false;
|
let lowDiskSpace = false;
|
||||||
const host = getEngine(engine);
|
|
||||||
try {
|
try {
|
||||||
let stdout = null
|
let stdout = null
|
||||||
if (!isDev) {
|
if (!isDev) {
|
||||||
const output = await asyncExecShell(
|
const output = await executeDockerCmd({ dockerId: destination.id, command: `docker exec coolify sh -c 'df -kPT /'` })
|
||||||
`DOCKER_HOST=${host} docker exec coolify sh -c 'df -kPT /'`
|
|
||||||
);
|
|
||||||
stdout = output.stdout;
|
stdout = output.stdout;
|
||||||
} else {
|
} else {
|
||||||
const output = await asyncExecShell(
|
const output = await asyncExecShell(
|
||||||
@@ -53,7 +54,7 @@ import { getEngine } from '../lib/docker';
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
await cleanupDockerStorage(host, lowDiskSpace, false)
|
await cleanupDockerStorage(destination.id, lowDiskSpace, false)
|
||||||
}
|
}
|
||||||
await prisma.$disconnect();
|
await prisma.$disconnect();
|
||||||
} else process.exit(0);
|
} else process.exit(0);
|
||||||
|
@@ -1530,15 +1530,14 @@ export function convertTolOldVolumeNames(type) {
|
|||||||
// const { data } = await axios.get(`https://gist.githubusercontent.com/andrasbacsai/4aac36d8d6214dbfc34fa78110554a50/raw/5b27e6c37d78aaeedc1148d797112c827a2f43cf/availableServices.json`)
|
// const { data } = await axios.get(`https://gist.githubusercontent.com/andrasbacsai/4aac36d8d6214dbfc34fa78110554a50/raw/5b27e6c37d78aaeedc1148d797112c827a2f43cf/availableServices.json`)
|
||||||
// return data
|
// return data
|
||||||
// }
|
// }
|
||||||
export async function cleanupDockerStorage(host, lowDiskSpace, force) {
|
export async function cleanupDockerStorage(dockerId, lowDiskSpace, force) {
|
||||||
// Cleanup old coolify images
|
// Cleanup old coolify images
|
||||||
try {
|
try {
|
||||||
let { stdout: images } = await asyncExecShell(
|
let { stdout: images } = await executeDockerCmd({ dockerId, command: `docker images coollabsio/coolify --filter before="coollabsio/coolify:${version}" -q | xargs` })
|
||||||
`DOCKER_HOST=${host} docker images coollabsio/coolify --filter before="coollabsio/coolify:${version}" -q | xargs `
|
|
||||||
);
|
|
||||||
images = images.trim();
|
images = images.trim();
|
||||||
if (images) {
|
if (images) {
|
||||||
await asyncExecShell(`DOCKER_HOST=${host} docker rmi -f ${images}`);
|
await executeDockerCmd({ dockerId, command: `docker rmi -f ${images}" -q | xargs` })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//console.log(error);
|
//console.log(error);
|
||||||
@@ -1549,17 +1548,17 @@ export async function cleanupDockerStorage(host, lowDiskSpace, force) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await asyncExecShell(`DOCKER_HOST=${host} docker container prune -f`);
|
await executeDockerCmd({ dockerId, command: `docker container prune -f` })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//console.log(error);
|
//console.log(error);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await asyncExecShell(`DOCKER_HOST=${host} docker image prune -f`);
|
await executeDockerCmd({ dockerId, command: `docker image prune -f` })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//console.log(error);
|
//console.log(error);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await asyncExecShell(`DOCKER_HOST=${host} docker image prune -a -f`);
|
await executeDockerCmd({ dockerId, command: `docker image prune -a -f` })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
//console.log(error);
|
//console.log(error);
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,8 @@ export async function hashPassword(password: string): Promise<string> {
|
|||||||
|
|
||||||
export async function cleanupManually() {
|
export async function cleanupManually() {
|
||||||
try {
|
try {
|
||||||
await cleanupDockerStorage('unix:///var/run/docker.sock', true, true)
|
const destination = await prisma.destinationDocker.findFirst({ where: { engine: '/var/run/docker.sock' } })
|
||||||
|
await cleanupDockerStorage(destination.id, true, true)
|
||||||
return {}
|
return {}
|
||||||
} catch ({ status, message }) {
|
} catch ({ status, message }) {
|
||||||
return errorHandler({ status, message })
|
return errorHandler({ status, message })
|
||||||
|
Reference in New Issue
Block a user