This commit is contained in:
Andras Bacsai
2023-05-16 11:02:51 +02:00
parent 57c64d0b86
commit 752c86d8f7
16 changed files with 165 additions and 92 deletions

View File

@@ -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 @@ class Form extends Component
}
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);
}
}
}

View File

@@ -44,6 +44,10 @@ class StandaloneDocker extends Component
$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 @@ class StandaloneDocker extends Component
'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);
}
}

View File

@@ -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()
{

View File

@@ -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 @@ class ByIp extends Component
'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);

View File

@@ -13,8 +13,16 @@ class StandaloneDocker extends BaseModel
{
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;
}
}