diff --git a/app/Actions/Server/InstallDocker.php b/app/Actions/Server/InstallDocker.php index 2ddda94a8..39d0718db 100644 --- a/app/Actions/Server/InstallDocker.php +++ b/app/Actions/Server/InstallDocker.php @@ -4,11 +4,10 @@ namespace App\Actions\Server; use App\Models\Server; use App\Models\StandaloneDocker; -use App\Models\Team; class InstallDocker { - public function __invoke(Server $server) + public function __invoke(Server $server, bool $instant = false) { $dockerVersion = '24.0'; $config = base64_encode('{ @@ -26,8 +25,9 @@ class InstallDocker 'server_id' => $server->id, ]); } - if (isDev()) { - return remote_process([ + + if (isDev() && $server->id === 0) { + $command = [ "echo '####### Installing Prerequisites...'", "sleep 1", "echo '####### Installing/updating Docker Engine...'", @@ -35,9 +35,9 @@ class InstallDocker "sleep 4", "echo '####### Restarting Docker Engine...'", "ls -l /tmp" - ], $server); + ]; } else { - return remote_process([ + $command = [ "echo '####### Installing Prerequisites...'", "command -v jq >/dev/null || apt-get update", "command -v jq >/dev/null || apt install -y jq", @@ -53,7 +53,11 @@ class InstallDocker "echo '####### Creating default Docker network (coolify)...'", "docker network create --attachable coolify >/dev/null 2>&1 || true", "echo '####### Done!'" - ], $server); + ]; } + if ($instant) { + return instant_remote_process($command, $server); + } + return remote_process($command, $server); } } diff --git a/app/Http/Livewire/Boarding/Index.php b/app/Http/Livewire/Boarding/Index.php index dcf7623d0..bc15c5579 100644 --- a/app/Http/Livewire/Boarding/Index.php +++ b/app/Http/Livewire/Boarding/Index.php @@ -38,6 +38,7 @@ class Index extends Component public ?int $selectedExistingProject = null; public ?Project $createdProject = null; + public bool $dockerInstallationStarted = false; public function mount() { $this->privateKeyName = generate_random_name(); @@ -65,14 +66,14 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== public function restartBoarding() { - if ($this->selectedServerType !== 'localhost') { - if ($this->createdServer) { - $this->createdServer->delete(); - } - if ($this->createdPrivateKey) { - $this->createdPrivateKey->delete(); - } - } + // if ($this->selectedServerType !== 'localhost') { + // if ($this->createdServer) { + // $this->createdServer->delete(); + // } + // if ($this->createdPrivateKey) { + // $this->createdPrivateKey->delete(); + // } + // } return redirect()->route('boarding'); } public function skipBoarding() @@ -118,8 +119,6 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== } $this->selectedExistingPrivateKey = $this->createdServer->privateKey->id; $this->validateServer(); - $this->getProxyType(); - $this->getProjects(); } public function getProxyType() { @@ -132,6 +131,7 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== } public function selectExistingPrivateKey() { + $this->createdPrivateKey = PrivateKey::find($this->selectedExistingPrivateKey); $this->currentState = 'create-server'; } public function createNewServer() @@ -154,6 +154,13 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== 'privateKeyName' => 'required', 'privateKey' => 'required', ]); + $this->createdPrivateKey = PrivateKey::create([ + 'name' => $this->privateKeyName, + 'description' => $this->privateKeyDescription, + 'private_key' => $this->privateKey, + 'team_id' => currentTeam()->id + ]); + $this->createdPrivateKey->save(); $this->currentState = 'create-server'; } public function saveServer() @@ -165,28 +172,20 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== 'remoteServerUser' => 'required', ]); $this->privateKey = formatPrivateKey($this->privateKey); - $this->createdPrivateKey = new PrivateKey(); - $this->createdPrivateKey->private_key = $this->privateKey; - $this->createdPrivateKey->name = $this->privateKeyName; - $this->createdPrivateKey->description = $this->privateKeyDescription; - $this->createdPrivateKey->team_id = currentTeam()->id; $foundServer = Server::whereIp($this->remoteServerHost)->first(); if ($foundServer) { return $this->emit('error', 'IP address is already in use by another team.'); } - $this->createdServer = new Server(); - $this->createdServer->uuid = (string)new Cuid2(7); - $this->createdServer->name = $this->remoteServerName; - $this->createdServer->ip = $this->remoteServerHost; - $this->createdServer->port = $this->remoteServerPort; - $this->createdServer->user = $this->remoteServerUser; - $this->createdServer->description = $this->remoteServerDescription; - $this->createdServer->privateKey = $this->createdPrivateKey; - $this->createdServer->team_id = currentTeam()->id; - - ray($this->createdServer); - - + $this->createdServer = Server::create([ + 'name' => $this->remoteServerName, + 'ip' => $this->remoteServerHost, + 'port' => $this->remoteServerPort, + 'user' => $this->remoteServerUser, + 'description' => $this->remoteServerDescription, + 'private_key_id' => $this->createdPrivateKey->id, + 'team_id' => currentTeam()->id, + ]); + $this->createdServer->save(); $this->validateServer(); } public function validateServer(?string $type = null) @@ -194,47 +193,36 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== try { $customErrorMessage = "Server is not reachable:"; config()->set('coolify.mux_enabled', false); + instant_remote_process(['uptime'], $this->createdServer, true); + + $this->createdServer->settings->update([ + 'is_reachable' => true, + ]); + $dockerVersion = instant_remote_process(["docker version|head -2|grep -i version| awk '{print $2}'"], $this->createdServer, true); $dockerVersion = checkMinimumDockerEngineVersion($dockerVersion); if (is_null($dockerVersion)) { - throw new \Exception('No Docker Engine or older than 23 version installed.'); + $this->currentState = 'install-docker'; + throw new \Exception('Docker version is not supported or not installed.'); } - $customErrorMessage = "Cannot create Server or Private Key. Please try again."; - if ($type !== 'localhost') { - $createdPrivateKey = PrivateKey::create([ - 'name' => $this->privateKeyName, - 'description' => $this->privateKeyDescription, - 'private_key' => $this->privateKey, - 'team_id' => currentTeam()->id - ]); - $server = Server::create([ - 'name' => $this->remoteServerName, - 'ip' => $this->remoteServerHost, - 'port' => $this->remoteServerPort, - 'user' => $this->remoteServerUser, - 'description' => $this->remoteServerDescription, - 'private_key_id' => $createdPrivateKey->id, - 'team_id' => currentTeam()->id, - ]); - $server->settings->is_reachable = true; - $server->settings->is_usable = true; - $server->settings->save(); - } else { - $this->createdServer->settings->update([ - 'is_reachable' => true, - ]); - } - $this->getProxyType(); + $this->dockerInstalledOrSkipped(); } catch (\Throwable $e) { return handleError(error: $e, customErrorMessage: $customErrorMessage, livewire: $this); } } public function installDocker() { + $this->dockerInstallationStarted = true; $activity = resolve(InstallDocker::class)($this->createdServer); $this->emit('newMonitorActivity', $activity->id); - $this->currentState = 'select-proxy'; + } + public function dockerInstalledOrSkipped() + { + $this->createdServer->settings->update([ + 'is_usable' => true, + ]); + $this->getProxyType(); } public function selectProxy(string|null $proxyType = null) { diff --git a/resources/views/layouts/boarding.blade.php b/resources/views/layouts/boarding.blade.php index a63d26a41..39b1ae252 100644 --- a/resources/views/layouts/boarding.blade.php +++ b/resources/views/layouts/boarding.blade.php @@ -1,9 +1,19 @@ @extends('layouts.base') @section('body') -
-
- {{ $slot }} -
-
-@parent +
+
+ + + + + + + Close + + + + {{ $slot }} +
+
+ @parent @endsection diff --git a/resources/views/livewire/boarding/index.blade.php b/resources/views/livewire/boarding/index.blade.php index 45a11c4bd..8cd3034eb 100644 --- a/resources/views/livewire/boarding/index.blade.php +++ b/resources/views/livewire/boarding/index.blade.php @@ -23,9 +23,12 @@ -

You do not to manage your servers too much. Coolify do it for you.

-

All configurations are stored on your server, so everything works without Coolify (except integrations and automations).

-

You will get notified on your favourite platform (Discord, Telegram, Email, etc.) when something goes wrong, or an action needed from your side.

+

You do not to manage your servers too much. Coolify do + it for you.

+

All configurations are stored on your server, so + everything works without Coolify (except integrations and automations).

+

You will get notified on your favourite platform (Discord, + Telegram, Email, etc.) when something goes wrong, or an action needed from your side.

Next @@ -194,16 +197,6 @@
@if ($currentState === 'install-docker') - - - - - - - Close - - - Could not find Docker Engine on your server. Do you want me to install it for you? @@ -211,8 +204,11 @@ - Let's do - it! + Let's do it! + @if ($dockerInstallationStarted) + + Next + @endif

This will install the latest Docker Engine on your server, configure a few things to be able