Skip to content

Commit 7f551c0

Browse files
authored
Merge pull request #34 from go0baahh/main
Sail v1.46.0 compose.yaml compatibility
2 parents 0db9b67 + a23f7bc commit 7f551c0

File tree

6 files changed

+61
-17
lines changed

6 files changed

+61
-17
lines changed

src/Console/InstallCommand.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ class InstallCommand extends Command
2424
*
2525
* @return void
2626
*/
27-
public function handle()
27+
public function handle(): void
2828
{
29-
$dockerCompose = file_get_contents($this->laravel->basePath('docker-compose.yml'));
29+
$dockerComposePath = $this->laravel->basePath('docker-compose.yml');
30+
if (!file_exists($dockerComposePath)) {
31+
$dockerComposePath = $this->laravel->basePath('compose.yaml');
32+
}
33+
34+
$dockerCompose = file_get_contents($dockerComposePath);
3035
if (str_contains($dockerCompose, 'nginx:')) {
3136
$this->info('Nginx container is already installed. Do nothing.');
3237
return;
@@ -39,7 +44,7 @@ public function handle()
3944
["services:\n{$nginxStub}", "volumes:\n{$volumeStub}"],
4045
$dockerCompose
4146
);
42-
file_put_contents($this->laravel->basePath('docker-compose.yml'), $dockerCompose);
47+
file_put_contents($dockerComposePath, $dockerCompose);
4348
$this->info('Nginx container successfully installed in Docker Compose.');
4449
}
4550
}

src/Console/PublishCommand.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@ class PublishCommand extends Command
2525
*
2626
* @return void
2727
*/
28-
public function handle()
28+
public function handle(): void
2929
{
30-
$dockerCompose = file_get_contents($this->laravel->basePath('docker-compose.yml'));
30+
$dockerComposePath = $this->laravel->basePath('docker-compose.yml');
31+
if (!file_exists($dockerComposePath)) {
32+
$dockerComposePath = $this->laravel->basePath('compose.yaml');
33+
}
34+
35+
$dockerCompose = file_get_contents($dockerComposePath);
3136
$this->call('vendor:publish', ['--tag' => 'sail-ssl']);
3237
file_put_contents(
33-
$this->laravel->basePath('docker-compose.yml'),
34-
str_replace('./vendor/ryoluo/sail-ssl/nginx/templates', './nginx/templates', $dockerCompose)
38+
$dockerComposePath,
39+
str_replace(
40+
'./vendor/ryoluo/sail-ssl/nginx/templates',
41+
'./nginx/templates',
42+
$dockerCompose
43+
)
3544
);
3645
}
3746
}

