This commit is contained in:
Andras Bacsai
2023-06-13 10:02:58 +02:00
parent a4177ca0ec
commit e4704fb7e6
16 changed files with 123 additions and 54 deletions

View File

@@ -38,24 +38,29 @@ class StandaloneDocker extends Component
public function submit()
{
$this->validate();
$found = ModelsStandaloneDocker::where('server_id', $this->server_id)->where('network', $this->network)->first();
if ($found) {
$this->addError('network', 'Network already added to this server.');
return;
try {
$found = ModelsStandaloneDocker::where('server_id', $this->server_id)->where('network', $this->network)->first();
if ($found) {
$this->addError('network', 'Network already added to this server.');
return;
}
$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);
$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);
} catch (\Exception $e) {
return general_error_handler(err: $e);
}
$server = Server::find($this->server_id);
instant_remote_process(['docker network create --attachable ' . $this->network], $server, throwError: false);
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);
}
}

View File

@@ -33,7 +33,12 @@ class Server extends BaseModel
{
return $this->extra_attributes->modelScope();
}
public function destinations()
{
$standalone_docker = $this->hasMany(StandaloneDocker::class)->get();
$swarm_docker = $this->hasMany(SwarmDocker::class)->get();
return $standalone_docker->concat($swarm_docker);
}
public function standaloneDockers()
{
return $this->hasMany(StandaloneDocker::class);