fix
This commit is contained in:
@@ -14,6 +14,7 @@ class StandaloneDocker extends Component
|
|||||||
public string $network;
|
public string $network;
|
||||||
|
|
||||||
public Collection $servers;
|
public Collection $servers;
|
||||||
|
public Server $server;
|
||||||
public int|null $server_id = null;
|
public int|null $server_id = null;
|
||||||
|
|
||||||
protected $rules = [
|
protected $rules = [
|
||||||
@@ -35,29 +36,31 @@ class StandaloneDocker extends Component
|
|||||||
$this->network = new Cuid2(7);
|
$this->network = new Cuid2(7);
|
||||||
$this->name = generate_random_name();
|
$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()
|
public function submit()
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->validate();
|
$this->validate();
|
||||||
try {
|
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) {
|
if ($found) {
|
||||||
|
$this->createNetworkAndAttachToProxy();
|
||||||
$this->addError('network', 'Network already added to this server.');
|
$this->addError('network', 'Network already added to this server.');
|
||||||
return;
|
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);
|
$this->createNetworkAndAttachToProxy();
|
||||||
|
|
||||||
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
|
|
||||||
]);
|
|
||||||
return redirect()->route('destination.show', $docker->uuid);
|
return redirect()->route('destination.show', $docker->uuid);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return general_error_handler(err: $e);
|
return general_error_handler(err: $e);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if ($destination->getMorphClass() === 'App\Models\StandaloneDocker')
|
@if ($destination->getMorphClass() === 'App\Models\StandaloneDocker')
|
||||||
<div class="pt-2 pb-10 text-sm">Your standalone docker network.</div>
|
<div class="pt-2 pb-10 text-sm">A Docker network in a non-swarm environment</div>
|
||||||
@else
|
@else
|
||||||
<div class="pt-2 pb-10 text-sm">Your swarm docker network. WIP</div>
|
<div class="pt-2 pb-10 text-sm">Your swarm docker network. WIP</div>
|
||||||
@endif
|
@endif
|
||||||
|
|||||||
@@ -6,11 +6,12 @@
|
|||||||
<x-forms.button>Add a new destination</x-forms.button>
|
<x-forms.button>Add a new destination</x-forms.button>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="pt-2 pb-8 text-sm">Docker Networks available on the server</div>
|
<div class="pt-2 pb-6 text-sm">Destinations are used to segregate resources by network.</div>
|
||||||
<div class="pb-10 text-sm">
|
<div class="flex gap-2 text-sm">
|
||||||
|
Docker Networks available on the server:
|
||||||
@forelse ($server->standaloneDockers as $docker)
|
@forelse ($server->standaloneDockers as $docker)
|
||||||
<a href="{{ route('destination.show', ['destination_uuid' => data_get($docker, 'uuid')]) }}">
|
<a href="{{ route('destination.show', ['destination_uuid' => data_get($docker, 'uuid')]) }}">
|
||||||
<x-forms.button>{{ data_get($docker, 'network') }} </x-forms.button>
|
<button class="text-white btn-link">{{ data_get($docker, 'network') }} </button>
|
||||||
</a>
|
</a>
|
||||||
@empty
|
@empty
|
||||||
<div class="text-sm">No destinations added</div>
|
<div class="text-sm">No destinations added</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user