From 8b128c1bbe78f2604ead1ad190a22ce7138f8b2e Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 14 Jul 2023 13:38:24 +0200 Subject: [PATCH] lots of UI fixes --- .../{InstallProxy.php => StartProxy.php} | 2 +- app/Http/Controllers/MagicController.php | 2 +- app/Http/Livewire/Server/Proxy.php | 4 +- app/Http/Livewire/Server/Proxy/Deploy.php | 4 +- app/Http/Livewire/Settings/Configuration.php | 5 +- app/Jobs/ApplicationDeploymentJob.php | 2 +- app/Jobs/ProxyCheckJob.php | 24 +-- app/Jobs/ProxyStartJob.php | 35 +++++ app/Models/Server.php | 8 +- database/seeders/ServerSeeder.php | 1 - database/seeders/ServerSettingSeeder.php | 4 +- .../views/components/server/navbar.blade.php | 8 +- .../views/livewire/destination/show.blade.php | 62 ++++---- .../views/livewire/server/proxy.blade.php | 8 +- .../livewire/server/proxy/deploy.blade.php | 145 +++++++++--------- resources/views/server/all.blade.php | 15 +- routes/web.php | 4 +- 17 files changed, 188 insertions(+), 145 deletions(-) rename app/Actions/Proxy/{InstallProxy.php => StartProxy.php} (99%) create mode 100755 app/Jobs/ProxyStartJob.php diff --git a/app/Actions/Proxy/InstallProxy.php b/app/Actions/Proxy/StartProxy.php similarity index 99% rename from app/Actions/Proxy/InstallProxy.php rename to app/Actions/Proxy/StartProxy.php index 1e2369f8a..2050e2ca1 100644 --- a/app/Actions/Proxy/InstallProxy.php +++ b/app/Actions/Proxy/StartProxy.php @@ -8,7 +8,7 @@ use App\Models\Server; use Spatie\Activitylog\Models\Activity; use Illuminate\Support\Str; -class InstallProxy +class StartProxy { public function __invoke(Server $server): Activity { diff --git a/app/Http/Controllers/MagicController.php b/app/Http/Controllers/MagicController.php index 66dcf5549..c4f77805a 100644 --- a/app/Http/Controllers/MagicController.php +++ b/app/Http/Controllers/MagicController.php @@ -13,7 +13,7 @@ class MagicController extends Controller public function servers() { return response()->json([ - 'servers' => Server::validated()->get() + 'servers' => Server::isUsable()->get() ]); } public function destinations() diff --git a/app/Http/Livewire/Server/Proxy.php b/app/Http/Livewire/Server/Proxy.php index e790e3565..5d3c1ebba 100644 --- a/app/Http/Livewire/Server/Proxy.php +++ b/app/Http/Livewire/Server/Proxy.php @@ -27,14 +27,16 @@ class Proxy extends Component } public function switchProxy() { - $this->server->proxy->type = null; + $this->server->proxy = null; $this->server->save(); + $this->emit('proxyStatusUpdated'); } public function setProxy(string $proxy_type) { $this->server->proxy->type = $proxy_type; $this->server->proxy->status = 'exited'; $this->server->save(); + $this->emit('proxyStatusUpdated'); } public function stopProxy() { diff --git a/app/Http/Livewire/Server/Proxy/Deploy.php b/app/Http/Livewire/Server/Proxy/Deploy.php index afb7202a4..c1ca4ab57 100644 --- a/app/Http/Livewire/Server/Proxy/Deploy.php +++ b/app/Http/Livewire/Server/Proxy/Deploy.php @@ -2,7 +2,7 @@ namespace App\Http\Livewire\Server\Proxy; -use App\Actions\Proxy\InstallProxy; +use App\Actions\Proxy\StartProxy; use App\Models\Server; use Livewire\Component; use Str; @@ -24,7 +24,7 @@ class Deploy extends Component ) { $this->saveConfiguration($this->server); } - $activity = resolve(InstallProxy::class)($this->server); + $activity = resolve(StartProxy::class)($this->server); $this->emit('newMonitorActivity', $activity->id); } public function stop() diff --git a/app/Http/Livewire/Settings/Configuration.php b/app/Http/Livewire/Settings/Configuration.php index a5c9ad335..98371d136 100644 --- a/app/Http/Livewire/Settings/Configuration.php +++ b/app/Http/Livewire/Settings/Configuration.php @@ -2,8 +2,7 @@ namespace App\Http\Livewire\Settings; -use App\Actions\Proxy\InstallProxy; -use App\Jobs\ProxyCheckJob; +use App\Jobs\ProxyStartJob; use App\Models\InstanceSettings as ModelsInstanceSettings; use App\Models\Server; use Livewire\Component; @@ -108,7 +107,7 @@ class Configuration extends Component ]; } $this->save_configuration_to_disk($traefik_dynamic_conf, $file); - dispatch(new ProxyCheckJob($this->server)); + dispatch(new ProxyStartJob($this->server)); } } private function save_configuration_to_disk(array $traefik_dynamic_conf, string $file) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index d9e080648..a800d7c2e 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -117,7 +117,7 @@ class ApplicationDeploymentJob implements ShouldQueue } else { $this->deploy(); } - if ($this->application->fqdn) dispatch(new ProxyCheckJob($this->server)); + if ($this->application->fqdn) dispatch(new ProxyStartJob($this->server)); $this->next(ApplicationDeploymentStatus::FINISHED->value); } catch (\Exception $e) { ray($e); diff --git a/app/Jobs/ProxyCheckJob.php b/app/Jobs/ProxyCheckJob.php index dbe785d96..ab04d3d07 100755 --- a/app/Jobs/ProxyCheckJob.php +++ b/app/Jobs/ProxyCheckJob.php @@ -2,7 +2,7 @@ namespace App\Jobs; -use App\Actions\Proxy\InstallProxy; +use App\Actions\Proxy\StartProxy; use App\Enums\ProxyTypes; use App\Models\Server; use Illuminate\Bus\Queueable; @@ -15,30 +15,20 @@ class ProxyCheckJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; - public function __construct(protected Server|null $server = null) + public function __construct() { } public function handle() { try { $container_name = 'coolify-proxy'; - if ($this->server) { - ray('Checking proxy for server: ' . $this->server->name); - $status = get_container_status(server: $this->server, container_id: $container_name); + $servers = Server::isUsable()->whereNotNull('proxy')->get(); + foreach ($servers as $server) { + $status = get_container_status(server: $server, container_id: $container_name); if ($status === 'running') { - return; - } - resolve(InstallProxy::class)($this->server); - } else { - $servers = Server::whereRelation('settings', 'is_usable', true)->get(); - - foreach ($servers as $server) { - $status = get_container_status(server: $server, container_id: $container_name); - if ($status === 'running') { - continue; - } - resolve(InstallProxy::class)($server); + continue; } + resolve(StartProxy::class)($server); } } catch (\Throwable $th) { ray($th->getMessage()); diff --git a/app/Jobs/ProxyStartJob.php b/app/Jobs/ProxyStartJob.php new file mode 100755 index 000000000..074d21664 --- /dev/null +++ b/app/Jobs/ProxyStartJob.php @@ -0,0 +1,35 @@ +server->name); + $status = get_container_status(server: $this->server, container_id: $container_name); + if ($status === 'running') { + return; + } + resolve(StartProxy::class)($this->server); + } catch (\Throwable $th) { + ray($th->getMessage()); + //throw $th; + } + } +} diff --git a/app/Models/Server.php b/app/Models/Server.php index 0d21e80b0..31e2d1e5c 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -94,10 +94,14 @@ class Server extends BaseModel return Server::whereTeamId(session('currentTeam')->id)->with('settings')->select($selectArray->all())->orderBy('name'); } - static public function validated() + static public function isReachable() { return Server::ownedByCurrentTeam()->whereRelation('settings', 'is_reachable', true); } + static public function isUsable() + { + return Server::ownedByCurrentTeam()->whereRelation('settings', 'is_reachable', true)->whereRelation('settings', 'is_usable', true); + } static public function destinationsByServer(string $server_id) { @@ -106,4 +110,4 @@ class Server extends BaseModel $swarmDocker = collect($server->swarmDockers->all()); return $standaloneDocker->concat($swarmDocker); } -} \ No newline at end of file +} diff --git a/database/seeders/ServerSeeder.php b/database/seeders/ServerSeeder.php index e43092b12..82ab2552b 100644 --- a/database/seeders/ServerSeeder.php +++ b/database/seeders/ServerSeeder.php @@ -2,7 +2,6 @@ namespace Database\Seeders; -use App\Actions\Proxy\InstallProxy; use App\Data\ServerMetadata; use App\Enums\ProxyStatus; use App\Enums\ProxyTypes; diff --git a/database/seeders/ServerSettingSeeder.php b/database/seeders/ServerSettingSeeder.php index f2d8c9b49..fe366ba77 100644 --- a/database/seeders/ServerSettingSeeder.php +++ b/database/seeders/ServerSettingSeeder.php @@ -16,12 +16,14 @@ class ServerSettingSeeder extends Seeder $server_2 = Server::find(0)->load(['settings']); $server_2->settings->wildcard_domain = 'http://127.0.0.1.sslip.io'; $server_2->settings->is_build_server = true; + $server_2->settings->is_usable = true; $server_2->settings->is_reachable = true; $server_2->settings->save(); $server_3 = Server::find(1)->load(['settings']); $server_3->settings->is_part_of_swarm = false; + $server_2->settings->is_usable = false; $server_3->settings->is_reachable = false; $server_3->settings->save(); } -} \ No newline at end of file +} diff --git a/resources/views/components/server/navbar.blade.php b/resources/views/components/server/navbar.blade.php index 5fe9b0759..dcfd76dbb 100644 --- a/resources/views/components/server/navbar.blade.php +++ b/resources/views/components/server/navbar.blade.php @@ -26,11 +26,9 @@ ]) }}"> - @if ($server->settings->is_reachable) - @if (request()->routeIs('server.proxy')) -
- - @endif + @if (request()->routeIs('server.proxy')) +
+ @endif diff --git a/resources/views/livewire/destination/show.blade.php b/resources/views/livewire/destination/show.blade.php index a59c05f2b..f39b2a3a8 100644 --- a/resources/views/livewire/destination/show.blade.php +++ b/resources/views/livewire/destination/show.blade.php @@ -1,32 +1,36 @@
-
-

Destinations

- - Add a new destination - - Scan destinations on the server -
-
Destinations are used to segregate resources by network.
-
- Available for using: - @forelse ($server->standaloneDockers as $docker) - - + @if ($server->settings->is_usable) +
+

Destinations

+
+ Add a new destination - @empty -
N/A
- @endforelse -
-
- @if (count($networks) > 0) -

Found Destinations

- @endif - @foreach ($networks as $network) - - Add{{ data_get($network, 'Name') }} - - - @endforeach -
+ Scan destinations on the server +
+
Destinations are used to segregate resources by network.
+
+ Available for using: + @forelse ($server->standaloneDockers as $docker) + + + + @empty +
N/A
+ @endforelse +
+
+ @if (count($networks) > 0) +

Found Destinations

+ @endif + @foreach ($networks as $network) + + Add{{ data_get($network, 'Name') }} + + + @endforeach +
+ @else +
Server is not validated. Validate first.
+ @endif
diff --git a/resources/views/livewire/server/proxy.blade.php b/resources/views/livewire/server/proxy.blade.php index a31278985..26620ea0f 100644 --- a/resources/views/livewire/server/proxy.blade.php +++ b/resources/views/livewire/server/proxy.blade.php @@ -1,7 +1,7 @@
- @if ($server->settings->is_reachable) + @if ($server->settings->is_usable) @if ($server->proxy->type)
@if ($selectedProxy->value === 'TRAEFIK_V2') @@ -12,9 +12,7 @@ @if ($server->proxy->status === 'exited') Switch Proxy @endif - @if ($server->settings->is_reachable) - - @endif +
Traefik v2
@@ -66,6 +64,6 @@
@endif @else -
Server is not validated. Validate first.
+
Server is not validated. Validate first.
@endif diff --git a/resources/views/livewire/server/proxy/deploy.blade.php b/resources/views/livewire/server/proxy/deploy.blade.php index b08d90948..01abbc38c 100644 --- a/resources/views/livewire/server/proxy/deploy.blade.php +++ b/resources/views/livewire/server/proxy/deploy.blade.php @@ -1,76 +1,79 @@
- @if ($server->proxy->status === 'running') -
-
- - - @else - + @else + + @endif @endif
diff --git a/resources/views/server/all.blade.php b/resources/views/server/all.blade.php index b08b2c845..c7ee37a2a 100644 --- a/resources/views/server/all.blade.php +++ b/resources/views/server/all.blade.php @@ -11,13 +11,22 @@
{{ $server->name }} - @if (!$server->settings->is_reachable) - not validated yet - @endif +
{{ $server->description }}
+
+ @if (!$server->settings->is_reachable) + Not reachable + @endif + @if (!$server->settings->is_reachable && !$server->settings->is_usable) + & + @endif + @if (!$server->settings->is_usable) + Not usable by Coolify + @endif +
diff --git a/routes/web.php b/routes/web.php index b72fc889d..10e15d77d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -93,7 +93,7 @@ Route::middleware(['auth'])->group(function () { Route::get('/team/new', fn () => view('team.create'))->name('team.create'); Route::get('/team/notifications', fn () => view('team.notifications'))->name('team.notifications'); Route::get('/team/members', [Controller::class, 'members'])->name('team.members'); - Route::get('/command-center', fn () => view('command-center', ['servers' => Server::validated()->get()]))->name('command-center'); + Route::get('/command-center', fn () => view('command-center', ['servers' => Server::isReachable()->get()]))->name('command-center'); Route::get('/invitations/{uuid}', [Controller::class, 'acceptInvitation'])->name('team.invitation.accept'); Route::get('/invitations/{uuid}/revoke', [Controller::class, 'revokeInvitation'])->name('team.invitation.revoke'); }); @@ -156,7 +156,7 @@ Route::middleware(['auth'])->group(function () { ]); })->name('destination.all'); Route::get('/destination/new', function () { - $servers = Server::validated()->get(); + $servers = Server::isUsable()->get(); $pre_selected_server_uuid = data_get(request()->query(), 'server'); if ($pre_selected_server_uuid) { $server = $servers->firstWhere('uuid', $pre_selected_server_uuid);