fix set custom port or user during boarding

This commit is contained in:
peaklabs-dev
2024-09-10 16:55:34 +02:00
parent 83698ac8f2
commit 91c845732e
3 changed files with 55 additions and 8 deletions

View File

@@ -73,6 +73,8 @@ class Index extends Component
} }
$this->privateKeyName = generate_random_name(); $this->privateKeyName = generate_random_name();
$this->remoteServerName = generate_random_name(); $this->remoteServerName = generate_random_name();
$this->remoteServerPort = $this->remoteServerPort;
$this->remoteServerUser = $this->remoteServerUser;
if (isDev()) { if (isDev()) {
$this->privateKey = '-----BEGIN OPENSSH PRIVATE KEY----- $this->privateKey = '-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
@@ -173,6 +175,8 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==
} }
$this->selectedExistingPrivateKey = $this->createdServer->privateKey->id; $this->selectedExistingPrivateKey = $this->createdServer->privateKey->id;
$this->serverPublicKey = $this->createdServer->privateKey->publicKey(); $this->serverPublicKey = $this->createdServer->privateKey->publicKey();
$this->remoteServerPort = $this->createdServer->port;
$this->remoteServerUser = $this->createdServer->user;
$this->currentState = 'validate-server'; $this->currentState = 'validate-server';
} }
@@ -269,7 +273,7 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==
public function validateServer() public function validateServer()
{ {
try { try {
config()->set('coolify.mux_enabled', false); config()->set('coolify.mux_enabled', true);
// EC2 does not have `uptime` command, lol // EC2 does not have `uptime` command, lol
instant_remote_process(['ls /'], $this->createdServer, true); instant_remote_process(['ls /'], $this->createdServer, true);
@@ -277,9 +281,13 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==
$this->createdServer->settings()->update([ $this->createdServer->settings()->update([
'is_reachable' => true, 'is_reachable' => true,
]); ]);
$this->serverReachable = true;
} catch (\Throwable $e) { } catch (\Throwable $e) {
$this->serverReachable = false; $this->serverReachable = false;
$this->createdServer->delete(); $this->createdServer->settings()->update([
'is_reachable' => false,
]);
return handleError(error: $e, livewire: $this); return handleError(error: $e, livewire: $this);
} }
@@ -296,6 +304,9 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==
]); ]);
$this->getProxyType(); $this->getProxyType();
} catch (\Throwable $e) { } catch (\Throwable $e) {
$this->createdServer->settings()->update([
'is_usable' => false,
]);
return handleError(error: $e, livewire: $this); return handleError(error: $e, livewire: $this);
} }
} }
@@ -349,6 +360,33 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==
); );
} }
public function saveAndValidateServer()
{
$this->validate([
'remoteServerPort' => 'required|integer|min:1|max:65535',
'remoteServerUser' => 'required|string',
]);
if (!$this->createdServer) {
$this->createdServer = Server::create([
'name' => $this->remoteServerName ?? 'New Server',
'ip' => $this->remoteServerHost,
'port' => $this->remoteServerPort,
'user' => $this->remoteServerUser,
'team_id' => currentTeam()->id,
'timezone' => 'UTC',
]);
} else {
$this->createdServer->update([
'port' => $this->remoteServerPort,
'user' => $this->remoteServerUser,
'timezone' => 'UTC',
]);
}
$this->validateServer();
}
private function createNewPrivateKey() private function createNewPrivateKey()
{ {
$this->privateKeyName = generate_random_name(); $this->privateKeyName = generate_random_name();

View File

@@ -112,6 +112,11 @@ class Server extends BaseModel
'proxy', 'proxy',
]; ];
protected $fillable = [
'port',
'user',
];
protected $guarded = []; protected $guarded = [];
public static function isReachable() public static function isReachable()
@@ -143,7 +148,11 @@ class Server extends BaseModel
public function settings() public function settings()
{ {
return $this->hasOne(ServerSetting::class); return $this->hasOne(ServerSetting::class)->withDefault([
'force_disabled' => false,
'is_reachable' => false,
'is_usable' => false,
]);
} }
public function setupDefault404Redirect() public function setupDefault404Redirect()

View File

@@ -64,9 +64,9 @@
<p class="mb-4">Please check the connection details below and correct them if they are incorrect.</p> <p class="mb-4">Please check the connection details below and correct them if they are incorrect.</p>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4"> <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
<x-forms.input placeholder="Default is 22" label="Port" id="remoteServerPort" wire:model="remoteServerPort" value="{{ $createdServer->port }}" /> <x-forms.input placeholder="Default is 22" label="Port" id="remoteServerPort" wire:model.live="remoteServerPort" />
<div> <div>
<x-forms.input placeholder="Default is root" label="User" id="remoteServerUser" wire:model="remoteServerUser" value="{{ $createdServer->user }}" /> <x-forms.input placeholder="Default is root" label="User" id="remoteServerUser" wire:model.live="remoteServerUser" />
<p class="text-xs mt-1"> <p class="text-xs mt-1">
Non-root user is experimental: Non-root user is experimental:
<a class="font-bold underline" target="_blank" href="https://coolify.io/docs/knowledge-base/server/non-root-user">docs</a> <a class="font-bold underline" target="_blank" href="https://coolify.io/docs/knowledge-base/server/non-root-user">docs</a>
@@ -88,7 +88,7 @@
<x-forms.input readonly id="serverPublicKey" class="mb-4" label="Current Public Key"></x-forms.input> <x-forms.input readonly id="serverPublicKey" class="mb-4" label="Current Public Key"></x-forms.input>
<x-forms.button class="w-full md:w-auto box-boarding" wire:target="setServerType('localhost')" wire:click="setServerType('localhost')"> <x-forms.button class="w-full md:w-auto box-boarding" wire:click="saveAndValidateServer">
Check again Check again
</x-forms.button> </x-forms.button>
</div> </div>
@@ -236,9 +236,9 @@
Advanced Settings Advanced Settings
</button> </button>
<div x-show="showAdvanced" class="flex flex-col gap-2 lg:flex-row"> <div x-show="showAdvanced" class="flex flex-col gap-2 lg:flex-row">
<x-forms.input placeholder="Port number of your server. Default is 22." label="Port" id="remoteServerPort" wire:model="remoteServerPort" /> <x-forms.input placeholder="Port number of your server. Default is 22." label="Port" id="remoteServerPort" wire:model.lazy="remoteServerPort" />
<div class="w-full"> <div class="w-full">
<x-forms.input placeholder="User to connect to your server. Default is root." label="User" id="remoteServerUser" wire:model="remoteServerUser" /> <x-forms.input placeholder="User to connect to your server. Default is root." label="User" id="remoteServerUser" wire:model.lazy="remoteServerUser" />
<div class="text-xs text-gray-600 dark:text-gray-300">Non-root user is experimental: <a class="font-bold underline" target="_blank" href="https://coolify.io/docs/knowledge-base/server/non-root-user">docs</a>. <div class="text-xs text-gray-600 dark:text-gray-300">Non-root user is experimental: <a class="font-bold underline" target="_blank" href="https://coolify.io/docs/knowledge-base/server/non-root-user">docs</a>.
</div> </div>
</div> </div>