diff --git a/app/Http/Livewire/Destination/Form.php b/app/Http/Livewire/Destination/Form.php index f6434f61d..3643e6782 100644 --- a/app/Http/Livewire/Destination/Form.php +++ b/app/Http/Livewire/Destination/Form.php @@ -2,8 +2,6 @@ namespace App\Http\Livewire\Destination; -use App\Models\StandaloneDocker; -use App\Models\SwarmDocker; use Livewire\Component; class Form extends Component @@ -22,8 +20,18 @@ public function submit() } public function delete() { - // instantRemoteProcess(['docker network rm -f ' . $this->destination->network], $this->destination->server); - $this->destination->delete(); - return redirect()->route('dashboard'); + try { + if ($this->destination->getMorphClass() === 'App\Models\StandaloneDocker') { + if ($this->destination->attachedTo()) { + return $this->emit('error', 'You must delete all resources before deleting this destination.'); + } + instantRemoteProcess(["docker network disconnect {$this->destination->network} coolify-proxy"], $this->destination->server, throwError: false); + instantRemoteProcess(['docker network rm -f ' . $this->destination->network], $this->destination->server); + } + $this->destination->delete(); + return redirect()->route('dashboard'); + } catch (\Exception $e) { + return generalErrorHandler($e); + } } } diff --git a/app/Http/Livewire/Destination/New/StandaloneDocker.php b/app/Http/Livewire/Destination/New/StandaloneDocker.php index 96625eba8..f7ce86713 100644 --- a/app/Http/Livewire/Destination/New/StandaloneDocker.php +++ b/app/Http/Livewire/Destination/New/StandaloneDocker.php @@ -44,6 +44,10 @@ public function submit() $this->addError('network', 'Network already added to this server.'); return; } + $server = Server::find($this->server_id); + instantRemoteProcess(['docker network create --attachable ' . $this->network], $server, throwError: false); + instantRemoteProcess(["docker network connect $this->network coolify-proxy"], $server, throwError: false); + $docker = ModelsStandaloneDocker::create([ 'name' => $this->name, 'network' => $this->network, @@ -51,9 +55,7 @@ public function submit() 'team_id' => session('currentTeam')->id ]); - $server = Server::find($this->server_id); - instantRemoteProcess(['docker network create --attachable ' . $this->network], $server, throwError: false); return redirect()->route('destination.show', $docker->uuid); } } diff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.php index f131c159a..d14bbcd21 100644 --- a/app/Http/Livewire/Server/Form.php +++ b/app/Http/Livewire/Server/Form.php @@ -20,7 +20,8 @@ class Form extends Component 'server.ip' => 'required', 'server.user' => 'required', 'server.port' => 'required', - 'server.settings.is_validated' => 'required' + 'server.settings.is_validated' => 'required', + 'server.settings.is_part_of_swarm' => 'required' ]; public function mount() { diff --git a/app/Http/Livewire/Server/New/ByIp.php b/app/Http/Livewire/Server/New/ByIp.php index b99121a40..d2a4f1b3c 100644 --- a/app/Http/Livewire/Server/New/ByIp.php +++ b/app/Http/Livewire/Server/New/ByIp.php @@ -19,24 +19,28 @@ class ByIp extends Component public string $ip; public string $user = 'root'; public int $port = 22; + public bool $is_part_of_swarm = false; protected $rules = [ 'name' => 'required', 'ip' => 'required', 'user' => 'required', 'port' => 'required|integer', + 'is_part_of_swarm' => 'required|boolean', ]; public function mount() { $this->name = generateRandomName(); - if ($this->private_keys->count() > 0) { - $this->private_key_id = $this->private_keys->first()->id; - } + $this->private_key_id = $this->private_keys->first()->id; } public function setPrivateKey(string $private_key_id) { $this->private_key_id = $private_key_id; } + public function instantSave() + { + $this->emit('saved', 'Application settings updated!'); + } public function submit() { try { @@ -51,8 +55,10 @@ public function submit() 'user' => $this->user, 'port' => $this->port, 'team_id' => session('currentTeam')->id, - 'private_key_id' => $this->private_key_id + 'private_key_id' => $this->private_key_id, ]); + $server->settings->is_part_of_swarm = $this->is_part_of_swarm; + $server->settings->save(); return redirect()->route('server.show', $server->uuid); } catch (\Exception $e) { return generalErrorHandler($e); diff --git a/app/Models/StandaloneDocker.php b/app/Models/StandaloneDocker.php index adb251094..ea257dd60 100644 --- a/app/Models/StandaloneDocker.php +++ b/app/Models/StandaloneDocker.php @@ -13,8 +13,16 @@ public function applications() { return $this->morphMany(Application::class, 'destination'); } + public function databases() + { + return $this->morphMany(Database::class, 'destination'); + } public function server() { return $this->belongsTo(Server::class); } + public function attachedTo() + { + return $this->applications->count() > 0 || $this->databases->count() > 0; + } } diff --git a/database/migrations/2023_03_24_140712_create_server_settings_table.php b/database/migrations/2023_03_24_140712_create_server_settings_table.php index ed2e6d122..30ede3870 100644 --- a/database/migrations/2023_03_24_140712_create_server_settings_table.php +++ b/database/migrations/2023_03_24_140712_create_server_settings_table.php @@ -14,6 +14,8 @@ public function up(): void Schema::create('server_settings', function (Blueprint $table) { $table->id(); $table->string('uuid')->unique(); + + $table->boolean('is_part_of_swarm')->default(false); $table->boolean('is_jump_server')->default(false); $table->boolean('is_build_server')->default(false); $table->boolean('is_validated')->default(false); diff --git a/database/seeders/ServerSeeder.php b/database/seeders/ServerSeeder.php index ea8d389ea..8041d5a4f 100644 --- a/database/seeders/ServerSeeder.php +++ b/database/seeders/ServerSeeder.php @@ -26,7 +26,7 @@ public function run(): void 'team_id' => $root_team->id, 'private_key_id' => $private_key_1->id, 'extra_attributes' => ServerMetadata::from([ - 'proxy' => ProxyTypes::TRAEFIK_V2->value + 'proxy_type' => ProxyTypes::TRAEFIK_V2->value ]), ]); Server::create([ diff --git a/database/seeders/ServerSettingSeeder.php b/database/seeders/ServerSettingSeeder.php index fc59c4d57..e36edcc7a 100644 --- a/database/seeders/ServerSettingSeeder.php +++ b/database/seeders/ServerSettingSeeder.php @@ -19,7 +19,7 @@ public function run(): void $server_2->settings->save(); $server_3 = Server::find(2)->load(['settings']); - $server_3->settings->is_build_server = false; + $server_3->settings->is_part_of_swarm = true; $server_3->settings->is_validated = false; $server_3->settings->save(); } diff --git a/resources/views/livewire/destination/form.blade.php b/resources/views/livewire/destination/form.blade.php index 57f1fadde..3996885a8 100644 --- a/resources/views/livewire/destination/form.blade.php +++ b/resources/views/livewire/destination/form.blade.php @@ -7,8 +7,8 @@ @endif
- - Submit + + Save Delete diff --git a/resources/views/livewire/destination/new/standalone-docker.blade.php b/resources/views/livewire/destination/new/standalone-docker.blade.php index 023d7d4ba..13877a265 100644 --- a/resources/views/livewire/destination/new/standalone-docker.blade.php +++ b/resources/views/livewire/destination/new/standalone-docker.blade.php @@ -4,10 +4,11 @@ @foreach ($servers as $server) + @endforeach - + Submit diff --git a/resources/views/livewire/private-key/change.blade.php b/resources/views/livewire/private-key/change.blade.php index 931a82c86..031be1c24 100644 --- a/resources/views/livewire/private-key/change.blade.php +++ b/resources/views/livewire/private-key/change.blade.php @@ -1,14 +1,16 @@
-
+ - - - Submit - - - Delete - + +
+ + Save + + + Delete + +
diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php index d24d816b4..af5e205cc 100644 --- a/resources/views/livewire/server/form.blade.php +++ b/resources/views/livewire/server/form.blade.php @@ -1,27 +1,12 @@
-
-
-
Server
- Submit - - Delete - -
-
- @if ($server->settings->is_validated) -
Validated
- @else -
Not validated
- @endif -
-
-
+
@if ($server->id === 0) @@ -35,19 +20,34 @@ @endif
-
- Validate Server - Install Docker + +
+ Save + + + @if ($server->settings->is_validated) + Check Connection + @else + Validate Server + @endif + + + {{-- Install Docker --}} + + Delete + +
+
+ @isset($uptime) +

Connection: OK

+

Uptime: {{ $uptime }}

+ @endisset + @isset($dockerVersion) +

Docker Engine {{ $dockerVersion }}

+ @endisset + @isset($dockerComposeVersion) +

{{ $dockerComposeVersion }}

+ @endisset
- - @isset($uptime) -

Uptime: {{ $uptime }}

- @endisset - @isset($dockerVersion) -

Docker Engine: {{ $dockerVersion }}

- @endisset - @isset($dockerComposeVersion) -

Docker Compose: {{ $dockerComposeVersion }}

- @endisset
diff --git a/resources/views/livewire/server/new/by-ip.blade.php b/resources/views/livewire/server/new/by-ip.blade.php index feb27ab27..ecb5dea2a 100644 --- a/resources/views/livewire/server/new/by-ip.blade.php +++ b/resources/views/livewire/server/new/by-ip.blade.php @@ -7,7 +7,7 @@ - + + Save diff --git a/resources/views/livewire/source/github/change.blade.php b/resources/views/livewire/source/github/change.blade.php index 0f6fbc2ff..46e31c850 100644 --- a/resources/views/livewire/source/github/change.blade.php +++ b/resources/views/livewire/source/github/change.blade.php @@ -1,9 +1,8 @@
-

Change Github App

- + @if ($github_app->app_id) @@ -14,19 +13,24 @@ + @if ($github_app->app_id) - Save - - Delete - - @else +
- Save + Save + + Delete + +
+ @else + +
+ Save Delete diff --git a/resources/views/server/show.blade.php b/resources/views/server/show.blade.php index 83c56598d..6d8878ab1 100644 --- a/resources/views/server/show.blade.php +++ b/resources/views/server/show.blade.php @@ -1,30 +1,67 @@ - -
-

Private Key

- - Change - -
-

{{ $server->privateKey->name }}

-
-

Destinations

- - New - -
- @if ($server->standaloneDockers->count() > 0) - @foreach ($server->standaloneDockers as $docker) -

Network: {{ data_get($docker, 'network') }}

- @endforeach - @else -

No destinations found

- @endif -
-

Proxy

+
Server
+
@if ($server->settings->is_validated) -
{{ $server->extra_attributes->proxy_status }}
+
Validated
+ @else +
Not validated
@endif
- +
+ +
+

General Configurations

+ +
+
+
+

Private Keys

+ + Change + +
+

{{ $server->privateKey->name }}

+
+
+
+

Destinations

+ + New + +
+ @if ($server->standaloneDockers->count() > 0) + @foreach ($server->standaloneDockers as $docker) +

Network: {{ data_get($docker, 'network') }}

+ @endforeach + @else +

No destinations found

+ @endif +
+
+
+

Proxy

+ @if ($server->settings->is_validated) +
{{ $server->extra_attributes->proxy_status }}
+ @endif +
+ +
+ +
+ + + diff --git a/resources/views/source/github/show.blade.php b/resources/views/source/github/show.blade.php index b7c0b0e0b..dec78d335 100644 --- a/resources/views/source/github/show.blade.php +++ b/resources/views/source/github/show.blade.php @@ -57,11 +57,11 @@ function createGithubApp() { @elseif($github_app->app_id && !$github_app->installation_id) - Install Repositories + Install Repositories @elseif($github_app->app_id && $github_app->installation_id) - Update Repositories + Update Repositories @endif