Skip to content

Conversation

@the-braveknight
Copy link

Fix --tag parameter to properly push tags and update latest

Motivation

The --tag parameter was accepted by containertool but had no effect on the
actual tags pushed to the registry. When running:

swift package build-container-image --repository ghcr.io/org/image --tag v1.0.0

The image was only pushed to ghcr.io/org/image:latest (the default reference
from --repository), while the output misleadingly reported ghcr.io/org/image:v1.0.0.

This made it impossible to publish versioned releases using the --tag flag.

Modifications

  • Collect all tags to publish: the --tag value (if provided) plus the default
    reference from --repository (typically 'latest')
  • Push the manifest and index to each tag in the collection
  • Skip duplicate pushes when --tag matches the repository reference
  • Return the --tag reference (if provided) as the primary result

Result

When --tag is provided, the image is pushed to both the specified tag AND the
default reference:

--tag v1.0.0 → pushes to v1.0.0 and latest
--tag latest → pushes to latest (once, no duplicate)
(no --tag) → pushes to latest (existing behavior)

Test Plan

  1. Build with --tag flag: swift package build-container-image --repository ghcr.io/org/image --tag v1.0.0
  2. Verify both tags exist: docker pull ghcr.io/org/image:v1.0.0 and docker pull ghcr.io/org/image:latest
  3. Build with --tag latest: verify no errors and single push
  4. Build without --tag: verify existing behavior unchanged

The --tag parameter was accepted but not used when pushing the manifest
and index to the registry. The code was always using destinationImage.reference
(which defaults to 'latest') instead of the user-provided tag.

This fix:
- Pushes to both the specified --tag and the default reference (latest)
- Avoids duplicate pushes if --tag matches the repository reference
- Returns the correct reference in the result
@euanh euanh self-requested a review December 5, 2025 16:24
@the-braveknight the-braveknight force-pushed the fix/tag-publishing branch 2 times, most recently from 5fe16eb to 87d59d6 Compare December 5, 2025 19:40
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.

1 participant