coolify/app/Livewire/Destination/Show.php

32 lines
1.1 KiB
PHP
Raw Normal View History

2023-06-15 15:38:15 +02:00
<?php
2023-12-07 19:06:32 +01:00
namespace App\Livewire\Destination;
2023-06-15 15:38:15 +02:00
use App\Models\Server;
use Illuminate\Support\Collection;
use Livewire\Component;
class Show extends Component
{
public Server $server;
public Collection|array $networks = [];
2023-06-15 15:38:15 +02:00
public function scan()
{
2023-12-15 15:48:01 +01:00
if ($this->server->isSwarm()) {
$alreadyAddedNetworks = $this->server->swarmDockers;
} else {
$alreadyAddedNetworks = $this->server->standaloneDockers;
}
2023-06-15 15:38:15 +02:00
$networks = instant_remote_process(['docker network ls --format "{{json .}}"'], $this->server, false);
$this->networks = format_docker_command_output_to_json($networks)->filter(function ($network) {
return $network['Name'] !== 'bridge' && $network['Name'] !== 'host' && $network['Name'] !== 'none';
})->filter(function ($network) use ($alreadyAddedNetworks) {
return !$alreadyAddedNetworks->contains('network', $network['Name']);
});
2023-06-22 09:38:44 +02:00
if ($this->networks->count() === 0) {
2023-12-07 19:06:32 +01:00
$this->dispatch('success', 'No new networks found.');
2023-06-22 09:38:44 +02:00
}
2023-06-15 15:38:15 +02:00
}
}