Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify if a volume is active. #129

Merged
merged 23 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0d6876f
Verify if a volume is active.
danielebarbaro Sep 18, 2020
06e9ea8
Fix it_enables_services test.
danielebarbaro Sep 18, 2020
2701232
Detect OS after all containers are disabled to prevent docker service…
danielebarbaro Sep 21, 2020
6f3e195
Only check for running containers when disabling services
josecanhelp Sep 23, 2020
a9cfacc
Build v1.3.2
josecanhelp Sep 23, 2020
13ea832
Add CONTRIBUTING.md
faxblaster Sep 24, 2020
8f7dec3
Add License
faxblaster Sep 24, 2020
8c857e2
Update enable and disable commands to expect an array of arguments
bakerkretzmar Sep 17, 2020
b2be5f5
Add test
bakerkretzmar Sep 17, 2020
8432cd3
Fix optional array arguments
bakerkretzmar Sep 17, 2020
2bcfe22
Include service name in prompts
josecanhelp Sep 25, 2020
cb0e043
Return right container name when a docker run fail.
danielebarbaro Sep 18, 2020
cd28fb4
A more generic error exception string when docker run fail.
danielebarbaro Sep 24, 2020
9c95a5c
Add packagist badges
faxblaster Sep 23, 2020
271876c
Add Linux, Windows Testing Again
faxblaster Sep 24, 2020
e962930
Fix spacing
faxblaster Sep 24, 2020
239716c
Add ignore-platform-reqs flag
faxblaster Sep 24, 2020
a818ded
Build
mattstauffer Sep 26, 2020
4af60cf
Removed unused usedVolumes()
danielebarbaro Sep 26, 2020
4d26f13
Review list matching volume method name
danielebarbaro Sep 26, 2020
68ddafb
Merge branch 'main' into feature/verify-active-volume
danielebarbaro Sep 26, 2020
33ba180
Merge remote-tracking branch 'stream' into feature/verify-active-volume
danielebarbaro Oct 1, 2020
2f54f75
Merge remote-tracking branch 'stream' into feature/elastic-search-repo
danielebarbaro Oct 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/Services/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ protected function prompts(): void
foreach ($this->prompts as $prompt) {
$this->askQuestion($prompt, $this->useDefaults);

while ($prompt['shortname'] === 'volume' && !$this->docker->volumeIsAvailable($this->promptResponses['volume'])) {
app('console')->error("Volume {$this->promptResponses['volume']} is already in use. Please select a different volume.");
$this->askQuestion($prompt);
}

while (Str::contains($prompt['shortname'], 'port') && ! $this->environment->portIsAvailable($this->promptResponses[$prompt['shortname']])) {
app('console')->error("Port {$this->promptResponses[$prompt['shortname']]} is already in use. Please select a different port.");
$this->askQuestion($prompt);
Expand Down
11 changes: 11 additions & 0 deletions app/Shell/Docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public function allContainers(): Collection
return $this->containerRawOutputToCollection($this->allContainersRawOutput());
}

public function volumeIsAvailable(string $volumeName): bool
{
return $this->containerRawOutputToCollection($this->listMatchingVolumesRawOutput($volumeName))->count() === 0;
}

/**
* Given the raw string of output from Docker, return a collection of
* associative arrays, with the keys lowercased and slugged using underscores
Expand Down Expand Up @@ -93,6 +98,12 @@ protected function allContainersRawOutput(): string
return trim($this->shell->execQuietly($dockerProcessStatusString)->getOutput());
}

protected function listMatchingVolumesRawOutput(string $volumeName): string
{
$dockerProcessStatusString = "docker ps -a --filter volume={$volumeName} --format 'table {{.ID}}|{{.Names}}|{{.Status}}|{{.Ports}}'";
return trim($this->shell->execQuietly($dockerProcessStatusString)->getOutput());
}

public function imageIsDownloaded(string $organization, string $imageName, ?string $tag): bool
{
$process = $this->shell->execQuietly(sprintf(
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/BaseServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function it_enables_services()
app()->instance('console', M::mock(Command::class, function ($mock) {
$defaultPort = app(MeiliSearch::class)->defaultPort();
$mock->shouldReceive('ask')->with('Which host port would you like meilisearch to use?', $defaultPort)->andReturn(7700);
$mock->shouldReceive('ask')->with('What is the Docker volume name?', 'meili_data')->andReturn('meili_data');
$mock->shouldReceive('ask')->with('Which tag (version) of meilisearch would you like to use?', 'latest')->andReturn('v1.1.1');
$mock->shouldIgnoreMissing();
}));
Expand All @@ -41,6 +42,7 @@ public function it_enables_services()
$this->mock(Docker::class, function ($mock) {
$mock->shouldReceive('isInstalled')->andReturn(true);
$mock->shouldReceive('imageIsDownloaded')->andReturn(true);
$mock->shouldReceive('volumeIsAvailable')->andReturn(true);

// This is the actual assertion
$mock->shouldReceive('bootContainer')->with(['getmeili/meilisearch']);
Expand Down