src/SailSslServiceProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class SailSslServiceProvider extends ServiceProvider implements DeferrableProvid
1414
*
1515
* @return void
1616
*/
17-
public function boot()
17+
public function boot(): void
1818
{
1919
$this->registerCommands();
2020
$this->configurePublishing();
@@ -25,7 +25,7 @@ public function boot()
2525
*
2626
* @return void
2727
*/
28-
protected function registerCommands()
28+
protected function registerCommands(): void
2929
{
3030
if ($this->app->runningInConsole()) {
3131
$this->commands([
@@ -40,7 +40,7 @@ protected function registerCommands()
4040
*
4141
* @return void
4242
*/
43-
protected function configurePublishing()
43+
protected function configurePublishing(): void
4444
{
4545
if ($this->app->runningInConsole()) {
4646
$this->publishes([
@@ -54,7 +54,7 @@ protected function configurePublishing()
5454
*
5555
* @return array
5656
*/
57-
public function provides()
57+
public function provides(): array
5858
{
5959
return [
6060
InstallCommand::class,

tests/Feature/InstallCommandTest.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ public function test_execute_install_command_successfully()
1111
$this->artisan('sail-ssl:install')
1212
->expectsOutput('Nginx container successfully installed in Docker Compose.')
1313
->assertSuccessful();
14-
$dockerCompose = file_get_contents($this->app->basePath('docker-compose.yml'));
14+
15+
$dockerCompose = $this->app->basePath('docker-compose.yml');
16+
if (!file_exists($dockerCompose)) {
17+
$dockerCompose = $this->app->basePath('compose.yaml');
18+
}
19+
20+
$dockerCompose = file_get_contents($dockerCompose);
1521
$nginxStub = file_get_contents('stubs/nginx.stub');
1622
$volumeStub = file_get_contents('stubs/volume.stub');
1723
$this->assertTrue(str_contains($dockerCompose, $nginxStub));
@@ -21,20 +27,32 @@ public function test_execute_install_command_successfully()
2127
public function test_throw_exception_when_docker_compose_yml_is_not_found()
2228
{
2329
$this->expectException(\ErrorException::class);
24-
unlink($this->app->basePath('docker-compose.yml'));
30+
if (file_exists($this->app->basePath('docker-compose.yml'))) {
31+
unlink($this->app->basePath('docker-compose.yml'));
32+
} else if (file_exists($this->app->basePath('compose.yaml'))) {
33+
unlink($this->app->basePath('compose.yaml'));
34+
}
2535
$this->artisan('sail-ssl:install')->assertFailed();
2636
}
2737

2838
public function test_do_nothing_when_nginx_is_already_installed()
2939
{
3040
// First execution
3141
$this->artisan('sail-ssl:install')->assertSuccessful();
32-
$dockerComposeAfter1stExec = file_get_contents($this->app->basePath('docker-compose.yml'));
42+
$dockerCompose = $this->app->basePath('docker-compose.yml');
43+
if (!file_exists($dockerCompose)) {
44+
$dockerCompose = $this->app->basePath('compose.yaml');
45+
}
46+
$dockerComposeAfter1stExec = file_get_contents($dockerCompose);
3347
// Execute again
3448
$this->artisan('sail-ssl:install')
3549
->expectsOutput('Nginx container is already installed. Do nothing.')
3650
->assertSuccessful();
37-
$dockerComposeAfter2ndExec = file_get_contents($this->app->basePath('docker-compose.yml'));
51+
$dockerCompose = $this->app->basePath('docker-compose.yml');
52+
if (!file_exists($dockerCompose)) {
53+
$dockerCompose = $this->app->basePath('compose.yaml');
54+
}
55+
$dockerComposeAfter2ndExec = file_get_contents($dockerCompose);
3856
$this->assertEquals($dockerComposeAfter1stExec, $dockerComposeAfter2ndExec);
3957
}
4058
}

tests/Feature/PublishCommandTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ public function test_execute_publish_command_successfully()
1010
{
1111
$this->artisan('sail-ssl:install')->assertSuccessful();
1212
$this->artisan('sail-ssl:publish')->assertSuccessful();
13-
$dockerCompose = file_get_contents($this->app->basePath('docker-compose.yml'));
13+
14+
$dockerCompose = $this->app->basePath('docker-compose.yml');
15+
if (!file_exists($dockerCompose)) {
16+
$dockerCompose = $this->app->basePath('compose.yaml');
17+
}
18+
19+
$dockerCompose = file_get_contents($dockerCompose);
1420
$expectedLine = "- './nginx/templates:/etc/nginx/templates'";
1521
$this->assertTrue(str_contains($dockerCompose, $expectedLine));
1622
$this->assertTrue(file_exists($this->app->basePath('nginx/templates/default.conf.template')));
@@ -19,7 +25,11 @@ public function test_execute_publish_command_successfully()
1925
public function test_throw_exception_when_docker_compose_yml_is_not_found()
2026
{
2127
$this->expectException(\ErrorException::class);
22-
unlink($this->app->basePath('docker-compose.yml'));
28+
if (file_exists($this->app->basePath('docker-compose.yml'))) {
29+
unlink($this->app->basePath('docker-compose.yml'));
30+
} else if (file_exists($this->app->basePath('compose.yaml'))) {
31+
unlink($this->app->basePath('compose.yaml'));
32+
}
2333
$this->artisan('sail-ssl:publish')->assertFailed();
2434
}
2535
}

tests/TestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ private function deleteFiles()
4444
unlink($this->app->basePath('phpunit.xml'));
4545
if (file_exists($this->app->basePath('docker-compose.yml'))) {
4646
unlink($this->app->basePath('docker-compose.yml'));
47+
} else if (file_exists($this->app->basePath('compose.yaml'))) {
48+
unlink($this->app->basePath('compose.yaml'));
4749
}
4850
if (file_exists($this->app->basePath('nginx/templates/default.conf.template'))) {
4951
unlink($this->app->basePath('nginx/templates/default.conf.template'));

0 commit comments

Comments
 (0)