77
88trait 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}
0 commit comments