From e1468da36ac9b7f05f5348bea8ac8521241e5ed1 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 12 Feb 2024 11:46:36 +0100 Subject: [PATCH] feat: add proxy start to server validation fix: boarding flow updated --- app/Livewire/Boarding/Index.php | 37 +++++---------- app/Livewire/Project/Application/Heading.php | 8 ++-- app/Livewire/Project/Shared/Destination.php | 5 ++- app/Livewire/Server/Proxy/Status.php | 2 +- app/Livewire/Server/ValidateAndInstall.php | 10 +++++ app/Models/Application.php | 5 +-- .../components/applications/links.blade.php | 28 ++++++++++-- resources/views/components/navbar.blade.php | 12 ++++- .../views/components/slide-over.blade.php | 4 +- .../views/livewire/boarding/index.blade.php | 45 +++++++++++-------- .../livewire/project/new/select.blade.php | 8 ++-- .../project/shared/destination.blade.php | 16 ++++--- .../views/livewire/server/form.blade.php | 2 +- .../livewire/server/proxy/deploy.blade.php | 5 +-- .../server/validate-and-install.blade.php | 24 ++++++++++ 15 files changed, 134 insertions(+), 77 deletions(-) diff --git a/app/Livewire/Boarding/Index.php b/app/Livewire/Boarding/Index.php index eee62c93d..8cb1dd7d2 100644 --- a/app/Livewire/Boarding/Index.php +++ b/app/Livewire/Boarding/Index.php @@ -3,6 +3,7 @@ namespace App\Livewire\Boarding; use App\Actions\Server\InstallDocker; +use App\Enums\ProxyTypes; use App\Models\PrivateKey; use App\Models\Project; use App\Models\Server; @@ -121,15 +122,16 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== } $this->selectedExistingPrivateKey = $this->createdServer->privateKey->id; $this->serverPublicKey = $this->createdServer->privateKey->publicKey(); - $this->validateServer(); + $this->installServer(); } public function getProxyType() { - $proxyTypeSet = $this->createdServer->proxy->type; - if (!$proxyTypeSet) { - $this->currentState = 'select-proxy'; - return; - } + $this->selectProxy(ProxyTypes::TRAEFIK_V2->value); + // $proxyTypeSet = $this->createdServer->proxy->type; + // if (!$proxyTypeSet) { + // $this->currentState = 'select-proxy'; + // return; + // } $this->getProjects(); } public function selectExistingPrivateKey() @@ -193,7 +195,7 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== $this->createdServer->settings->is_cloudflare_tunnel = $this->isCloudflareTunnel; $this->createdServer->settings->save(); $this->createdServer->addInitialNetwork(); - $this->validateServer(); + $this->currentState = 'validate-server'; } public function installServer() { @@ -219,7 +221,7 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== $dockerVersion = instant_remote_process(["docker version|head -2|grep -i version| awk '{print $2}'"], $this->createdServer, true); $dockerVersion = checkMinimumDockerEngineVersion($dockerVersion); if (is_null($dockerVersion)) { - $this->currentState = 'install-docker'; + $this->currentState = 'validate-server'; throw new \Exception('Docker not found or old version is installed.'); } $this->createdServer->settings()->update([ @@ -227,27 +229,10 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== ]); $this->getProxyType(); } catch (\Throwable $e) { - // $this->dockerInstallationStarted = false; return handleError(error: $e, livewire: $this); } } - public function installDocker() - { - try { - $this->dockerInstallationStarted = true; - $activity = InstallDocker::run($this->createdServer); - $this->dispatch('installDocker'); - $this->dispatch('activityMonitor', $activity->id); - } catch (\Throwable $e) { - $this->dockerInstallationStarted = false; - return handleError(error: $e, livewire: $this); - } - } - public function dockerInstalledOrSkipped() - { - $this->validateServer(); - } - public function selectProxy(string|null $proxyType = null) + public function selectProxy(?string $proxyType = null) { if (!$proxyType) { return $this->getProjects(); diff --git a/app/Livewire/Project/Application/Heading.php b/app/Livewire/Project/Application/Heading.php index 1b19c445a..01ab13c4e 100644 --- a/app/Livewire/Project/Application/Heading.php +++ b/app/Livewire/Project/Application/Heading.php @@ -56,15 +56,15 @@ class Heading extends Component return; } if ($this->application->destination->server->isSwarm() && str($this->application->docker_registry_image_name)->isEmpty()) { - $this->dispatch('error', 'Failed to deploy', 'To deploy to a Swarm cluster you must set a Docker image name first.'); + $this->dispatch('error', 'Failed to deploy.', 'To deploy to a Swarm cluster you must set a Docker image name first.'); return; } if (data_get($this->application, 'settings.is_build_server_enabled') && str($this->application->docker_registry_image_name)->isEmpty()) { - $this->dispatch('error', 'Failed to deploy', 'To use a build server, you must first set a Docker image.
More information here: documentation'); + $this->dispatch('error', 'Failed to deploy.', 'To use a build server, you must first set a Docker image.
More information here: documentation'); return; } if ($this->application->additional_servers->count() > 0 && str($this->application->docker_registry_image_name)->isEmpty()) { - $this->dispatch('error', 'Failed to deploy', 'To deploy to more than one server, you must first set a Docker image.
More information here: documentation'); + $this->dispatch('error', 'Failed to deploy.', 'Before deploying to multiple servers, you must first set a Docker image in the General tab.
More information here: documentation'); return; } $this->setDeploymentUuid(); @@ -103,7 +103,7 @@ class Heading extends Component public function restart() { if ($this->application->additional_servers->count() > 0 && str($this->application->docker_registry_image_name)->isEmpty()) { - $this->dispatch('error', 'Failed to deploy', 'To deploy to more than one server, you must first set a Docker image.
More information here: documentation'); + $this->dispatch('error', 'Failed to deploy', 'Before deploying to multiple servers, you must first set a Docker image in the General tab.
More information here: documentation'); return; } $this->setDeploymentUuid(); diff --git a/app/Livewire/Project/Shared/Destination.php b/app/Livewire/Project/Shared/Destination.php index cf5e2632f..3d816149b 100644 --- a/app/Livewire/Project/Shared/Destination.php +++ b/app/Livewire/Project/Shared/Destination.php @@ -37,10 +37,13 @@ class Destination extends Component $this->networks = $this->networks->reject(function ($network) use ($all_networks) { return $all_networks->pluck('id')->contains($network->id); }); - } public function redeploy(int $network_id, int $server_id) { + if ($this->resource->additional_servers->count() > 0 && str($this->resource->docker_registry_image_name)->isEmpty()) { + $this->dispatch('error', 'Failed to deploy.', 'Before deploying to multiple servers, you must first set a Docker image in the General tab.
More information here: documentation'); + return; + } $deployment_uuid = new Cuid2(7); $server = Server::find($server_id); $destination = StandaloneDocker::find($network_id); diff --git a/app/Livewire/Server/Proxy/Status.php b/app/Livewire/Server/Proxy/Status.php index a41994c8f..bd0ffe431 100644 --- a/app/Livewire/Server/Proxy/Status.php +++ b/app/Livewire/Server/Proxy/Status.php @@ -12,7 +12,7 @@ class Status extends Component public Server $server; public bool $polling = false; public int $numberOfPolls = 0; - protected $listeners = ['proxyStatusUpdated', 'startProxyPolling']; + protected $listeners = ['proxyStatusUpdated' => '$refresh', 'startProxyPolling']; public function startProxyPolling() { diff --git a/app/Livewire/Server/ValidateAndInstall.php b/app/Livewire/Server/ValidateAndInstall.php index ca81487a8..4d37feca2 100644 --- a/app/Livewire/Server/ValidateAndInstall.php +++ b/app/Livewire/Server/ValidateAndInstall.php @@ -2,6 +2,7 @@ namespace App\Livewire\Server; +use App\Actions\Proxy\StartProxy; use App\Models\Server; use Livewire\Component; @@ -16,17 +17,21 @@ class ValidateAndInstall extends Component public $docker_installed = null; public $docker_compose_installed = null; public $docker_version = null; + public $proxy_started = false; public $error = null; protected $listeners = ['validateServer' => 'init', 'validateDockerEngine', 'validateServerNow' => 'validateServer']; public function init(bool $install = true) { + $this->install = $install; $this->uptime = null; $this->supported_os_type = null; $this->docker_installed = null; $this->docker_version = null; + $this->docker_compose_installed = null; + $this->proxy_started = null; $this->error = null; $this->number_of_tries = 0; $this->dispatch('validateServerNow'); @@ -44,6 +49,11 @@ class ValidateAndInstall extends Component if ($swarmInstalled) { $this->dispatch('success', 'Docker Swarm is initiated.'); } + } else { + $proxy = StartProxy::run($this->server); + if ($proxy) { + $this->proxy_started = true; + } } } catch (\Throwable $e) { return handleError($e, $this); diff --git a/app/Models/Application.php b/app/Models/Application.php index 959d06d7f..0ba1d24d1 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -200,9 +200,6 @@ class Application extends BaseModel set: fn ($value) => $value === "" ? null : $value, ); } - - // Normal Deployments - public function portsMappingsArray(): Attribute { return Attribute::make( @@ -214,7 +211,7 @@ class Application extends BaseModel } public function realStatus() { - return $this->getRawOriginal('status'); + return $this->getRawOriginal('status'); } public function status(): Attribute { diff --git a/resources/views/components/applications/links.blade.php b/resources/views/components/applications/links.blade.php index a6e4b5c82..92acb01a2 100644 --- a/resources/views/components/applications/links.blade.php +++ b/resources/views/components/applications/links.blade.php @@ -28,8 +28,8 @@ + stroke-width="1.5" stroke="currentColor" fill="none" + stroke-linecap="round" stroke-linejoin="round"> @@ -84,7 +84,7 @@ @endif @if (data_get($application, 'ports_mappings_array')) @foreach ($application->ports_mappings_array as $port) - @if (isDev()) + @if ($application->destination->server->id === 0)
  • @@ -114,9 +114,29 @@ - Port {{ $port }} + {{ $application->destination->server->ip }}:{{ explode(':', $port)[0] }}
  • + @if (count($application->additional_servers) > 0) + @foreach ($application->additional_servers as $server) +
  • + + + + + + + + {{ $server->ip }}:{{ explode(':', $port)[0] }} + +
  • + @endforeach + @endif @endif @endforeach @endif diff --git a/resources/views/components/navbar.blade.php b/resources/views/components/navbar.blade.php index 456d2347f..39a022dc4 100644 --- a/resources/views/components/navbar.blade.php +++ b/resources/views/components/navbar.blade.php @@ -136,6 +136,7 @@ @endif + @if (isInstanceAdmin())
  • @@ -152,7 +153,16 @@
  • @endif - +
  • + + + + + Boarding + +
  • diff --git a/resources/views/components/slide-over.blade.php b/resources/views/components/slide-over.blade.php index a77e71507..5ea4dfe65 100644 --- a/resources/views/components/slide-over.blade.php +++ b/resources/views/components/slide-over.blade.php @@ -1,4 +1,4 @@ -@props(['closeWithX' => 'false', 'fullScreen' => 'false']) +@props(['closeWithX' => false, 'fullScreen' => false])
    @@ -19,7 +19,7 @@ x-transition:leave-start="translate-x-0" x-transition:leave-end="translate-x-full" @class([ 'max-w-md w-screen' => !$fullScreen, - 'max-w-7xl w-screen' => $fullScreen, + 'max-w-4xl w-screen' => $fullScreen, ])>
    diff --git a/resources/views/livewire/boarding/index.blade.php b/resources/views/livewire/boarding/index.blade.php index ca1ab07a0..88ca49bb9 100644 --- a/resources/views/livewire/boarding/index.blade.php +++ b/resources/views/livewire/boarding/index.blade.php @@ -121,18 +121,24 @@ There are already servers available for your Team. Do you want to use one of them? - No (create one for me) - -
    -
    - - @foreach ($servers as $server) - - @endforeach - - Use this Server -
    +
    +
    + No (create one + for + me) + +
    +
    +
    + + @foreach ($servers as $server) + + @endforeach + + Use this Server +
    +
    @if (!$serverReachable) This server is not reachable with the following public key. @@ -216,7 +222,7 @@ helper="If you are using Cloudflare Tunnels, enable this. It will proxy all ssh requests to your server through Cloudflare.
    Coolify does not install/setup Cloudflare (cloudflared) on your server." id="isCloudflareTunnel" label="Cloudflare Tunnel" />
    - Check Connection + Continue
    @@ -227,14 +233,15 @@ @endif
    - @if ($currentState === 'install-docker') - + @if ($currentState === 'validate-server') + - Could not find Docker Engine on your server. Do you want me to install it for you? + I need to validate your server (connection, Docker Engine, etc) and configure if something is + missing for me. Are you okay with this? - Configuring Server + Validating & Configuring @@ -254,7 +261,7 @@ @endif
    -
    + {{--
    @if ($currentState === 'select-proxy') @@ -281,7 +288,7 @@ @endif -
    +
    --}}
    @if ($currentState === 'create-project') diff --git a/resources/views/livewire/project/new/select.blade.php b/resources/views/livewire/project/new/select.blade.php index 9ec9d06c4..ecb1c71ff 100644 --- a/resources/views/livewire/project/new/select.blade.php +++ b/resources/views/livewire/project/new/select.blade.php @@ -213,9 +213,9 @@ @endif --}}
    @forelse($servers as $server) -
    +
    -
    +
    {{ $server->name }}
    @@ -263,13 +263,13 @@ Standalone Docker ({{ $standaloneDocker->name }})
    - network: {{ $standaloneDocker->network }}
    + Network: {{ $standaloneDocker->network }}
    @endforeach @endif + class="items-center justify-center text-center box-without-bg group bg-coollabs hover:bg-coollabs-100">
    + Add New diff --git a/resources/views/livewire/project/shared/destination.blade.php b/resources/views/livewire/project/shared/destination.blade.php index 4c2561950..385183e7c 100644 --- a/resources/views/livewire/project/shared/destination.blade.php +++ b/resources/views/livewire/project/shared/destination.blade.php @@ -55,21 +55,25 @@ @endforeach @endif
    - {{-- @if ($resource->getMorphClass() === 'App\Models\Application') + @if ($resource->getMorphClass() === 'App\Models\Application') @if (count($networks) > 0)

    Choose another server

    (experimental)
    -
    +
    @foreach ($networks as $network)
    - {{ data_get($network, 'server.name') }} - {{ $network->name }} + class="relative flex flex-col text-white cursor-default box w-96"> +
    + Server: {{ data_get($network, 'server.name') }} +
    +
    + Network: {{ data_get($network, 'name') }} +
    @endforeach
    @else
    No additional servers available to attach.
    @endif - @endif --}} + @endif
    diff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.php index 8259a997d..209f951ef 100644 --- a/resources/views/livewire/server/form.blade.php +++ b/resources/views/livewire/server/form.blade.php @@ -19,7 +19,7 @@ @endif @if ((!$server->settings->is_reachable || !$server->settings->is_usable) && $server->id !== 0) - Configuring Server + Validating & Configuring diff --git a/resources/views/livewire/server/proxy/deploy.blade.php b/resources/views/livewire/server/proxy/deploy.blade.php index 0bc0ca1ba..7a27eeab3 100644 --- a/resources/views/livewire/server/proxy/deploy.blade.php +++ b/resources/views/livewire/server/proxy/deploy.blade.php @@ -51,7 +51,7 @@
    @else -
    + @if ($proxy_started) +
    Proxy Started: + + + + +
    + @else + @if ($error) +
    Proxy Started: + +
    + @else +
    + @endif + @endif @else @if ($error)
    Docker Compose is installed:
    @endif @endif + @endif @isset($docker_version)
    Minimum Docker version installed:
    @endisset + @isset($error)
    {!! $error !!}