fix: boarding again

This commit is contained in:
Andras Bacsai 2023-09-18 14:41:31 +02:00
parent af57b2aa73
commit 9cba0a6df3
7 changed files with 46 additions and 31 deletions

View File

@ -7,7 +7,7 @@
class InstallDocker
{
public function __invoke(Server $server, bool $instant = false)
public function __invoke(Server $server)
{
$dockerVersion = '24.0';
$config = base64_encode('{
@ -55,9 +55,6 @@ public function __invoke(Server $server, bool $instant = false)
"echo '####### Done!'"
];
}
if ($instant) {
return instant_remote_process($command, $server);
}
return remote_process($command, $server);
}
}

View File

@ -17,8 +17,11 @@ public function __construct(
public string $type,
public ?string $type_uuid = null,
public ?Model $model = null,
public string $status = ProcessStatus::QUEUED->value,
public ?string $status = null ,
public bool $ignore_errors = false,
) {
if(is_null($status)){
$this->status = ProcessStatus::QUEUED->value;
}
}
}

View File

@ -9,7 +9,6 @@
use App\Models\Team;
use Illuminate\Support\Collection;
use Livewire\Component;
use Visus\Cuid2\Cuid2;
class Index extends Component
{
@ -40,8 +39,8 @@ class Index extends Component
public bool $dockerInstallationStarted = false;
public string $localhostPublicKey;
public bool $localhostReachable = true;
public string $serverPublicKey;
public bool $serverReachable = true;
public function mount()
{
@ -98,7 +97,7 @@ public function setServerType(string $type)
if (!$this->createdServer) {
return $this->emit('error', 'Localhost server is not found. Something went wrong during installation. Please try to reinstall or contact support.');
}
$this->localhostPublicKey = $this->createdServer->privateKey->publicKey();
$this->serverPublicKey = $this->createdServer->privateKey->publicKey();
return $this->validateServer('localhost');
} elseif ($this->selectedServerType === 'remote') {
$this->privateKeys = PrivateKey::ownedByCurrentTeam(['name'])->where('id', '!=', 0)->get();
@ -123,6 +122,7 @@ public function selectExistingServer()
return;
}
$this->selectedExistingPrivateKey = $this->createdServer->privateKey->id;
$this->serverPublicKey = $this->createdServer->privateKey->publicKey();
$this->validateServer();
}
public function getProxyType()
@ -201,11 +201,11 @@ public function validateServer()
instant_remote_process(['uptime'], $this->createdServer, true);
$this->createdServer->settings->update([
$this->createdServer->settings()->update([
'is_reachable' => true,
]);
} catch (\Throwable $e) {
$this->localhostReachable = false;
$this->serverReachable = false;
return handleError(error: $e, customErrorMessage: $customErrorMessage, livewire: $this);
}
@ -216,8 +216,12 @@ public function validateServer()
$this->currentState = 'install-docker';
throw new \Exception('Docker version is not supported or not installed.');
}
$this->dockerInstalledOrSkipped();
$this->createdServer->settings()->update([
'is_usable' => true,
]);
$this->getProxyType();
} catch (\Throwable $e) {
$this->dockerInstallationStarted = false;
return handleError(error: $e, customErrorMessage: $customErrorMessage, livewire: $this);
}
}
@ -229,10 +233,7 @@ public function installDocker()
}
public function dockerInstalledOrSkipped()
{
$this->createdServer->settings->update([
'is_usable' => true,
]);
$this->getProxyType();
$this->validateServer();
}
public function selectProxy(string|null $proxyType = null)
{

View File

@ -18,12 +18,14 @@
function remote_process(
array $command,
Server $server,
string $type = ActivityTypes::INLINE->value,
?string $type = null,
?string $type_uuid = null,
?Model $model = null,
bool $ignore_errors = false,
): Activity {
if (is_null($type)) {
$type = ActivityTypes::INLINE->value;
}
$command_string = implode("\n", $command);
if (auth()->user()) {
$teams = auth()->user()->teams->pluck('id');

View File

@ -138,5 +138,6 @@ function allowedPathsForBoardingAccounts()
...allowedPathsForUnsubscribedAccounts(),
'boarding',
'livewire/message/boarding.index',
'livewire/message/activity-monitor'
];
}

View File

@ -1,17 +1,17 @@
@extends('layouts.base')
@section('body')
<x-modal noSubmit modalId="installDocker">
<x-slot:modalBody>
<livewire:activity-monitor header="Docker Installation Logs" />
</x-slot:modalBody>
<x-slot:modalSubmit>
<x-forms.button onclick="installDocker.close()" type="submit">
Close
</x-forms.button>
</x-slot:modalSubmit>
</x-modal>
<main class="min-h-screen hero">
<div class="hero-content">
<x-modal modalId="installDocker">
<x-slot:modalBody>
<livewire:activity-monitor header="Docker Installation Logs" />
</x-slot:modalBody>
<x-slot:modalSubmit>
<x-forms.button onclick="installDocker.close()" type="submit">
Close
</x-forms.button>
</x-slot:modalSubmit>
</x-modal>
{{ $slot }}
</div>
</main>

View File

@ -50,13 +50,13 @@
<x-forms.button class="justify-center box" wire:target="setServerType('remote')"
wire:click="setServerType('remote')">Remote Server
</x-forms.button>
@if (!$localhostReachable)
@if (!$serverReachable)
Localhost is not reachable with the following public key.
<br /> <br />
Please make sure you have the correct public key in your ~/.ssh/authorized_keys file for user
'root' or skip the boarding process and add a new private key manually to Coolify and to the
server.
<x-forms.input readonly id="localhostPublicKey"></x-forms.input>
<x-forms.input readonly id="serverPublicKey"></x-forms.input>
<x-forms.button class="box" wire:target="setServerType('localhost')"
wire:click="setServerType('localhost')">Check again
</x-forms.button>
@ -130,6 +130,17 @@
<x-forms.button type="submit">Use this Server</x-forms.button>
</form>
</div>
@if (!$serverReachable)
This server is not reachable with the following public key.
<br /> <br />
Please make sure you have the correct public key in your ~/.ssh/authorized_keys file for user
'root' or skip the boarding process and add a new private key manually to Coolify and to the
server.
<x-forms.input readonly id="serverPublicKey"></x-forms.input>
<x-forms.button class="box" wire:target="validateServer"
wire:click="validateServer">Check again
</x-forms.button>
@endif
</x-slot:actions>
<x-slot:explanation>
<p>Private Keys are used to connect to a remote server through a secure shell, called SSH.</p>
@ -214,10 +225,10 @@
Could not find Docker Engine on your server. Do you want me to install it for you?
</x-slot:question>
<x-slot:actions>
@if ($dockerInstallationStarted)
<x-forms.button class="justify-center box" wire:click="installDocker"
onclick="installDocker.showModal()">
Let's do it!</x-forms.button>
@if ($dockerInstallationStarted)
<x-forms.button class="justify-center box" wire:click="dockerInstalledOrSkipped">
Next</x-forms.button>
@endif