diff --git a/web/Modules/Docker/App/Models/DockerContainer.php b/web/Modules/Docker/App/Models/DockerContainer.php index 00adc22..ef91040 100644 --- a/web/Modules/Docker/App/Models/DockerContainer.php +++ b/web/Modules/Docker/App/Models/DockerContainer.php @@ -89,7 +89,6 @@ class DockerContainer extends Model } $createContainer = $dockerContainerApi->run(); - if (!isset($createContainer['ID'])) { throw new \Exception('Failed to create container'); } diff --git a/web/Modules/Docker/DockerContainerApi.php b/web/Modules/Docker/DockerContainerApi.php index 2f35c60..58cf8b8 100644 --- a/web/Modules/Docker/DockerContainerApi.php +++ b/web/Modules/Docker/DockerContainerApi.php @@ -76,6 +76,7 @@ class DockerContainerApi 'externalPort' => $this->externalPort, 'environmentVariables' => $this->environmentVariables, 'volumeMapping' => $this->volumeMapping, + 'version' => '3' ])->render(); } @@ -84,6 +85,7 @@ class DockerContainerApi shell_exec('mkdir -p ' . $dockerContaienrPath); } + $dockerComposeFile = $dockerContaienrPath . '/docker-compose.yml'; file_put_contents($dockerComposeFile, $dockerComposeFileContent); 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 9914f7f..9c0ecc8 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 @@ -5,12 +5,14 @@ version: '{{$version}}' services: {{$name}}: - image: {{$image}} + image: "{{$image}}" restart: always ports: - {{$externalPort}}:{{ $port }} - @if(isset($environmentVariables) && !empty($environmentVariables)) + @if(isset($environmentVariables) + && !empty($environmentVariables) + && is_array($environmentVariables)) environment: diff --git a/web/tests/Unit/DockerTest.php b/web/tests/Unit/DockerTest.php index 150e807..7829cee 100644 --- a/web/tests/Unit/DockerTest.php +++ b/web/tests/Unit/DockerTest.php @@ -13,6 +13,7 @@ use Modules\Docker\Filament\Clusters\Docker\Resources\DockerContainerResource\Pa 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 Psy\Util\Str; use Tests\TestCase; class DockerTest extends TestCase @@ -23,6 +24,9 @@ class DockerTest extends TestCase ini_set('max_execution_time', 0); $this->actingAs(User::factory()->create()); + if (!is_file('/usr/local/phyre/web/storage/installed')) { + file_put_contents('/usr/local/phyre/web/storage/installed', ''); + } $modulesTest = Livewire::test(Modules::class); $modulesTest->call('openInstallModal', 'Docker'); @@ -59,17 +63,17 @@ class DockerTest extends TestCase $pullDockerImage = $dockerCatalogTest->call('pullDockerImage', $dockerImage) ->assertSee('Pull Docker Image'); - $isDokerImagePulled = false; $pullLog = ''; + $isDockerImagePulled = false; for ($i = 0; $i < 300; $i++) { $pullLog = @file_get_contents($pullDockerImage->get('pullLogFile')); - if (strpos($pullLog, 'DONE!') !== false) { - $isDokerImagePulled = true; + if (str_contains($pullLog, 'DONE!')) { + $isDockerImagePulled = true; break; } sleep(1); } - $this->assertTrue($isDokerImagePulled); + $this->assertTrue($isDockerImagePulled); $this->assertNotEmpty($pullLog); $this->assertStringContainsString('DONE!', $pullLog); @@ -77,7 +81,7 @@ class DockerTest extends TestCase $createDockerContainerTest = Livewire::test(CreateDockerContainer::class); $createDockerContainerTest->assertSee('Create Docker Container'); - $dockerName = 'nginx-latest-phyre-'.rand(1111,9999); + $dockerName = \Illuminate\Support\Str::random(10); $create = $createDockerContainerTest->fillForm([ 'name' => $dockerName, 'image' => 'nginx',