From 58236e08406ac9e110f74ac29f23da303061d474 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 15 Jun 2023 14:41:39 +0200 Subject: [PATCH] fix --- .../Destination/New/StandaloneDocker.php | 31 ++++++++++--------- .../views/livewire/destination/form.blade.php | 2 +- resources/views/server/destinations.blade.php | 7 +++-- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/app/Http/Livewire/Destination/New/StandaloneDocker.php b/app/Http/Livewire/Destination/New/StandaloneDocker.php index 7a0d09169..40bdbe937 100644 --- a/app/Http/Livewire/Destination/New/StandaloneDocker.php +++ b/app/Http/Livewire/Destination/New/StandaloneDocker.php @@ -14,6 +14,7 @@ class StandaloneDocker extends Component public string $network; public Collection $servers; + public Server $server; public int|null $server_id = null; protected $rules = [ @@ -35,29 +36,31 @@ class StandaloneDocker extends Component $this->network = new Cuid2(7); $this->name = generate_random_name(); } - + private function createNetworkAndAttachToProxy() + { + instant_remote_process(['docker network create --attachable ' . $this->network], $this->server, throwError: false); + instant_remote_process(["docker network connect $this->network coolify-proxy"], $this->server, throwError: false); + } public function submit() { $this->validate(); try { - $found = ModelsStandaloneDocker::where('server_id', $this->server_id)->where('network', $this->network)->first(); + $this->server = Server::find($this->server_id); + $found = $this->server->standaloneDockers()->where('network', $this->network)->first(); if ($found) { + $this->createNetworkAndAttachToProxy(); $this->addError('network', 'Network already added to this server.'); return; + } else { + $docker = ModelsStandaloneDocker::create([ + 'name' => $this->name, + 'network' => $this->network, + 'server_id' => $this->server_id, + 'team_id' => session('currentTeam')->id + ]); } - $server = Server::find($this->server_id); - - instant_remote_process(['docker network create --attachable ' . $this->network], $server); - - instant_remote_process(["docker network connect $this->network coolify-proxy"], $server, throwError: false); - - $docker = ModelsStandaloneDocker::create([ - 'name' => $this->name, - 'network' => $this->network, - 'server_id' => $this->server_id, - 'team_id' => session('currentTeam')->id - ]); + $this->createNetworkAndAttachToProxy(); return redirect()->route('destination.show', $docker->uuid); } catch (\Exception $e) { return general_error_handler(err: $e); diff --git a/resources/views/livewire/destination/form.blade.php b/resources/views/livewire/destination/form.blade.php index 76825d6dc..fb4bd2470 100644 --- a/resources/views/livewire/destination/form.blade.php +++ b/resources/views/livewire/destination/form.blade.php @@ -14,7 +14,7 @@ @if ($destination->getMorphClass() === 'App\Models\StandaloneDocker') -
Your standalone docker network.
+
A Docker network in a non-swarm environment
@else
Your swarm docker network. WIP
@endif diff --git a/resources/views/server/destinations.blade.php b/resources/views/server/destinations.blade.php index e6d0e299b..338531ae7 100644 --- a/resources/views/server/destinations.blade.php +++ b/resources/views/server/destinations.blade.php @@ -6,11 +6,12 @@ Add a new destination -
Docker Networks available on the server
-
+
Destinations are used to segregate resources by network.
+
+ Docker Networks available on the server: @forelse ($server->standaloneDockers as $docker) - {{ data_get($docker, 'network') }} + @empty
No destinations added