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 @@