From 93b202bde45902d53f11653c8a33b151f15714c2 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 18 Sep 2023 12:29:50 +0200 Subject: [PATCH 1/5] fix: convert startProxy to action --- app/Actions/Proxy/StartProxy.php | 4 +++- app/Http/Livewire/Server/Proxy/Deploy.php | 2 +- app/Jobs/ContainerStatusJob.php | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Actions/Proxy/StartProxy.php b/app/Actions/Proxy/StartProxy.php index fd14f49d5..7af5aa019 100644 --- a/app/Actions/Proxy/StartProxy.php +++ b/app/Actions/Proxy/StartProxy.php @@ -6,11 +6,13 @@ use App\Enums\ProxyStatus; use App\Enums\ProxyTypes; use App\Models\Server; use Illuminate\Support\Str; +use Lorisleiva\Actions\Concerns\AsAction; use Spatie\Activitylog\Models\Activity; class StartProxy { - public function __invoke(Server $server, bool $async = true): Activity|string + use AsAction; + public function handle(Server $server, bool $async = true): Activity|string { $proxyType = data_get($server,'proxy.type'); if ($proxyType === 'none') { diff --git a/app/Http/Livewire/Server/Proxy/Deploy.php b/app/Http/Livewire/Server/Proxy/Deploy.php index ad60ca53a..506fd3b81 100644 --- a/app/Http/Livewire/Server/Proxy/Deploy.php +++ b/app/Http/Livewire/Server/Proxy/Deploy.php @@ -27,7 +27,7 @@ class Deploy extends Component SaveConfiguration::run($this->server); } - $activity = resolve(StartProxy::class)($this->server); + $activity = StartProxy::run($this->server); $this->emit('newMonitorActivity', $activity->id); } catch (\Throwable $e) { return handleError($e); diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.php index 20d6640bd..b7c76363c 100644 --- a/app/Jobs/ContainerStatusJob.php +++ b/app/Jobs/ContainerStatusJob.php @@ -82,7 +82,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted })->first(); if (!$foundProxyContainer) { if ($this->server->isProxyShouldRun()) { - resolve(StartProxy::class)($this->server, false); + StartProxy::run($this->server, false); $this->server->team->notify(new ContainerRestarted('coolify-proxy', $this->server)); } } else { From e2ab569244f462a37466c3006fe93c9c728ef1de Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 18 Sep 2023 12:30:49 +0200 Subject: [PATCH 2/5] version++ --- config/sentry.php | 2 +- config/version.php | 2 +- versions.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/sentry.php b/config/sentry.php index ad788a56e..45b51b89b 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.41', + 'release' => '4.0.0-beta.42', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index 9d505bcb9..270d2ee5f 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ Date: Mon, 18 Sep 2023 12:38:11 +0200 Subject: [PATCH 3/5] fix: stop/start UI on apps and dbs --- app/Http/Livewire/Project/Application/Heading.php | 3 ++- app/Http/Livewire/Project/Database/Heading.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Http/Livewire/Project/Application/Heading.php b/app/Http/Livewire/Project/Application/Heading.php index 8c0da7a1e..6bf72e1d0 100644 --- a/app/Http/Livewire/Project/Application/Heading.php +++ b/app/Http/Livewire/Project/Application/Heading.php @@ -68,10 +68,11 @@ class Heading extends Component ["docker rm -f {$containerName}"], $this->application->destination->server ); - $this->application->status = 'stopped'; + $this->application->status = 'exited'; $this->application->save(); // $this->application->environment->project->team->notify(new StatusChanged($this->application)); } } + $this->application->refresh(); } } diff --git a/app/Http/Livewire/Project/Database/Heading.php b/app/Http/Livewire/Project/Database/Heading.php index 60144073e..3389ac80a 100644 --- a/app/Http/Livewire/Project/Database/Heading.php +++ b/app/Http/Livewire/Project/Database/Heading.php @@ -43,7 +43,7 @@ class Heading extends Component stopPostgresProxy($this->database); $this->database->is_public = false; } - $this->database->status = 'stopped'; + $this->database->status = 'exited'; $this->database->save(); $this->check_status(); // $this->database->environment->project->team->notify(new StatusChanged($this->database)); From c023be2348fb7d3b3fd0a4006c61049f32bc9733 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 18 Sep 2023 13:01:01 +0200 Subject: [PATCH 4/5] fix: improve localhost boarding process --- app/Http/Livewire/Boarding/Index.php | 12 +++++++++++- app/Jobs/ApplicationDeploymentJob.php | 2 +- bootstrap/helpers/remoteProcess.php | 4 ++-- resources/views/livewire/boarding/index.blade.php | 12 ++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/Http/Livewire/Boarding/Index.php b/app/Http/Livewire/Boarding/Index.php index bc15c5579..fc1784383 100644 --- a/app/Http/Livewire/Boarding/Index.php +++ b/app/Http/Livewire/Boarding/Index.php @@ -39,6 +39,10 @@ class Index extends Component public ?Project $createdProject = null; public bool $dockerInstallationStarted = false; + + public string $localhostPublicKey; + public bool $localhostReachable = true; + public function mount() { $this->privateKeyName = generate_random_name(); @@ -94,6 +98,7 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== 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(); return $this->validateServer('localhost'); } elseif ($this->selectedServerType === 'remote') { $this->privateKeys = PrivateKey::ownedByCurrentTeam(['name'])->where('id', '!=', 0)->get(); @@ -188,7 +193,7 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== $this->createdServer->save(); $this->validateServer(); } - public function validateServer(?string $type = null) + public function validateServer() { try { $customErrorMessage = "Server is not reachable:"; @@ -199,7 +204,12 @@ uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA== $this->createdServer->settings->update([ 'is_reachable' => true, ]); + } catch (\Throwable $e) { + $this->localhostReachable = false; + return handleError(error: $e, customErrorMessage: $customErrorMessage, livewire: $this); + } + try { $dockerVersion = instant_remote_process(["docker version|head -2|grep -i version| awk '{print $2}'"], $this->createdServer, true); $dockerVersion = checkMinimumDockerEngineVersion($dockerVersion); if (is_null($dockerVersion)) { diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 484c8709e..1054c3f3b 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -89,7 +89,7 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted $this->is_debug_enabled = $this->application->settings->is_debug_enabled; $this->container_name = generateApplicationContainerName($this->application->uuid, $this->pull_request_id); - addPrivateKeyToSshAgent($this->server); + savePrivateKeyToFs($this->server); $this->saved_outputs = collect(); // Set preview fqdn diff --git a/bootstrap/helpers/remoteProcess.php b/bootstrap/helpers/remoteProcess.php index 7017ead10..5982b46d8 100644 --- a/bootstrap/helpers/remoteProcess.php +++ b/bootstrap/helpers/remoteProcess.php @@ -53,7 +53,7 @@ function remote_process( // } // // processWithEnv()->run("echo '{$server->privateKey->private_key}' | ssh-add -d -"); // } -function addPrivateKeyToSshAgent(Server $server) +function savePrivateKeyToFs(Server $server) { if (data_get($server, 'privateKey.private_key') === null) { throw new \Exception("Server {$server->name} does not have a private key"); @@ -70,7 +70,7 @@ function generateSshCommand(Server $server, string $command, bool $isMux = true) { $user = $server->user; $port = $server->port; - $privateKeyLocation = addPrivateKeyToSshAgent($server); + $privateKeyLocation = savePrivateKeyToFs($server); $timeout = config('constants.ssh.command_timeout'); $connectionTimeout = config('constants.ssh.connection_timeout'); $serverInterval = config('constants.ssh.server_interval'); diff --git a/resources/views/livewire/boarding/index.blade.php b/resources/views/livewire/boarding/index.blade.php index 8cd3034eb..b86320612 100644 --- a/resources/views/livewire/boarding/index.blade.php +++ b/resources/views/livewire/boarding/index.blade.php @@ -46,9 +46,21 @@ Localhost + Remote Server + @if (!$localhostReachable) + Localhost is not reachable with the following public key. +

+ 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. + + Check again + + @endif

Servers are the main building blocks, as they will host your applications, databases, From 1093294f067101c7b5849338864d76ac4acbe75f Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 18 Sep 2023 13:06:02 +0200 Subject: [PATCH 5/5] minimum toaster --- config/toaster.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/toaster.php b/config/toaster.php index 950a98a01..13c9200a8 100644 --- a/config/toaster.php +++ b/config/toaster.php @@ -30,7 +30,7 @@ return [ * * Minimum: 3000 (in milliseconds) */ - 'duration' => 1500, + 'duration' => 3000, /** * The horizontal position of each toast.