fix: more aggressive cleanup

This commit is contained in:
Andras Bacsai
2023-05-24 20:34:40 +02:00
parent e86b916415
commit d4798a3b22
3 changed files with 50 additions and 49 deletions

View File

@@ -604,53 +604,54 @@ async function cleanupStorage() {
if (!destination.remoteVerified) continue; if (!destination.remoteVerified) continue;
enginesDone.add(destination.remoteIpAddress); enginesDone.add(destination.remoteIpAddress);
} }
let lowDiskSpace = false; await cleanupDockerStorage(destination.id);
try { // let lowDiskSpace = false;
let stdout = null; // try {
if (!isDev) { // let stdout = null;
const output = await executeCommand({ // if (!isDev) {
dockerId: destination.id, // const output = await executeCommand({
command: `CONTAINER=$(docker ps -lq | head -1) && docker exec $CONTAINER sh -c 'df -kPT /'`, // dockerId: destination.id,
shell: true // command: `CONTAINER=$(docker ps -lq | head -1) && docker exec $CONTAINER sh -c 'df -kPT /'`,
}); // shell: true
stdout = output.stdout; // });
} else { // stdout = output.stdout;
const output = await executeCommand({ // } else {
command: `df -kPT /` // const output = await executeCommand({
}); // command: `df -kPT /`
stdout = output.stdout; // });
} // stdout = output.stdout;
let lines = stdout.trim().split('\n'); // }
let header = lines[0]; // let lines = stdout.trim().split('\n');
let regex = // let header = lines[0];
/^Filesystem\s+|Type\s+|1024-blocks|\s+Used|\s+Available|\s+Capacity|\s+Mounted on\s*$/g; // let regex =
const boundaries = []; // /^Filesystem\s+|Type\s+|1024-blocks|\s+Used|\s+Available|\s+Capacity|\s+Mounted on\s*$/g;
let match; // const boundaries = [];
// let match;
while ((match = regex.exec(header))) { // while ((match = regex.exec(header))) {
boundaries.push(match[0].length); // boundaries.push(match[0].length);
} // }
boundaries[boundaries.length - 1] = -1; // boundaries[boundaries.length - 1] = -1;
const data = lines.slice(1).map((line) => { // const data = lines.slice(1).map((line) => {
const cl = boundaries.map((boundary) => { // const cl = boundaries.map((boundary) => {
const column = boundary > 0 ? line.slice(0, boundary) : line; // const column = boundary > 0 ? line.slice(0, boundary) : line;
line = line.slice(boundary); // line = line.slice(boundary);
return column.trim(); // return column.trim();
}); // });
return { // return {
capacity: Number.parseInt(cl[5], 10) / 100 // capacity: Number.parseInt(cl[5], 10) / 100
}; // };
}); // });
if (data.length > 0) { // if (data.length > 0) {
const { capacity } = data[0]; // const { capacity } = data[0];
if (capacity > 0.8) { // if (capacity > 0.8) {
lowDiskSpace = true; // lowDiskSpace = true;
} // }
} // }
} catch (error) {} // } catch (error) {}
if (lowDiskSpace) { // if (lowDiskSpace) {
await cleanupDockerStorage(destination.id); // await cleanupDockerStorage(destination.id);
} // }
} }
} }

View File

@@ -19,7 +19,7 @@ import { saveBuildLog } from './buildPacks/common';
import { scheduler } from './scheduler'; import { scheduler } from './scheduler';
import type { ExecaChildProcess } from 'execa'; import type { ExecaChildProcess } from 'execa';
export const version = '3.12.31'; export const version = '3.12.32';
export const isDev = process.env.NODE_ENV === 'development'; export const isDev = process.env.NODE_ENV === 'development';
export const proxyPort = process.env.COOLIFY_PROXY_PORT; export const proxyPort = process.env.COOLIFY_PROXY_PORT;
export const proxySecurePort = process.env.COOLIFY_PROXY_SECURE_PORT; export const proxySecurePort = process.env.COOLIFY_PROXY_SECURE_PORT;

View File

@@ -1,7 +1,7 @@
{ {
"name": "coolify", "name": "coolify",
"description": "An open-source & self-hostable Heroku / Netlify alternative.", "description": "An open-source & self-hostable Heroku / Netlify alternative.",
"version": "3.12.31", "version": "3.12.32",
"license": "Apache-2.0", "license": "Apache-2.0",
"repository": "github:coollabsio/coolify", "repository": "github:coollabsio/coolify",
"scripts": { "scripts": {
@@ -50,4 +50,4 @@
"open-source", "open-source",
"coolify" "coolify"
] ]
} }