Skip to content

Bake temp image name mangled by rsplit(":", 1) for registries containing a port #738

Description

@ianpittwood

Problem

BakeTarget.from_image_target() strips what it assumes is a tag off the temporary image name:

# posit_bakery/image/bake/bake.py:138-139
if image_target.temp_name is not None:
    kwargs["tags"] = [image_target.temp_name.rsplit(":", 1)[0]]

rsplit(":", 1)[0] is not tag-aware — it splits on the last : anywhere in the reference,
including a registry port. For a temp registry with a port:

"localhost:5000/package-manager/tmp".rsplit(":", 1)[0] == "localhost"

The bake target would then be tagged localhost, and the resulting metadata image.name
(and therefore BuildMetadata.image_ref, and therefore ImageTarget.get_merge_sources() and
everything bakery ci publish does with it) would be garbage — silently, since the build
itself would still succeed against a bogus name.

Two aggravating factors:

  • ImageTarget.temp_name (image_target.py:573-578) returns {temp_registry}/{image}/tmp
    with no tag at all, so the rsplit is a no-op in every correct case — it can only ever
    do harm.
  • ImageTarget.build() uses self.temp_name verbatim (image_target.py:678), so the two
    build strategies disagree about how the temp name is derived. Keeping them identical is
    what makes bake/build metadata provably interchangeable (see [SPIKE] investigate bake build metadata for native workflow migration #728).

Local registries with ports are a normal --temp-registry value for local/dev and
bakery services style workflows, so this is reachable, not theoretical.

Fix

Drop the rsplit and use image_target.temp_name directly, matching ImageTarget.build().
If tag-stripping is ever genuinely needed, it must be done with a reference parser that
understands registry ports (split on the last : only when it appears after the final /).

Acceptance criteria

  • Bake targets for temp-registry builds are tagged with the same value ImageTarget.build()
    uses.
  • Test with --temp-registry localhost:5000 asserting the bake plan target tag is
    localhost:5000/<image>/tmp.
  • Test asserting bake and build strategies produce the same image.name for a temp-registry
    target.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdockerRelated to container images we producedocker/toolsRelated to container build/test tools

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions