Skip to content

Commit

Permalink
refactor: Add Docker Hub hosted image links
Browse files Browse the repository at this point in the history
From the perspective of linking to image details on the Docker Hub web
interface, there are two types of images:

  1. Docker Official Images
  2. all of the other images, regardless of their trustworthiness

The Docker Official Images can be referenced several ways, either on the
command line when passed to docker pull, or in the FROM instruction of a
Dockerfile:

  * busybox
  * library/busybox
  * docker.io/busybox
  * docker.io/library/busybox

Furthermore, over the years there have been several domains used for the
official Docker Hub registry:

  * docker.io
  * index.docker.io
  * registry-1.docker.io
  * registry.hub.docker.com

The goal here is handling each possible case, which makes Docker Hub
images more complex than the handling for other registries.

It also makes the case block's '*' (default) case harder to find in the
sequence of glob expressions, but this is necessary to avoid repeating
the parsing or adding another helper function.

Reference:
docker/hub-feedback#2113
docker/cli#3793

Signed-off-by: Dan Christensen <opello@opello.org>
  • Loading branch information
opello committed Feb 4, 2023
1 parent b083be2 commit 3401173
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions .github/workflows/daily.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,22 @@ jobs:
*.ocir.io/*)
prefix=""
;;
*hub.docker*)
prefix="https://"
;;
*docker.io*)
container=${container#docker.io}
prefix="https://hub.docker.com"
;;
*hub.docker*)
prefix="https://"
# There have been a number of domains used for the Docker Hub registry over the years.
# NOTE: This is also the default case!
docker.io/*|index.docker.io/*|registry-1.docker.io/*|registry.hub.docker.com/*|*)
prefix="https://hub.docker.com/r/"
container=${container#docker.io/}
container=${container#index.docker.io/}
container=${container#registry-1.docker.io/}
container=${container#registry.hub.docker.com/}
# If the image name does not contain a slash it is a Docker Official Image.
if [ "$container" == "${container////}" ]; then
prefix="https://hub.docker.com/_/"
# If the user name is library it is a Docker Official Image.
elif [ "${container%%/*}" == "library" ]; then
prefix="https://hub.docker.com/_/"
container=${container#library/}
fi
;;
esac
if [ -n "${prefix}" ]; then
Expand Down

0 comments on commit 3401173

Please sign in to comment.