Skip to content

Commit

Permalink
[MakeDocker] add support for .yml docker-compose files
Browse files Browse the repository at this point in the history
  • Loading branch information
jrushlow authored and weaverryan committed Apr 23, 2021
1 parent 8580778 commit 56becd3
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions src/Maker/MakeDockerDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ final class MakeDockerDatabase extends AbstractMaker
public function __construct(FileManager $fileManager)
{
$this->fileManager = $fileManager;
$this->composeFilePath = sprintf('%s/docker-compose.yaml', $this->fileManager->getRootDirectory());
}

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

$composeFileContents = '';
$statusMessage = 'Existing docker-compose.yaml not found: a new one will be generated!';

if ($this->fileManager->fileExists($this->composeFilePath)) {
$composeFileContents = $this->fileManager->getFileContents($this->composeFilePath);

$statusMessage = 'We found your existing docker-compose.yaml: Let\'s update it!';
}

$io->text($statusMessage);

$this->composeFileManipulator = new ComposeFileManipulator($composeFileContents);
$this->composeFileManipulator = new ComposeFileManipulator($this->getComposeFileContents($io));

$io->newLine();

Expand Down Expand Up @@ -185,4 +173,34 @@ private function checkForPDOSupport(string $databaseType, ConsoleStyle $io): voi
);
}
}

/**
* Determines and sets the correct Compose File Path and retrieves its contents
* if the file exists else an empty string.
*/
private function getComposeFileContents(ConsoleStyle $io): string
{
$this->composeFilePath = sprintf('%s/docker-compose.yaml', $this->fileManager->getRootDirectory());

$composeFileExists = false;
$statusMessage = 'Existing docker-compose.yaml not found: a new one will be generated!';
$contents = '';

foreach (['.yml', '.yaml'] as $extension) {
$composeFilePath = sprintf('%s/docker-compose%s', $this->fileManager->getRootDirectory(), $extension);

if (!$composeFileExists && $this->fileManager->fileExists($composeFilePath)) {
$composeFileExists = true;

$statusMessage = sprintf('We found your existing docker-compose%s: Let\'s update it!', $extension);

$this->composeFilePath = $composeFilePath;
$contents = $this->fileManager->getFileContents($composeFilePath);
}
}

$io->text($statusMessage);

return $contents;
}
}

0 comments on commit 56becd3

Please sign in to comment.