From 30a1ed80d5ad3b310e4fd2430c2a2d1a7ab467ff Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Tue, 30 Apr 2024 00:43:30 +0300 Subject: [PATCH] update --- .../Filament/CustomerPanelProvider.php | 16 +++---- .../Docker/App/Models/DockerContainer.php | 2 +- web/Modules/Docker/DockerContainerApi.php | 1 - .../actions/docker-compose-yml.blade.php | 2 +- .../Providers/Filament/AdminPanelProvider.php | 39 ++++++++------- web/tests/Unit/DockerTest.php | 47 ++++++++++++++++++- 6 files changed, 73 insertions(+), 34 deletions(-) diff --git a/web/Modules/Customer/App/Providers/Filament/CustomerPanelProvider.php b/web/Modules/Customer/App/Providers/Filament/CustomerPanelProvider.php index 265735a..4a368c5 100644 --- a/web/Modules/Customer/App/Providers/Filament/CustomerPanelProvider.php +++ b/web/Modules/Customer/App/Providers/Filament/CustomerPanelProvider.php @@ -30,15 +30,13 @@ class CustomerPanelProvider extends PanelProvider $defaultColor = Color::Yellow; $brandLogo = asset('images/phyre-logo.svg'); - if (!app()->runningInConsole()) { - $isAppInstalled = file_exists(storage_path('installed')); - if ($isAppInstalled) { - if (setting('general.brand_logo_url')) { - $brandLogo = setting('general.brand_logo_url'); - } - if (setting('general.brand_primary_color')) { - $defaultColor = Color::hex(setting('general.brand_primary_color')); - } + $isAppInstalled = file_exists(storage_path('installed')); + if ($isAppInstalled) { + if (setting('general.brand_logo_url')) { + $brandLogo = setting('general.brand_logo_url'); + } + if (setting('general.brand_primary_color')) { + $defaultColor = Color::hex(setting('general.brand_primary_color')); } } diff --git a/web/Modules/Docker/App/Models/DockerContainer.php b/web/Modules/Docker/App/Models/DockerContainer.php index 0bf450e..00adc22 100644 --- a/web/Modules/Docker/App/Models/DockerContainer.php +++ b/web/Modules/Docker/App/Models/DockerContainer.php @@ -91,7 +91,7 @@ class DockerContainer extends Model $createContainer = $dockerContainerApi->run(); if (!isset($createContainer['ID'])) { - return false; + throw new \Exception('Failed to create container'); } $model->image = $createContainer['Image']; diff --git a/web/Modules/Docker/DockerContainerApi.php b/web/Modules/Docker/DockerContainerApi.php index 328eb38..2f35c60 100644 --- a/web/Modules/Docker/DockerContainerApi.php +++ b/web/Modules/Docker/DockerContainerApi.php @@ -90,7 +90,6 @@ class DockerContainerApi $output = shell_exec("cd $dockerContaienrPath && docker-compose up -d"); // Get docker container id from output - $dockerContainerId = trim($output); $output = shell_exec('docker ps --format json --filter name='.$this->name); $output = json_decode($output, true); diff --git a/web/Modules/Docker/resources/views/actions/docker-compose-yml.blade.php b/web/Modules/Docker/resources/views/actions/docker-compose-yml.blade.php index 7c11a56..9914f7f 100644 --- a/web/Modules/Docker/resources/views/actions/docker-compose-yml.blade.php +++ b/web/Modules/Docker/resources/views/actions/docker-compose-yml.blade.php @@ -10,7 +10,7 @@ services: ports: - {{$externalPort}}:{{ $port }} - @if(isset($environmentVariables)) + @if(isset($environmentVariables) && !empty($environmentVariables)) environment: diff --git a/web/app/Providers/Filament/AdminPanelProvider.php b/web/app/Providers/Filament/AdminPanelProvider.php index 29e85fc..68ad812 100644 --- a/web/app/Providers/Filament/AdminPanelProvider.php +++ b/web/app/Providers/Filament/AdminPanelProvider.php @@ -97,26 +97,25 @@ class AdminPanelProvider extends PanelProvider $defaultColor = Color::Yellow; $brandLogo = asset('images/phyre-logo.svg'); - if (!app()->runningInConsole()) { - $isAppInstalled = file_exists(storage_path('installed')); - if ($isAppInstalled) { - if (setting('general.brand_logo_url')) { - $brandLogo = setting('general.brand_logo_url'); - } - if (setting('general.brand_primary_color')) { - $defaultColor = Color::hex(setting('general.brand_primary_color')); - } - $findModules = Module::where('installed', 1)->get(); - if ($findModules->count() > 0) { - foreach ($findModules as $module) { - $modulePathClusters = module_path($module->name, 'Filament/Clusters'); - if (is_dir($modulePathClusters)) { - $panel->discoverClusters(in: $modulePathClusters, for: 'Modules\\' . $module->name . '\\Filament\\Clusters'); - } - $modulePathPages = module_path($module->name, 'Filament/Pages'); - if (is_dir($modulePathPages)) { - $panel->discoverPages(in: $modulePathPages, for: 'Modules\\' . $module->name . '\\Filament\\Pages'); - } + + $isAppInstalled = file_exists(storage_path('installed')); + if ($isAppInstalled) { + if (setting('general.brand_logo_url')) { + $brandLogo = setting('general.brand_logo_url'); + } + if (setting('general.brand_primary_color')) { + $defaultColor = Color::hex(setting('general.brand_primary_color')); + } + $findModules = Module::where('installed', 1)->get(); + if ($findModules->count() > 0) { + foreach ($findModules as $module) { + $modulePathClusters = module_path($module->name, 'Filament/Clusters'); + if (is_dir($modulePathClusters)) { + $panel->discoverClusters(in: $modulePathClusters, for: 'Modules\\' . $module->name . '\\Filament\\Clusters'); + } + $modulePathPages = module_path($module->name, 'Filament/Pages'); + if (is_dir($modulePathPages)) { + $panel->discoverPages(in: $modulePathPages, for: 'Modules\\' . $module->name . '\\Filament\\Pages'); } } } diff --git a/web/tests/Unit/DockerTest.php b/web/tests/Unit/DockerTest.php index c18e75f..cbb60ec 100644 --- a/web/tests/Unit/DockerTest.php +++ b/web/tests/Unit/DockerTest.php @@ -3,15 +3,19 @@ namespace tests\Unit; use App\Models\User; +use Filament\Actions\DeleteAction; use Livewire\Livewire; +use Modules\Docker\App\Models\DockerContainer; use Modules\Docker\Filament\Clusters\Docker\Pages\DockerCatalog; -use Modules\Docker\Filament\Clusters\Docker\Resources\DockerContainerResource; +use Modules\Docker\Filament\Clusters\Docker\Resources\DockerContainerResource\Pages\CreateDockerContainer; +use Modules\Docker\Filament\Clusters\Docker\Resources\DockerContainerResource\Pages\EditDockerContainer; +use Modules\Docker\Filament\Clusters\Docker\Resources\DockerContainerResource\Pages\ListDockerContainers; use Modules\Docker\PostInstall; use Tests\TestCase; class DockerTest extends TestCase { - public function testDocker() + public function testDockerImages() { $docker = new PostInstall(); $docker->setLogFile('/tmp/phyrepanel-docker-install.log'); @@ -62,4 +66,43 @@ class DockerTest extends TestCase } + public function testDockerContainers() + { + $createDockerContainerTest = Livewire::test(CreateDockerContainer::class); + $createDockerContainerTest->assertSee('Create Docker Container'); + + $dockerName = 'nginx-latest-phyre-'.rand(1111,9999); + $create = $createDockerContainerTest->fillForm([ + 'name' => $dockerName, + 'image' => 'nginx', + 'environmentVariables' => [ + 'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + 'NGINX_VERSION' => '1.25.5', + 'NJS_VERSION' => '0.8.4', + 'NJS_RELEASE' => '2~bookworm', + 'PKG_RELEASE' => '1~bookworm', + ], + 'volumeMapping' => [], + 'port' => '83', + 'externalPort' => '3000', + ])->call('create'); + + $this->assertDatabaseHas(DockerContainer::class, [ + 'name' => $dockerName, + ]); + + $listDockerContainersTest = Livewire::test(ListDockerContainers::class); + $listDockerContainersTest->assertSee($dockerName); + + $findDockerContainer = DockerContainer::where('name', $dockerName)->first(); + + $editDockerContainersTest = Livewire::test(EditDockerContainer::class, [ + 'record'=> $findDockerContainer->id + ]); + $editDockerContainersTest->assertSee('Edit Docker Container'); + $editDockerContainersTest->callAction(DeleteAction::class); + + $this->assertModelMissing($findDockerContainer); + + } }