tighten / takeout

Docker-based development-only dependency manager. macOS, Linux, and WSL2-only and installs via PHP's Composer... for now.
MIT License
1.6k stars 84 forks source link

`takeout enable mysql` getting the lowest docker image version instead of latest #207

Closed andradei closed 3 years ago

andradei commented 3 years ago

When leaving docker tag empty (default latest) or explicitly typing "latest", it picks the lowest version from Docker Hub instead... Selecting the version explicitly works, however.

Note this is downloading mysql:5.6.51 instead of mysql:latest (version 8.0.23 as of today)


➤ takeout enable mysql

 Which host port would you like mysql to use? [3306]:
 > 

 Which tag (version) of mysql would you like to use? [latest]:
 > latest

 What is the Docker volume name? [mysql_data]:
 > 

 What will the root password be? (null by default) []:
 > 

Downloading docker image...

 OUT  5.6.51: Pulling from library/mysql
 OUT  8aff230071c9: Pulling fs layer
 OUT  134fc34c9927: Pulling fs layer
 OUT  27dfb473d52e: Pulling fs layer
 OUT  702c333a167e: Pulling fs layer
 OUT  699bc078b452: Pulling fs layer
 OUT  01dd862365bd: Pulling fs layer
 OUT  7dbfc4425b5a: Pulling fs layer
 OUT  038f3579b073: Pulling fs layer
 OUT  d03e96fd56ed: Pulling fs layer
 OUT  01dd862365bd: Waiting
 OUT  d4e40c94cc3e: Pulling fs layer
 OUT  552099682f91: Pulling fs layer
 OUT  7dbfc4425b5a: Waiting
 OUT  d03e96fd56ed: Waiting
 OUT  038f3579b073: Waiting
 OUT  552099682f91: Waiting
 OUT  d4e40c94cc3e: Waiting
 OUT  702c333a167e: Waiting
 OUT  699bc078b452: Waiting
 OUT  134fc34c9927: Verifying Checksum
 OUT  134fc34c9927: Download complete
 OUT  27dfb473d52e: Verifying Checksum
 OUT  27dfb473d52e: Download complete
 OUT  8aff230071c9: Verifying Checksum
 OUT  8aff230071c9: Download complete
 OUT  8aff230071c9: Pull complete
 OUT  134fc34c9927: Pull complete
 OUT  27dfb473d52e: Pull complete
 OUT  699bc078b452: Verifying Checksum
 OUT  699bc078b452: Download complete
 OUT  702c333a167e: Download complete
 OUT  702c333a167e: Pull complete
 OUT  699bc078b452: Pull complete
 OUT  01dd862365bd: Verifying Checksum
 OUT  01dd862365bd: Download complete
 OUT  01dd862365bd: Pull complete
 OUT  7dbfc4425b5a: Download complete
 OUT  7dbfc4425b5a: Pull complete
 OUT  038f3579b073: Download complete
 OUT  d4e40c94cc3e: Verifying Checksum
 OUT  d4e40c94cc3e: Download complete
 OUT  038f3579b073: Pull complete
 OUT  d03e96fd56ed: Verifying Checksum
 OUT  d03e96fd56ed: Download complete
 OUT  d03e96fd56ed: Pull complete
 OUT  d4e40c94cc3e: Pull complete
 OUT  552099682f91: Verifying Checksum
 OUT  552099682f91: Download complete
 OUT  552099682f91: Pull complete
 OUT  Digest: sha256:a1868bd2d1c8c32a46baa7d06f38c3de76e949c8f811a5bc42bac6738520f3a7
 OUT  Status: Downloaded newer image for mysql:5.6.51
 OUT  docker.io/library/mysql:5.6.51
Enabling mysql...

 OUT  3c1dba027fa20b0eb6d39c7d88866ec8bd7692262fa14227c96ab2aba14ec8b6
111
mabadir commented 3 years ago

Hi @andradei, yes I confirm this is the case for me. I will look into the source code and help with a PR.

mabadir commented 3 years ago

I have checked the issue. It seems the issue related to how the tags (versions) are returned by Docker Hub.

Currently the versions are returned out of order.

I will dig a little bit more.

mabadir commented 3 years ago

@mattstauffer, in order to force order to the tags retrieved, we can add order=name query parameter. For example:

https://registry.hub.docker.com/v2/repositories/library/mysql/tags?ordering=name

This returns the tags in order, like that:

^ Illuminate\Support\Collection^ {#490
  #items: array:10 [
    0 => "latest"
    1 => "8.0.4-rc"
    2 => "8.0.4"
    3 => "8.0.3"
    4 => "8.0.23"
    5 => "8.0.22"
    6 => "8.0.21"
    7 => "8.0.20"
    8 => "8.0.2"
    9 => "8.0.19"
  ]

Any thoughts, should I PR it?

mabadir commented 3 years ago

Also, another way of doing it, is to refactor this function, I am trying to get my head around it, but not sure why latest tag is being rejected.


 public function getLatestTag(): string
    {
        $nonLatestTags = $this->getTags()->reject(function ($tag) {
            return $tag === 'latest';
        });

        if ($nonLatestTags->isEmpty()) {
            return 'latest';
        }

        return $nonLatestTags->first();
    }
mattstauffer commented 3 years ago

Ah, that order param is a great idea!

We're rejecting latest because the whole point of that function is to figure out which tag latest is referring to.