Skip to content

feat: hub search v3 API#48692

Draft
Benehiko wants to merge 3 commits intomoby:masterfrom
Benehiko:hub-v3-search
Draft

feat: hub search v3 API#48692
Benehiko wants to merge 3 commits intomoby:masterfrom
Benehiko:hub-v3-search

Conversation

@Benehiko
Copy link
Contributor

@Benehiko Benehiko commented Oct 18, 2024

Added new engine endpoints to proxy image search requests to Docker Hub APIs.

Why?
The engine only supports search using the v1 registry https://github.com/moby/moby/blob/master/api/server/router/image/image.go#L43. But this seems to lack capabilities compared to Docker Hub v3. For instance, leaving out the term= parameter in the current search would yield no results.

The CLI would benefit from completing image names and image tags on docker pull/run. For example docker run [tab][tab] and docker pull [tab][tab] would retrieve a list of images from Docker Hub. This would allow for the user to search Docker Hub images using CLI completions.

Below are some examples of what could be implemented - not necessarily what should :)

A draft PR using these APIs have been implemented in the CLI docker/cli#5528

⋊> ~/G/cli on hub-completions ⨯ ./build/docker pull                                                                                                                                         14:08:27
memcached                 (Free & open source, high-performance, distributed memory object caching system.)
nginx                                                                            (Official build of Nginx.)
busybox                                                                               (Busybox base image.)
alpine  (A minimal Docker image based on Alpine Linux with a complete package index and only 5 MB in size!)
ubuntu                            (Ubuntu is a Debian-based Linux operating system based on free software.)
redis         (Redis is the world’s fastest data platform for caching, vector search, and NoSQL databases.)
postgres        (The PostgreSQL object-relational database system provides reliability and data integrity.)
python          (Python is an interpreted, interactive, object-oriented, open-source programming language.)
node                  (Node.js is a JavaScript-based platform for server-side and networking applications.)
httpd                                                                      (The Apache HTTP Server Project)
mongo                          (MongoDB document databases provide high availability and easy scalability.)
mysql                  (MySQL is a widely used, open-source relational database management system (RDBMS).)
rabbitmq                                      (RabbitMQ is an open source multi-protocol messaging broker.)
traefik                                                             (Traefik, The Cloud Native Edge Router)
docker                                                                                  (Docker in Docker!)
hello-world                                            (Hello World! (an example of minimal Dockerization))
mariadb           (MariaDB Server is a high performing open source relational database, forked from MySQL.)
openjdk                                                    (Pre-release / non-production builds of OpenJDK)
golang                   (Go (golang) is a general purpose, higher-level, imperative programming language.)
registry       (Distribution implementation for storing and distributing of container images and artifacts)
ruby   (Ruby is a dynamic, reflective, object-oriented, general-purpose, open-source programming language.)
wordpress          (The WordPress rich content management system can utilize plugins, widgets, and themes.)
debian          (Debian is a Linux distribution that's composed entirely of free and open-source software.)
php     (While designed for web development, the PHP scripting language also provides general-purpose use.)
centos                                                          (DEPRECATED; The official build of CentOS.)
⋊> ~/G/cli on hub-completions ⨯ ./build/docker pull postgres:13.16-bookworm                                                                                                                 14:08:27
postgres:13.16-bookworm  (2024-10-18 11:08:30.896642 +0000 UTC)  postgres:16.4             (2024-10-18 08:10:06.28729 +0000 UTC)  postgres:14-bookworm    (2024-10-18 08:08:51.721222 +0000 UTC)
postgres:13.16           (2024-10-18 11:08:18.796189 +0000 UTC)  postgres:16-bookworm     (2024-10-18 08:10:02.330196 +0000 UTC)  postgres:14              (2024-10-18 08:08:40.24017 +0000 UTC)
postgres:13-bookworm     (2024-10-18 11:08:13.225335 +0000 UTC)  postgres:16              (2024-10-18 08:09:51.127061 +0000 UTC)  postgres:latest          (2024-10-18 05:09:46.28153 +0000 UTC)
postgres:13              (2024-10-18 11:08:00.239001 +0000 UTC)  postgres:15.8-bookworm   (2024-10-18 08:09:41.850909 +0000 UTC)  postgres:bookworm       (2024-10-18 05:09:42.962053 +0000 UTC)
postgres:12.20-bookworm  (2024-10-18 11:07:49.793756 +0000 UTC)  postgres:15.8            (2024-10-18 08:09:32.326534 +0000 UTC)  postgres:17.0-bookworm  (2024-10-18 05:09:33.600165 +0000 UTC)
postgres:12.20           (2024-10-18 11:07:37.813313 +0000 UTC)  postgres:15-bookworm     (2024-10-18 08:09:27.218194 +0000 UTC)  postgres:17.0           (2024-10-18 05:09:25.333884 +0000 UTC)
postgres:12-bookworm     (2024-10-18 11:07:31.639943 +0000 UTC)  postgres:15              (2024-10-18 08:09:16.708768 +0000 UTC)  postgres:17-bookworm    (2024-10-18 05:09:20.167271 +0000 UTC)
postgres:12              (2024-10-18 11:07:16.421658 +0000 UTC)  postgres:14.13-bookworm  (2024-10-18 08:09:07.196582 +0000 UTC)  
postgres:16.4-bookworm   (2024-10-18 08:10:16.018942 +0000 UTC)  postgres:14.13           (2024-10-18 08:08:56.827444 +0000 UTC)

- What I did

This PR introduces two new API endpoints:

  • /hub/image/search
  • /hub/image/{name:.*}/get

These endpoints directly communicate with the official Docker Hub APIs, to do image search and retrieve image tags.

  • https://hub.docker.com/api/search/v3/catalog/search
  • https://hub.docker.com/v2/repositories/library/<image>/tags

- How I did it

- How to verify it
Image Search

curl --unix-socket /run/docker.sock "http://localhost/hub/image/search?term="
curl --unix-socket /run/docker.sock "http://localhost/hub/image/search?term=&from=0&size=100&order=asc&source=store"

Image tag search

curl --unix-socket /run/docker.sock "http://localhost/hub/image/postgres/get"
curl --unix-socket /run/docker.sock "http://localhost/hub/image/postgres/get?name=15.9-alpine"
curl --unix-socket /run/docker.sock "http://localhost/hub/image/postgres/get?name=15&ordering=last_updated"

- Description for the changelog

new endpoints that proxy image search to Docker Hub APIs 

- A picture of a cute animal (not mandatory but encouraged)

image

@tianon
Copy link
Member

tianon commented Nov 16, 2024

I'm all for better search, but please don't make tab completion hit a remote web service 😅 😭 ❤️

@Benehiko
Copy link
Contributor Author

I'm all for better search, but please don't make tab completion hit a remote web service 😅 😭 ❤️

@tianon Could you expand more on your concerns?

@tianon
Copy link
Member

tianon commented Nov 22, 2024

Speed, reliability, privacy - feel free to pick any one of these 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants