Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: cleanup function

Andras Bacsai8b57a2b05515
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index 1ab6acd479..44d46f8a37 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -591,6 +591,8 @@ async function cleanupStorage() {
}
}
} catch (error) {}
- await cleanupDockerStorage(destination.id, lowDiskSpace, force);
+ if (lowDiskSpace) {
+ await cleanupDockerStorage(destination.id);
+ }
}
}
diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts
index 02f932613d..3eeced3f7b 100644
--- a/apps/api/src/lib/common.ts
+++ b/apps/api/src/lib/common.ts
@@ -19,7 +19,7 @@ import { saveBuildLog, saveDockerRegistryCredentials } from './buildPacks/common
import { scheduler } from './scheduler';
import type { ExecaChildProcess } from 'execa';
-export const version = '3.12.14';
+export const version = '3.12.15';
export const isDev = process.env.NODE_ENV === 'development';
export const sentryDSN =
'https://[email protected]/4504236622217216';
@@ -1714,78 +1714,24 @@ export function convertTolOldVolumeNames(type) {
}
}
-export async function cleanupDockerStorage(dockerId, lowDiskSpace, force) {
- // Cleanup old coolify images
+export async function cleanupDockerStorage(dockerId) {
+ // Cleanup images that are not used by any container
try {
- let { stdout: images } = await executeCommand({
- dockerId,
- command: `docker images coollabsio/coolify --filter before="coollabsio/coolify:${version}" -q | xargs -r`,
- shell: true
- });
-
- images = images.trim();
- if (images) {
- await executeCommand({
- dockerId,
- command: `docker rmi -f ${images}" -q | xargs -r`,
- shell: true
- });
- }
+ await executeCommand({ dockerId, command: `docker image prune -af` });
} catch (error) {}
- if (lowDiskSpace || force) {
- // Cleanup images that are not used
- try {
- await executeCommand({ dockerId, command: `docker image prune -f` });
- } catch (error) {}
- const { numberOfDockerImagesKeptLocally } = await prisma.setting.findUnique({
- where: { id: '0' }
- });
- const { stdout: images } = await executeCommand({
+ // Prune coolify managed containers
+ try {
+ await executeCommand({
dockerId,
- command: `docker images|grep -v "<none>"|grep -v REPOSITORY|awk '{print $1, $2}'`,
- shell: true
+ command: `docker container prune -f --filter "label=coolify.managed=true"`
});
- const imagesArray = images.trim().replaceAll(' ', ':').split('\n');
- const imagesSet = new Set(imagesArray.map((image) => image.split(':')[0]));
- let deleteImage = [];
- for (const image of imagesSet) {
- let keepImage = [];
- for (const image2 of imagesArray) {
- if (image2.startsWith(image)) {
- if (force) {
- deleteImage.push(image2);
- continue;
- }
- if (keepImage.length >= numberOfDockerImagesKeptLocally) {
- deleteImage.push(image2);
- } else {
- keepImage.push(image2);
- }
- }
- }
- }
- for (const image of deleteImage) {
- try {
- await executeCommand({ dockerId, command: `docker image rm -f ${image}` });
- } catch (error) {
- console.log(error);
- }
- }
-
- // Prune coolify managed containers
- try {
- await executeCommand({
- dockerId,
- command: `docker container prune -f --filter "label=coolify.managed=true"`
- });
- } catch (error) {}
+ } catch (error) {}
- // Cleanup build caches
- try {
- await executeCommand({ dockerId, command: `docker builder prune -a -f` });
- } catch (error) {}
- }
+ // Cleanup build caches
+ try {
+ await executeCommand({ dockerId, command: `docker builder prune -af` });
+ } catch (error) {}
}
export function persistentVolumes(id, persistentStorage, config) {
diff --git a/apps/api/src/routes/api/v1/handlers.ts b/apps/api/src/routes/api/v1/handlers.ts
index 3826358008..52d5e4e38a 100644
--- a/apps/api/src/routes/api/v1/handlers.ts
+++ b/apps/api/src/routes/api/v1/handlers.ts
@@ -59,7 +59,7 @@ export async function cleanupManually(request: FastifyRequest) {
const destination = await prisma.destinationDocker.findUnique({
where: { id: serverId }
});
- await cleanupDockerStorage(destination.id, true, true);
+ await cleanupDockerStorage(destination.id);
return {};
} catch ({ status, message }) {
return errorHandler({ status, message });
diff --git a/package.json b/package.json
index 9ace8b3e16..88034d7b71 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "coolify",
"description": "An open-source & self-hostable Heroku / Netlify alternative.",
- "version": "3.12.14",
+ "version": "3.12.15",
"license": "Apache-2.0",
"repository": "github:coollabsio/coolify",
"scripts": {