Skip to content

Commit eb90c4f

Browse files
CasEbbtaylorotwell
andauthored
Rename docker-compose.yml to compose.yaml (#818)
* Rename `docker-compose.yml` to `compose.yaml` * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent f908e3a commit eb90c4f

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

src/Console/Concerns/InteractsWithDockerComposeServices.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77

88
trait InteractsWithDockerComposeServices
99
{
10+
/**
11+
* Possible names for the compose file according to the spec.
12+
*
13+
* @var array<string>
14+
*/
15+
protected $composePaths = [
16+
'compose.yaml',
17+
'compose.yml',
18+
'docker-compose.yaml',
19+
'docker-compose.yml',
20+
];
21+
1022
/**
1123
* The available services that may be installed.
1224
*
@@ -62,11 +74,11 @@ protected function gatherServicesInteractively()
6274
*/
6375
protected function buildDockerCompose(array $services)
6476
{
65-
$composePath = base_path('docker-compose.yml');
77+
$composePath = $this->composePath();
6678

6779
$compose = file_exists($composePath)
6880
? Yaml::parseFile($composePath)
69-
: Yaml::parse(file_get_contents(__DIR__ . '/../../../stubs/docker-compose.stub'));
81+
: Yaml::parse(file_get_contents(__DIR__ . '/../../../stubs/compose.stub'));
7082

7183
// Prepare the installation of the "mariadb-client" package if the MariaDB service is used...
7284
if (in_array('mariadb', $services)) {
@@ -84,7 +96,7 @@ protected function buildDockerCompose(array $services)
8496
->all();
8597
}
8698

87-
// Add the services to the docker-compose.yml...
99+
// Add the services to the compose.yaml...
88100
collect($services)
89101
->filter(function ($service) use ($compose) {
90102
return ! array_key_exists($service, $compose['services'] ?? []);
@@ -111,7 +123,7 @@ protected function buildDockerCompose(array $services)
111123

112124
$yaml = str_replace('{{PHP_VERSION}}', $this->hasOption('php') ? $this->option('php') : '8.4', $yaml);
113125

114-
file_put_contents($this->laravel->basePath('docker-compose.yml'), $yaml);
126+
file_put_contents($composePath, $yaml);
115127
}
116128

117129
/**
@@ -313,4 +325,16 @@ protected function runCommands($commands)
313325
$this->output->write(' '.$line);
314326
});
315327
}
328+
329+
/**
330+
* Get the path to an existing Compose file or fall back to a default of `compose.yaml`.
331+
*
332+
* @return string
333+
*/
334+
protected function composePath()
335+
{
336+
return collect($this->composePaths)
337+
->map(fn ($path) => $this->laravel->basePath($path))
338+
->first(fn ($path) => file_exists($path), $this->laravel->basePath('compose.yaml'));
339+
}
316340
}

src/Console/PublishCommand.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
namespace Laravel\Sail\Console;
44

55
use Illuminate\Console\Command;
6+
use Laravel\Sail\Console\Concerns\InteractsWithDockerComposeServices;
67
use Symfony\Component\Console\Attribute\AsCommand;
78

89
#[AsCommand(name: 'sail:publish')]
910
class PublishCommand extends Command
1011
{
12+
use InteractsWithDockerComposeServices;
13+
1114
/**
1215
* The name and signature of the console command.
1316
*
@@ -33,7 +36,7 @@ public function handle()
3336
$this->call('vendor:publish', ['--tag' => 'sail-database']);
3437

3538
file_put_contents(
36-
$this->laravel->basePath('docker-compose.yml'),
39+
$this->composePath(),
3740
str_replace(
3841
[
3942
'./vendor/laravel/sail/runtimes/8.4',
@@ -53,7 +56,7 @@ public function handle()
5356
'./docker/mysql',
5457
'./docker/pgsql'
5558
],
56-
file_get_contents($this->laravel->basePath('docker-compose.yml'))
59+
file_get_contents($this->composePath())
5760
)
5861
);
5962
}
File renamed without changes.

stubs/devcontainer.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"name": "Existing Docker Compose (Extend)",
44
"dockerComposeFile": [
5-
"../docker-compose.yml"
5+
"../compose.yaml"
66
],
77
"service": "laravel.test",
88
"workspaceFolder": "/var/www/html",

0 commit comments

Comments
 (0)