diff --git a/app/Shell/DockerTags.php b/app/Shell/DockerTags.php index 6b977a66..a9ec6978 100644 --- a/app/Shell/DockerTags.php +++ b/app/Shell/DockerTags.php @@ -43,11 +43,9 @@ public function getLatestTag(): string public function getTags(): Collection { $response = json_decode($this->getTagsResponse()->getContents(), true); - $platform = $this->platform(); [$numericTags, $alphaTags] = collect($response['results']) - ->when($platform === 'arm64', $this->armSupportedImagesOnlyFilter()) - ->when($platform !== 'arm64', $this->nonArmOnlySupportImagesFilter()) + ->filter($this->onlySupportedImagesFilter()) ->pluck('name') ->partition(function ($tag) { return is_numeric($tag[0]); @@ -64,42 +62,14 @@ public function getTags(): Collection return $sortedTags->values()->filter(); } - /** - * Return a function intended to filter tags, ensuring images that do not support arm architecture are filtered out. - * - * @return callable - */ - protected function armSupportedImagesOnlyFilter() + protected function onlySupportedImagesFilter() { - return function ($tags) { - return $tags->filter(function ($tag) { - return collect($tag['images']) - ->pluck('architecture') - ->contains('arm64'); - }); - }; - } + $platform = $this->platform(); - /** - * Return a function intended to filter tags, that ensures are arm-only images are filtered out. - * - * @return callable - */ - protected function nonArmOnlySupportImagesFilter() - { - return function ($tags) { - return $tags->filter(function ($tag) { - $supportedArchitectures = collect($tag['images']) - ->pluck('architecture') - ->unique() - ->values(); - - // When removing the arm64 option from the list, there should - // still be other options in the supported architectures - // so we can consider that the tag is not arm-only. - - return $supportedArchitectures->diff(['arm64'])->count() > 0; - }); + return function ($tag) use ($platform) { + return collect($tag['images']) + ->pluck('architecture') + ->contains($platform); }; } diff --git a/tests/Feature/DockerTagsTest.php b/tests/Feature/DockerTagsTest.php index 509c65b1..4e275e2f 100644 --- a/tests/Feature/DockerTagsTest.php +++ b/tests/Feature/DockerTagsTest.php @@ -77,13 +77,16 @@ private function mockImagesResponseHandler() [ 'name' => 'latest', 'images' => [ + ['architecture' => 'x86_64'], ['architecture' => 'amd64'], ['architecture' => 'arm64'], + ['architecture' => 'aarch64'], ], ], [ 'name' => '1.0.0', 'images' => [ + ['architecture' => 'x86_64'], ['architecture' => 'amd64'], ], ], @@ -91,6 +94,7 @@ private function mockImagesResponseHandler() 'name' => '1.0.0-arm64', 'images' => [ ['architecture' => 'arm64'], + ['architecture' => 'aarch64'], ], ], ],