Skip to content

Commit 2d90730

Browse files
committed
bug #818 [MakeDocker] add support for .yml docker-compose files (jrushlow)
This PR was squashed before being merged into the 1.0-dev branch. Discussion ---------- [MakeDocker] add support for .yml docker-compose files Currently, `make:docker:database` only supports creating & manipulating `docker-compose.yaml` files. In the docker world however, it is common to have `docker-compose.yml` files. This PR adds support to manipulate existing `docker-compose`(`.yml`||`.yaml`) files. When running this command without an existing compose file, `.yaml` will be used. fixes #777 Commits ------- 56becd3 [MakeDocker] add support for .yml docker-compose files
2 parents 8580778 + 56becd3 commit 2d90730

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

src/Maker/MakeDockerDatabase.php

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ final class MakeDockerDatabase extends AbstractMaker
5656
public function __construct(FileManager $fileManager)
5757
{
5858
$this->fileManager = $fileManager;
59-
$this->composeFilePath = sprintf('%s/docker-compose.yaml', $this->fileManager->getRootDirectory());
6059
}
6160

6261
public static function getCommandName(): string
@@ -80,18 +79,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
8079
{
8180
$io->section('- Docker Compose Setup-');
8281

83-
$composeFileContents = '';
84-
$statusMessage = 'Existing docker-compose.yaml not found: a new one will be generated!';
85-
86-
if ($this->fileManager->fileExists($this->composeFilePath)) {
87-
$composeFileContents = $this->fileManager->getFileContents($this->composeFilePath);
88-
89-
$statusMessage = 'We found your existing docker-compose.yaml: Let\'s update it!';
90-
}
91-
92-
$io->text($statusMessage);
93-
94-
$this->composeFileManipulator = new ComposeFileManipulator($composeFileContents);
82+
$this->composeFileManipulator = new ComposeFileManipulator($this->getComposeFileContents($io));
9583

9684
$io->newLine();
9785

@@ -185,4 +173,34 @@ private function checkForPDOSupport(string $databaseType, ConsoleStyle $io): voi
185173
);
186174
}
187175
}
176+
177+
/**
178+
* Determines and sets the correct Compose File Path and retrieves its contents
179+
* if the file exists else an empty string.
180+
*/
181+
private function getComposeFileContents(ConsoleStyle $io): string
182+
{
183+
$this->composeFilePath = sprintf('%s/docker-compose.yaml', $this->fileManager->getRootDirectory());
184+
185+
$composeFileExists = false;
186+
$statusMessage = 'Existing docker-compose.yaml not found: a new one will be generated!';
187+
$contents = '';
188+
189+
foreach (['.yml', '.yaml'] as $extension) {
190+
$composeFilePath = sprintf('%s/docker-compose%s', $this->fileManager->getRootDirectory(), $extension);
191+
192+
if (!$composeFileExists && $this->fileManager->fileExists($composeFilePath)) {
193+
$composeFileExists = true;
194+
195+
$statusMessage = sprintf('We found your existing docker-compose%s: Let\'s update it!', $extension);
196+
197+
$this->composeFilePath = $composeFilePath;
198+
$contents = $this->fileManager->getFileContents($composeFilePath);
199+
}
200+
}
201+
202+
$io->text($statusMessage);
203+
204+
return $contents;
205+
}
188206
}

0 commit comments

Comments
 (0)