2024-01-12 07:45:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Actions\Server;
|
|
|
|
|
|
|
|
|
|
use App\Models\Server;
|
2024-06-10 20:43:34 +00:00
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
2024-01-12 07:45:24 +00:00
|
|
|
|
|
|
|
|
class CleanupDocker
|
|
|
|
|
{
|
|
|
|
|
use AsAction;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-11-22 10:16:01 +00:00
|
|
|
public string $jobQueue = 'high';
|
|
|
|
|
|
2024-08-21 08:50:05 +00:00
|
|
|
public function handle(Server $server)
|
2024-01-12 07:45:24 +00:00
|
|
|
{
|
2024-10-01 08:37:40 +00:00
|
|
|
$settings = instanceSettings();
|
2024-09-10 09:33:52 +00:00
|
|
|
$helperImageVersion = data_get($settings, 'helper_version');
|
2024-11-12 14:18:48 +00:00
|
|
|
$helperImage = config('constants.coolify.helper_image');
|
2024-09-22 18:02:51 +00:00
|
|
|
$helperImageWithVersion = "$helperImage:$helperImageVersion";
|
2024-09-10 09:33:52 +00:00
|
|
|
|
2024-09-22 18:02:51 +00:00
|
|
|
$commands = [
|
2024-09-28 09:14:14 +00:00
|
|
|
'docker container prune -f --filter "label=coolify.managed=true" --filter "label!=coolify.proxy=true"',
|
2024-09-08 10:38:22 +00:00
|
|
|
'docker image prune -af --filter "label!=coolify.managed=true"',
|
2024-08-26 10:23:03 +00:00
|
|
|
'docker builder prune -af',
|
2024-09-22 18:36:41 +00:00
|
|
|
"docker images --filter before=$helperImageWithVersion --filter reference=$helperImage | grep $helperImage | awk '{print $3}' | xargs -r docker rmi -f",
|
2024-08-09 21:27:39 +00:00
|
|
|
];
|
|
|
|
|
|
2024-09-22 18:02:51 +00:00
|
|
|
$serverSettings = $server->settings;
|
|
|
|
|
if ($serverSettings->delete_unused_volumes) {
|
|
|
|
|
$commands[] = 'docker volume prune -af';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($serverSettings->delete_unused_networks) {
|
|
|
|
|
$commands[] = 'docker network prune -f';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($commands as $command) {
|
|
|
|
|
instant_remote_process([$command], $server, false);
|
|
|
|
|
}
|
2024-01-12 07:45:24 +00:00
|
|
|
}
|
|
|
|
|
}
|