2024-01-12 07:45:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Actions\Server;
|
|
|
|
|
|
2024-09-10 09:33:52 +00:00
|
|
|
use App\Models\InstanceSettings;
|
2024-01-12 07:45:24 +00:00
|
|
|
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-08-21 08:50:05 +00:00
|
|
|
public function handle(Server $server)
|
2024-08-18 20:41:06 +00:00
|
|
|
{
|
2024-08-26 09:13:40 +00:00
|
|
|
|
2024-08-26 10:23:03 +00:00
|
|
|
$commands = $this->getCommands();
|
2024-08-18 20:41:06 +00:00
|
|
|
|
|
|
|
|
foreach ($commands as $command) {
|
|
|
|
|
instant_remote_process([$command], $server, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-26 10:23:03 +00:00
|
|
|
private function getCommands(): array
|
2024-01-12 07:45:24 +00:00
|
|
|
{
|
2024-09-10 09:33:52 +00:00
|
|
|
$settings = InstanceSettings::get();
|
|
|
|
|
$helperImageVersion = data_get($settings, 'helper_version');
|
|
|
|
|
$helperImage = config('coolify.helper_image');
|
|
|
|
|
$helperImageWithVersion = config('coolify.helper_image').':'.$helperImageVersion;
|
|
|
|
|
|
2024-08-09 21:27:39 +00:00
|
|
|
$commonCommands = [
|
|
|
|
|
'docker container prune -f --filter "label=coolify.managed=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-10 09:33:52 +00:00
|
|
|
"docker images --filter before=$helperImageWithVersion --filter reference=$helperImage | grep $helperImage | awk '{print $3}' | xargs -r docker rmi",
|
2024-08-09 21:27:39 +00:00
|
|
|
];
|
|
|
|
|
|
2024-08-18 20:41:06 +00:00
|
|
|
return $commonCommands;
|
2024-01-12 07:45:24 +00:00
|
|
|
}
|
|
|
|
|
}
|