Skip to content

Keep the tag of image references pinned by tag and digest - #1469

Merged
cristianrgreco merged 2 commits into
mainfrom
claude/issue-triage-1468-6a3758
Sep 26, 2026
Merged

cristianrgreco merged 2 commits into
mainfrom
claude/issue-triage-1468-6a3758

Conversation

@cristianrgreco

@cristianrgreco cristianrgreco commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

ImageName.fromString split name:tag@digest references at the @ first. For mongo:8@sha256:… that gave image = "mongo:8" and tag = "sha256:…": the tag stayed inside the image name and .tag held the digest. .string still round-tripped, so pulling and running worked, but modules that read the version from imageName.tag misbehaved:

This PR:

  • Splits off the digest first and reads the tag from what precedes it.
  • Adds an optional digest constructor argument and public field on ImageName. It is set whenever the reference has a digest, including digest-only references (image@sha256:…). For those, tag still holds the digest, as before.
  • Renders string as name:tag@digest when both are present.
  • Includes digest in equals.

This follows the Java fix for the same bug (testcontainers/testcontainers-java#11629), where getVersionPart() returns the tag and a new getDigest() returns the digest. Unlike Java, no change to pulling is needed, because Node passes the full imageName.string to dockerode.pull.

Verification

npx vitest run packages/testcontainers/src/container-runtime/image-name.test.ts
npm run format
npm run lint
npm run check-compiles

Test results

Red-green: I ran each test against the pre-fix implementation, then again after the fix.

Test Before the fix After the fix
image-name.test.ts: 4 new cases, plus digest checks on existing ones Failed, e.g. expected 'image:tag' to be 'image' 73/73 pass

During development I also reproduced the module symptoms and confirmed the fix. These tests are not kept in the PR, so CI doesn't pull an extra image:

  • Kafka: new KafkaContainer("confluentinc/cp-kafka:6.2.14@sha256:…").withKraft() threw Invalid argument not valid semver before the fix. After it, the error correctly reports version 6.2.14.
  • MongoDB: mongo:8.2.12@sha256:e0ce8c… failed with Health check not healthy after 120000ms before the fix and started after it.

format, lint and check-compiles are clean.

Why this is not breaking

  • .string, the only value used to pull and inspect images, is unchanged for every reference that already parsed correctly: image, image:tag, image@sha256:…, and references with a registry and port. For name:tag@digest it was already name:tag@digest and still is.
  • For digest-only references, tag still returns sha256:….
  • The new constructor argument is optional, so existing new ImageName(registry, image, tag) calls still compile and behave the same.
  • All existing ImageName tests pass unchanged.
  • equals now also compares digest. For names built without a digest, the digest is derived from the tag, so existing comparisons give the same result.

Closes #1468

ImageName.fromString split name:tag@digest at the @ first, leaving the tag
inside the image name and exposing the digest as the tag. Modules that read
the version from imageName.tag then misbehaved: MongoDB fell back to the
legacy mongo shell and never became healthy, and Kafka threw in its
constructor.

Split off the digest first, read the tag from what precedes it, and expose
the digest via a new optional digest field.
@cristianrgreco cristianrgreco added bug Something isn't working patch Backward compatible bug fix labels Sep 26, 2026
@netlify

netlify Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for testcontainers-node ready!

Name Link
🔨 Latest commit dd0a53b
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-node/deploys/6ab78fb933abe600094a829a
😎 Deploy Preview https://deploy-preview-1469--testcontainers-node.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment thread packages/modules/kafka/src/kafka-container-7.test.ts Outdated
@cristianrgreco
cristianrgreco marked this pull request as ready for review September 26, 2026 12:19
@cristianrgreco
cristianrgreco merged commit b24be83 into main Sep 26, 2026
275 checks passed
@cristianrgreco
cristianrgreco deleted the claude/issue-triage-1468-6a3758 branch September 26, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working patch Backward compatible bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImageName.fromString drops the tag of a name:tag@sha256:<digest> reference, so MongoDBContainer picks the legacy mongo shell and never becomes healthy

1 participant