Skip to content

Commit

Permalink
Tweaks the platform check code
Browse files Browse the repository at this point in the history
  • Loading branch information
tonysm committed Oct 28, 2023
1 parent cdeecdf commit c33a95c
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions app/Shell/DockerTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ public function getTags(): Collection
{
$response = json_decode($this->getTagsResponse()->getContents(), true);

$platform = $this->platform();

[$numericTags, $alphaTags] = collect($response['results'])
->filter($this->onlySupportedImagesFilter())
->when($this->isArm($platform), $this->onlyArmImagesFilter())
->when(! $this->isArm($platform), $this->onlyNonArmImagesFilter())
->pluck('name')
->partition(function ($tag) {
return is_numeric($tag[0]);
Expand All @@ -62,14 +65,29 @@ public function getTags(): Collection
return $sortedTags->values()->filter();
}

protected function onlySupportedImagesFilter()
protected function onlyArmImagesFilter()
{
$platform = $this->platform();
return function ($tags) {
return $tags->filter(function ($tag) {
return collect($tag['images'])
->pluck('architecture')
->first(function (string $platform) {
return $this->isArm($platform);
});
});
};
}

return function ($tag) use ($platform) {
return collect($tag['images'])
->pluck('architecture')
->contains($platform);
protected function onlyNonArmImagesFilter()
{
return function ($tags) {
return $tags->filter(function ($tag) {
return collect($tag['images'])
->pluck('architecture')
->first(function (string $platform) {
return ! $this->isArm($platform);
});
});
};
}

Expand All @@ -78,6 +96,11 @@ protected function platform(): string
return php_uname('m');
}

protected function isArm(string $platform): bool
{
return in_array($platform, ['arm64', 'aarch64']);
}

protected function getTagsResponse(): StreamInterface
{
return $this->guzzle
Expand Down

0 comments on commit c33a95c

Please sign in to comment.