Skip to content

Commit

Permalink
refactor: Update CleanupHelperContainersJob to use more efficient Doc…
Browse files Browse the repository at this point in the history
…ker command
  • Loading branch information
andrasbacsai committed Sep 20, 2024
1 parent fc6f5d8 commit f1881d5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions app/Jobs/CleanupHelperContainersJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ public function handle(): void
{
try {
ray('Cleaning up helper containers on '.$this->server->name);
$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) {
$containerId = data_get($container, 'ID');
$containers = instant_remote_process(['docker container ps --format \'{{json .}}\' | jq -s \'map(select(.Image | contains("ghcr.io/coollabsio/coolify-helper")))\''], $this->server, false);
$containerIds = collect(json_decode($containers))->pluck('ID');
if ($containerIds->count() > 0) {
foreach ($containerIds as $containerId) {
ray('Removing container '.$containerId);
instant_remote_process(['docker container rm -f '.$containerId], $this->server, false);
}
Expand Down

0 comments on commit f1881d5

Please sign in to comment.