Compare commits

...

11 commits

Author SHA1 Message Date
Bobi
91cebadad1
Update app-code-coverage.yml 2024-04-30 01:45:26 +03:00
Bobi
d2104fa2ee
Update app-unit-test.yml 2024-04-30 01:44:16 +03:00
Bobi
78938d2de2
Update app-code-coverage.yml 2024-04-30 01:42:59 +03:00
Bobi
553caf6fbe
Update DockerTest.php 2024-04-30 01:31:34 +03:00
Bozhidar
8d052a4121 Update DockerTest.php 2024-04-30 01:15:46 +03:00
Bozhidar
7fd6dfb6f2 Update DockerTest.php 2024-04-30 01:11:22 +03:00
Bozhidar
e7cec4c7c5 Update DockerTest.php 2024-04-30 01:10:08 +03:00
Bozhidar
ac3abe3e94 Create pint.json 2024-04-30 00:51:26 +03:00
Bozhidar
df1fbba8d5 update 2024-04-30 00:50:50 +03:00
Bozhidar
30a1ed80d5 update 2024-04-30 00:43:30 +03:00
Bozhidar
8dc9b2537b Update DockerTest.php 2024-04-30 00:07:17 +03:00
10 changed files with 121 additions and 42 deletions

View file

@ -63,6 +63,7 @@ jobs:
phyre-php -v
cd /usr/local/phyre/web/
sudo touch /usr/local/phyre/web/storage/installed
sudo chmod -R 777 vendor
composer test:coverage

View file

@ -43,6 +43,7 @@ jobs:
sudo COMPOSER_ALLOW_SUPERUSER=1 phyre-php composer.phar install
sudo /phyre-panel/install_web.sh
sudo touch /usr/local/phyre/web/storage/installed
sudo phyre-php artisan test
compile-phyre-web-panel:

View file

@ -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'));
}
}

View file

@ -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'];

View file

@ -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);

View file

@ -10,7 +10,7 @@ services:
ports:
- {{$externalPort}}:{{ $port }}
@if(isset($environmentVariables))
@if(isset($environmentVariables) && !empty($environmentVariables))
environment:

View file

@ -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');
}
}
}

View file

@ -16,6 +16,9 @@ class BackupTest extends ActionTestCase
{
public function testFullBackup()
{
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 0);
Artisan::call('phyre:run-backup');
$findLastBackup = Backup::orderBy('id', 'asc')->first();

View file

@ -2,23 +2,35 @@
namespace tests\Unit;
use App\Filament\Pages\Modules;
use App\Models\Module;
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\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');
$docker->run();
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 0);
$modulesTest = Livewire::test(Modules::class);
$modulesTest->call('openInstallModal', 'Docker');
$installLogFilePath = $modulesTest->get('installLogFilePath');
$dockerIsInstalled = false;
for ($i = 0; $i < 50; $i++) {
$logFile = file_get_contents('/tmp/phyrepanel-docker-install.log');
for ($i = 0; $i < 400; $i++) {
$modulesTest->call('getInstallLog');
$logFile = file_get_contents($installLogFilePath);
if (strpos($logFile, 'Done!') !== false) {
$dockerIsInstalled = true;
break;
@ -27,11 +39,16 @@ class DockerTest extends TestCase
}
$this->assertTrue($dockerIsInstalled);
$findModule = Module::where('name', 'Docker')->first();
$this->assertNotEmpty($findModule);
$this->actingAs(User::factory()->create());
$livewireCatalogIndex = Livewire::test(DockerCatalog::class)
->set('keyword', 'nginx')
->assertSee('nginx');
$dockerImage = 'nginx';
$dockerCatalogTest = Livewire::test(DockerCatalog::class);
$livewireCatalogIndex = $dockerCatalogTest->set('keyword', $dockerImage)
->assertSee($dockerImage);
$viewData = $livewireCatalogIndex->viewData('dockerImages');
$this->assertNotEmpty($viewData);
@ -39,6 +56,63 @@ class DockerTest extends TestCase
$livewireCatalogIndex->set('keyword', 'non-existing-image')
->assertDontSee('non-existing-image');
}
$pullDockerImage = $dockerCatalogTest->call('pullDockerImage', $dockerImage)
->assertSee('Pull Docker Image');
$isDokerImagePulled = false;
$pullLog = '';
for ($i = 0; $i < 300; $i++) {
$pullLog = @file_get_contents($pullDockerImage->get('pullLogFile'));
if (strpos($pullLog, 'DONE!') !== false) {
$isDokerImagePulled = true;
break;
}
sleep(1);
}
$this->assertTrue($isDokerImagePulled);
$this->assertNotEmpty($pullLog);
$this->assertStringContainsString('DONE!', $pullLog);
$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);
// Unistall docker
$modulesTest = Livewire::test(Modules::class);
$modulesTest->call('openUnistallModal', 'Docker');
}
}

View file

@ -23,6 +23,9 @@ class HostingSubscriptionBackupTest extends ActionTestCase
{
public function testFullBackup()
{
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 0);
$chs = $this->_createHostingSubscription();
Artisan::call('phyre:run-hosting-subscriptions-backup');
@ -110,6 +113,7 @@ class HostingSubscriptionBackupTest extends ActionTestCase
private function _createHostingSubscription()
{
$customer = new Customer();
$customer->name = 'UnitBackupTest' . time();
$customer->email = 'UnitBackupTest' . time() . '@unit-test.com';