From baa236f9343730fddad42f805c26a0059c216b29 Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Wed, 11 Sep 2024 16:46:14 +0200 Subject: [PATCH 1/9] Feat: Add debug bar --- composer.json | 3 +- composer.lock | 154 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 155 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 7ca65babe..09e7f08e8 100644 --- a/composer.json +++ b/composer.json @@ -48,6 +48,7 @@ "zircote/swagger-php": "^4.10" }, "require-dev": { + "barryvdh/laravel-debugbar": "^3.13", "fakerphp/faker": "^v1.21.0", "laravel/dusk": "^v8.0", "laravel/pint": "^1.16", @@ -110,4 +111,4 @@ }, "minimum-stability": "stable", "prefer-stable": true -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index 4deaa42de..c3f521de0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "96f8146407d0e6e897ff097c5eccd3a4", + "content-hash": "42c28ab141b70fcabf75b51afa96c670", "packages": [ { "name": "amphp/amp", @@ -11895,6 +11895,90 @@ } ], "packages-dev": [ + { + "name": "barryvdh/laravel-debugbar", + "version": "v3.13.5", + "source": { + "type": "git", + "url": "https://github.com/barryvdh/laravel-debugbar.git", + "reference": "92d86be45ee54edff735e46856f64f14b6a8bb07" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/92d86be45ee54edff735e46856f64f14b6a8bb07", + "reference": "92d86be45ee54edff735e46856f64f14b6a8bb07", + "shasum": "" + }, + "require": { + "illuminate/routing": "^9|^10|^11", + "illuminate/session": "^9|^10|^11", + "illuminate/support": "^9|^10|^11", + "maximebf/debugbar": "~1.22.0", + "php": "^8.0", + "symfony/finder": "^6|^7" + }, + "require-dev": { + "mockery/mockery": "^1.3.3", + "orchestra/testbench-dusk": "^5|^6|^7|^8|^9", + "phpunit/phpunit": "^9.6|^10.5", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.13-dev" + }, + "laravel": { + "providers": [ + "Barryvdh\\Debugbar\\ServiceProvider" + ], + "aliases": { + "Debugbar": "Barryvdh\\Debugbar\\Facades\\Debugbar" + } + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Barryvdh\\Debugbar\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "PHP Debugbar integration for Laravel", + "keywords": [ + "debug", + "debugbar", + "laravel", + "profiler", + "webprofiler" + ], + "support": { + "issues": "https://github.com/barryvdh/laravel-debugbar/issues", + "source": "https://github.com/barryvdh/laravel-debugbar/tree/v3.13.5" + }, + "funding": [ + { + "url": "https://fruitcake.nl", + "type": "custom" + }, + { + "url": "https://github.com/barryvdh", + "type": "github" + } + ], + "time": "2024-04-12T11:20:37+00:00" + }, { "name": "brianium/paratest", "version": "v7.4.3", @@ -12373,6 +12457,74 @@ }, "time": "2024-08-06T15:11:54+00:00" }, + { + "name": "maximebf/debugbar", + "version": "v1.22.5", + "source": { + "type": "git", + "url": "https://github.com/maximebf/php-debugbar.git", + "reference": "1b5cabe0ce013134cf595bfa427bbf2f6abcd989" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/1b5cabe0ce013134cf595bfa427bbf2f6abcd989", + "reference": "1b5cabe0ce013134cf595bfa427bbf2f6abcd989", + "shasum": "" + }, + "require": { + "php": "^7.2|^8", + "psr/log": "^1|^2|^3", + "symfony/var-dumper": "^4|^5|^6|^7" + }, + "require-dev": { + "dbrekelmans/bdi": "^1", + "phpunit/phpunit": "^8|^9", + "symfony/panther": "^1|^2.1", + "twig/twig": "^1.38|^2.7|^3.0" + }, + "suggest": { + "kriswallsmith/assetic": "The best way to manage assets", + "monolog/monolog": "Log using Monolog", + "predis/predis": "Redis storage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.22-dev" + } + }, + "autoload": { + "psr-4": { + "DebugBar\\": "src/DebugBar/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Maxime Bouroumeau-Fuseau", + "email": "maxime.bouroumeau@gmail.com", + "homepage": "http://maximebf.com" + }, + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "Debug bar in the browser for php application", + "homepage": "https://github.com/maximebf/php-debugbar", + "keywords": [ + "debug", + "debugbar" + ], + "support": { + "issues": "https://github.com/maximebf/php-debugbar/issues", + "source": "https://github.com/maximebf/php-debugbar/tree/v1.22.5" + }, + "time": "2024-09-09T08:05:55+00:00" + }, { "name": "mockery/mockery", "version": "1.6.12", From 26f18e25aad56cb73fe401e7b3de30ae9c4e92fe Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Fri, 27 Sep 2024 16:54:24 +0200 Subject: [PATCH 2/9] Create .gitignore --- storage/debugbar/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 storage/debugbar/.gitignore diff --git a/storage/debugbar/.gitignore b/storage/debugbar/.gitignore new file mode 100644 index 000000000..d6b7ef32c --- /dev/null +++ b/storage/debugbar/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore From b99474ac731ba5f937b4052cf4a6a318ee1110c0 Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Fri, 27 Sep 2024 17:38:34 +0200 Subject: [PATCH 3/9] Fix: Remove memlock as it caused problems for some users --- app/Actions/Database/StartDragonfly.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/Actions/Database/StartDragonfly.php b/app/Actions/Database/StartDragonfly.php index 352c6a59f..3ee46a2e1 100644 --- a/app/Actions/Database/StartDragonfly.php +++ b/app/Actions/Database/StartDragonfly.php @@ -46,9 +46,6 @@ class StartDragonfly 'networks' => [ $this->database->destination->network, ], - 'ulimits' => [ - 'memlock' => '-1', - ], 'labels' => [ 'coolify.managed' => 'true', ], From 795af8de52f3031264646004e02aa7d1b6962959 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Sun, 29 Sep 2024 20:05:02 +0200 Subject: [PATCH 4/9] Make sure key is not created with wrong private_key --- database/seeders/ProductionSeeder.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/database/seeders/ProductionSeeder.php b/database/seeders/ProductionSeeder.php index d0f0f10f4..2c56824c6 100644 --- a/database/seeders/ProductionSeeder.php +++ b/database/seeders/ProductionSeeder.php @@ -106,7 +106,8 @@ class ProductionSeeder extends Seeder $ssh_keys_directory = Storage::disk('ssh-keys')->files(); $coolify_key = collect($ssh_keys_directory)->firstWhere(fn ($item) => str($item)->contains($coolify_key_name)); - $found = PrivateKey::find(0); + $server = Server::find(0); + $found = $server->privateKey; if ($found) { echo 'Private Key found in database.\n'; if ($coolify_key) { @@ -125,17 +126,7 @@ class ProductionSeeder extends Seeder ]); $server->update(['user' => $user]); echo "SSH key found for the Coolify host machine (localhost).\n"; - } else { - PrivateKey::create( - [ - 'id' => 0, - 'team_id' => 0, - 'name' => 'localhost\'s key', - 'description' => 'The private key for the Coolify host machine (localhost).', - 'private_key' => 'Paste here you private key!!', - ] - ); echo "No SSH key found for the Coolify host machine (localhost).\n"; echo "Please read the following documentation (point 3) to fix it: https://coolify.io/docs/knowledge-base/server/openssh/\n"; echo "Your localhost connection won't work until then."; From cccd05f32290f06574a6c3a9dac438a43446f24e Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Sun, 29 Sep 2024 20:12:30 +0200 Subject: [PATCH 5/9] chore: Refactor code to improve SSH key handling and storage --- bootstrap/helpers/shared.php | 6 ++---- database/seeders/PopulateSshKeysDirectorySeeder.php | 1 - database/seeders/ProductionSeeder.php | 8 +------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 350f16837..975edf9ca 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -1236,8 +1236,6 @@ function parseLineForSudo(string $command, Server $server): string function get_public_ips() { try { - echo "Refreshing public ips!\n"; - $settings = \App\Models\InstanceSettings::get(); [$first, $second] = Process::concurrently(function (Pool $pool) { $pool->path(__DIR__)->command('curl -4s https://ifconfig.io'); $pool->path(__DIR__)->command('curl -6s https://ifconfig.io'); @@ -1251,7 +1249,7 @@ function get_public_ips() return; } - $settings->update(['public_ipv4' => $ipv4]); + InstanceSettings::get()->update(['public_ipv4' => $ipv4]); } } catch (\Exception $e) { echo "Error: {$e->getMessage()}\n"; @@ -1266,7 +1264,7 @@ function get_public_ips() return; } - $settings->update(['public_ipv6' => $ipv6]); + InstanceSettings::get()->update(['public_ipv6' => $ipv6]); } } catch (\Throwable $e) { echo "Error: {$e->getMessage()}\n"; diff --git a/database/seeders/PopulateSshKeysDirectorySeeder.php b/database/seeders/PopulateSshKeysDirectorySeeder.php index dc27d21b0..e2543ee02 100644 --- a/database/seeders/PopulateSshKeysDirectorySeeder.php +++ b/database/seeders/PopulateSshKeysDirectorySeeder.php @@ -19,7 +19,6 @@ class PopulateSshKeysDirectorySeeder extends Seeder PrivateKey::chunk(100, function ($keys) { foreach ($keys as $key) { - echo 'Storing key: '.$key->name."\n"; $key->storeInFileSystem(); } }); diff --git a/database/seeders/ProductionSeeder.php b/database/seeders/ProductionSeeder.php index 2c56824c6..206f04d6b 100644 --- a/database/seeders/ProductionSeeder.php +++ b/database/seeders/ProductionSeeder.php @@ -101,19 +101,13 @@ class ProductionSeeder extends Seeder } if (! isCloud() && config('coolify.is_windows_docker_desktop') == false) { - echo "Checking localhost key.\n"; $coolify_key_name = '@host.docker.internal'; $ssh_keys_directory = Storage::disk('ssh-keys')->files(); $coolify_key = collect($ssh_keys_directory)->firstWhere(fn ($item) => str($item)->contains($coolify_key_name)); $server = Server::find(0); $found = $server->privateKey; - if ($found) { - echo 'Private Key found in database.\n'; - if ($coolify_key) { - echo "SSH key found for the Coolify host machine (localhost).\n"; - } - } else { + if (! $found) { if ($coolify_key) { $user = str($coolify_key)->before('@')->after('id.'); $coolify_key = Storage::disk('ssh-keys')->get($coolify_key); From 6fe31c26a33c7648e2d20f1bbf13ada57431477b Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 30 Sep 2024 11:14:40 +0200 Subject: [PATCH 6/9] refactor: remove unnecessary code --- app/Models/EnvironmentVariable.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/Models/EnvironmentVariable.php b/app/Models/EnvironmentVariable.php index 138775aba..9f8e4b342 100644 --- a/app/Models/EnvironmentVariable.php +++ b/app/Models/EnvironmentVariable.php @@ -126,11 +126,6 @@ class EnvironmentVariable extends Model $env = $this->get_real_environment_variables($this->value, $resource); return data_get($env, 'value', $env); - if (is_string($env)) { - return $env; - } - - return $env->value; } ); } From a66011701512c720fe7865d582575bd7685c7274 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 30 Sep 2024 11:14:53 +0200 Subject: [PATCH 7/9] use latest helper in dev --- app/Models/InstanceSettings.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/Models/InstanceSettings.php b/app/Models/InstanceSettings.php index 27a181ee4..6a9876c9b 100644 --- a/app/Models/InstanceSettings.php +++ b/app/Models/InstanceSettings.php @@ -85,4 +85,17 @@ class InstanceSettings extends Model implements SendsEmail return "[{$instanceName}]"; } + + public function helperVersion(): Attribute + { + return Attribute::make( + get: function () { + if (isDev()) { + return 'latest'; + } + + return $this->helper_version; + } + ); + } } From 8385b7dfe89aa4301122c142541793f693801898 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 30 Sep 2024 11:15:23 +0200 Subject: [PATCH 8/9] fix: handle edge case when build variables and env variables are in different format --- bootstrap/helpers/shared.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 975edf9ca..9ff05085a 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -3826,6 +3826,21 @@ function convertComposeEnvironmentToArray($environment) { $convertedServiceVariables = collect([]); if (isAssociativeArray($environment)) { + if ($environment instanceof Collection) { + $changedEnvironment = collect([]); + $environment->each(function ($value, $key) use ($changedEnvironment) { + $parts = explode('=', $value, 2); + if (count($parts) === 2) { + $key = $parts[0]; + $realValue = $parts[1] ?? ''; + $changedEnvironment->put($key, $realValue); + } else { + $changedEnvironment->put($key, $value); + } + }); + + return $changedEnvironment; + } $convertedServiceVariables = $environment; } else { foreach ($environment as $value) { From b6b4d936580b85904f66051f26ae952a2d50cdf3 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 30 Sep 2024 11:58:28 +0200 Subject: [PATCH 9/9] fix: compose based terminal --- .../Shared/ExecuteContainerCommand.php | 35 ++++++++++++------- .../execute-container-command.blade.php | 6 ++-- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/app/Livewire/Project/Shared/ExecuteContainerCommand.php b/app/Livewire/Project/Shared/ExecuteContainerCommand.php index d95443621..90419caed 100644 --- a/app/Livewire/Project/Shared/ExecuteContainerCommand.php +++ b/app/Livewire/Project/Shared/ExecuteContainerCommand.php @@ -11,6 +11,8 @@ use Livewire\Component; class ExecuteContainerCommand extends Component { + public $selected_container = 'default'; + public $container; public Collection $containers; @@ -83,11 +85,14 @@ class ExecuteContainerCommand extends Component $containers = getCurrentApplicationContainerStatus($server, $this->resource->id, includePullrequests: true); } foreach ($containers as $container) { - $payload = [ - 'server' => $server, - 'container' => $container, - ]; - $this->containers = $this->containers->push($payload); + // if container state is running + if (data_get($container, 'State') === 'running') { + $payload = [ + 'server' => $server, + 'container' => $container, + ]; + $this->containers = $this->containers->push($payload); + } } } elseif (data_get($this->parameters, 'database_uuid')) { if ($this->resource->isRunning()) { @@ -100,7 +105,6 @@ class ExecuteContainerCommand extends Component } } elseif (data_get($this->parameters, 'service_uuid')) { $this->resource->applications()->get()->each(function ($application) { - ray($application); if ($application->isRunning()) { $this->containers->push([ 'server' => $this->resource->server, @@ -131,9 +135,14 @@ class ExecuteContainerCommand extends Component #[On('connectToContainer')] public function connectToContainer() { + if ($this->selected_container === 'default') { + $this->dispatch('error', 'Please select a container.'); + + return; + } try { - $container_name = data_get($this->container, 'container.Names'); - if (is_null($container_name)) { + $container = collect($this->containers)->firstWhere('container.Names', $this->selected_container); + if (is_null($container)) { throw new \RuntimeException('Container not found.'); } $server = data_get($this->container, 'server'); @@ -141,11 +150,11 @@ class ExecuteContainerCommand extends Component if ($server->isForceDisabled()) { throw new \RuntimeException('Server is disabled.'); } - - $this->dispatch('send-terminal-command', - true, - $container_name, - $server->uuid, + $this->dispatch( + 'send-terminal-command', + isset($container), + data_get($container, 'container.Names'), + data_get($container, 'server.uuid') ); } catch (\Throwable $e) { diff --git a/resources/views/livewire/project/shared/execute-container-command.blade.php b/resources/views/livewire/project/shared/execute-container-command.blade.php index c98e9ae19..927e795ec 100644 --- a/resources/views/livewire/project/shared/execute-container-command.blade.php +++ b/resources/views/livewire/project/shared/execute-container-command.blade.php @@ -20,9 +20,11 @@ @if (count($containers) > 0)
- - + @foreach ($containers as $container) + @if ($loop->first) + + @endif