fix(server): exclude persistent resources from container prune

Prevent docker container prune from removing containers labeled as
database, application, or service types. Previously only proxy containers
were excluded, risking accidental cleanup of active resources.
This commit is contained in:
Andras Bacsai
2026-04-19 15:17:47 +02:00
parent 371e883c75
commit 0620496c5f
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -48,7 +48,7 @@ class CleanupDocker
);
$commands = [
'docker container prune -f --filter "label=coolify.managed=true" --filter "label!=coolify.proxy=true"',
'docker container prune -f --filter "label=coolify.managed=true" --filter "label!=coolify.proxy=true" --filter "label!=coolify.type=database" --filter "label!=coolify.type=application" --filter "label!=coolify.type=service"',
$imagePruneCmd,
'docker builder prune -af',
"docker images --filter before=$helperImageWithVersion --filter reference=$helperImage | grep $helperImage | awk '{print $3}' | xargs -r docker rmi -f",
@@ -437,6 +437,16 @@ it('deletes all build images when retention is disabled', function () {
expect($buildImagesToDelete->pluck('tag')->toArray())->toContain('commit1-build');
});
it('container prune excludes persistent resource types', function () {
$sourceFile = file_get_contents(__DIR__.'/../../../../app/Actions/Server/CleanupDocker.php');
expect($sourceFile)->toContain('label!=coolify.type=database');
expect($sourceFile)->toContain('label!=coolify.type=application');
expect($sourceFile)->toContain('label!=coolify.type=service');
expect($sourceFile)->toContain('label!=coolify.proxy=true');
expect($sourceFile)->toContain('label=coolify.managed=true');
});
it('preserves build image for currently running tag', function () {
$images = collect([
['repository' => 'app-uuid', 'tag' => 'commit1', 'created_at' => '2024-01-01 10:00:00', 'image_ref' => 'app-uuid:commit1'],