2023-08-29 12:36:17 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire;
|
2023-08-29 12:36:17 +00:00
|
|
|
|
2024-01-27 17:44:40 +00:00
|
|
|
use App\Models\ApplicationDeploymentQueue;
|
2024-03-21 13:30:35 +00:00
|
|
|
use App\Models\PrivateKey;
|
2023-08-29 12:36:17 +00:00
|
|
|
use App\Models\Project;
|
|
|
|
use App\Models\Server;
|
2024-01-27 17:44:40 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2024-02-08 11:47:00 +00:00
|
|
|
use Illuminate\Support\Facades\Artisan;
|
2023-08-29 12:36:17 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Dashboard extends Component
|
|
|
|
{
|
2023-10-10 08:56:11 +00:00
|
|
|
public $projects = [];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-27 17:44:40 +00:00
|
|
|
public Collection $servers;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-03-21 13:30:35 +00:00
|
|
|
public Collection $private_keys;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-29 12:26:50 +00:00
|
|
|
public $deployments_per_server;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-08-29 12:36:17 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2024-03-21 13:30:35 +00:00
|
|
|
$this->private_keys = PrivateKey::ownedByCurrentTeam()->get();
|
2023-10-10 08:56:11 +00:00
|
|
|
$this->servers = Server::ownedByCurrentTeam()->get();
|
2023-10-11 08:08:37 +00:00
|
|
|
$this->projects = Project::ownedByCurrentTeam()->get();
|
2024-01-27 17:44:40 +00:00
|
|
|
$this->get_deployments();
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-08 11:47:00 +00:00
|
|
|
public function cleanup_queue()
|
|
|
|
{
|
2024-02-09 12:51:31 +00:00
|
|
|
$this->dispatch('success', 'Cleanup started.');
|
2024-02-26 13:22:24 +00:00
|
|
|
Artisan::queue('cleanup:application-deployment-queue', [
|
2024-06-10 20:43:34 +00:00
|
|
|
'--team-id' => currentTeam()->id,
|
2024-02-08 11:47:00 +00:00
|
|
|
]);
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-01-27 17:44:40 +00:00
|
|
|
public function get_deployments()
|
|
|
|
{
|
2024-06-10 20:43:34 +00:00
|
|
|
$this->deployments_per_server = ApplicationDeploymentQueue::whereIn('status', ['in_progress', 'queued'])->whereIn('server_id', $this->servers->pluck('id'))->get([
|
|
|
|
'id',
|
|
|
|
'application_id',
|
|
|
|
'application_name',
|
|
|
|
'deployment_url',
|
|
|
|
'pull_request_id',
|
|
|
|
'server_name',
|
|
|
|
'server_id',
|
|
|
|
'status',
|
2024-01-29 12:26:50 +00:00
|
|
|
])->sortBy('id')->groupBy('server_name')->toArray();
|
2023-08-29 12:36:17 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-04 14:03:11 +00:00
|
|
|
// public function getIptables()
|
|
|
|
// {
|
|
|
|
// $servers = Server::ownedByCurrentTeam()->get();
|
|
|
|
// foreach ($servers as $server) {
|
|
|
|
// checkRequiredCommands($server);
|
|
|
|
// $iptables = instant_remote_process(['docker run --privileged --net=host --pid=host --ipc=host --volume /:/host busybox chroot /host bash -c "iptables -L -n | jc --iptables"'], $server);
|
|
|
|
// ray($iptables);
|
|
|
|
// }
|
|
|
|
// }
|
2023-08-29 12:36:17 +00:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.dashboard');
|
|
|
|
}
|
|
|
|
}
|