Skip to content

fix: normalize Docker Hub single-component refs with library/ prefix#1946

Open
knp-sap wants to merge 1 commit into
open-component-model:mainfrom
knp-sap:fix/docker-hub-library-prefix
Open

fix: normalize Docker Hub single-component refs with library/ prefix#1946
knp-sap wants to merge 1 commit into
open-component-model:mainfrom
knp-sap:fix/docker-hub-library-prefix

Conversation

@knp-sap
Copy link
Copy Markdown

@knp-sap knp-sap commented May 6, 2026

When docker.io is explicitly specified as the hostname with a single-component repository name (e.g. docker.io/bash:5.3.9), ParseRef now correctly normalizes it to docker.io/library/bash:5.3.9.

Previously, only bare image names (bash:5.3.9) received the library/ prefix via DockerLibraryReferenceRegexp. When docker.io was explicit, the reference matched ReferenceRegexp instead, which did not perform Docker Hub normalization.

@knp-sap knp-sap requested a review from a team as a code owner May 6, 2026 12:46
@github-actions github-actions Bot added kind/bugfix Bug size/xs Extra small labels May 6, 2026
When docker.io is explicitly specified as the hostname with a
single-component repository name (e.g. docker.io/bash:5.3.9), ParseRef
now correctly normalizes it to docker.io/library/bash:5.3.9.

Previously, only bare image names (bash:5.3.9) received the library/
prefix via DockerLibraryReferenceRegexp. When docker.io was explicit,
the reference matched ReferenceRegexp instead, which did not perform
Docker Hub normalization. This caused downstream tools (e.g. OCM CLI
component transfers) to fail when resolving official Docker Hub images
specified with an explicit docker.io host.

Signed-off-by: Kostadin Plachkov <kostadin.plachkov@sap.com>
@Skarlso
Copy link
Copy Markdown
Contributor

Skarlso commented May 6, 2026

Interesting. Did this cause any problems anywhere?

Comment thread api/oci/ref.go
Comment on lines +133 to +135
if (spec.Host == dockerHubDomain || spec.Host == dockerHubLegacyDomain) && !strings.Contains(spec.Repository, "/") {
spec.Repository = "library" + grammar.RepositorySeparator + spec.Repository
}
Copy link
Copy Markdown
Contributor

@matthiasbruns matthiasbruns May 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (spec.Host == dockerHubDomain || spec.Host == dockerHubLegacyDomain) && !strings.Contains(spec.Repository, "/") {
spec.Repository = "library" + grammar.RepositorySeparator + spec.Repository
}
needsDockerLibraryPath := pec.Host == dockerHubDomain || spec.Host == dockerHubLegacyDomain) && !strings.Contains(spec.Repository, "/")
// inject library path segment into the repository part of the parsed ref.
// for docker, images are resolved including a "library" path segment. This segment needs to be
// added into the Repository field, otherwise the lookup would fail in case of docker's image registry
if needsDockerLibraryPath {
spec.Repository = "library" + grammar.RepositorySeparator + spec.Repository
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added docs & a more understandable naming

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

Labels

kind/bugfix Bug size/xs Extra small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants