2023-11-16 19:48:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
|
|
use App\Models\Server;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
class CleanupHelperContainersJob implements ShouldBeEncrypted, ShouldBeUnique, ShouldQueue
|
2023-11-16 19:48:25 +00:00
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
public function __construct(public Server $server)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle(): void
|
|
|
|
{
|
|
|
|
try {
|
2024-06-10 20:43:34 +00:00
|
|
|
ray('Cleaning up helper containers on '.$this->server->name);
|
2023-11-16 19:48:25 +00:00
|
|
|
$containers = instant_remote_process(['docker container ps --filter "ancestor=ghcr.io/coollabsio/coolify-helper:next" --filter "ancestor=ghcr.io/coollabsio/coolify-helper:latest" --format \'{{json .}}\''], $this->server, false);
|
|
|
|
$containers = format_docker_command_output_to_json($containers);
|
|
|
|
if ($containers->count() > 0) {
|
|
|
|
foreach ($containers as $container) {
|
2024-06-10 20:43:34 +00:00
|
|
|
$containerId = data_get($container, 'ID');
|
|
|
|
ray('Removing container '.$containerId);
|
|
|
|
instant_remote_process(['docker container rm -f '.$containerId], $this->server, false);
|
2023-11-16 19:48:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (\Throwable $e) {
|
2024-06-10 20:43:34 +00:00
|
|
|
send_internal_notification('CleanupHelperContainersJob failed with error: '.$e->getMessage());
|
2023-11-16 19:48:25 +00:00
|
|
|
ray($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|