8000 Encode container image manifests in ImageBuilder via Encoder Fixes #47399 by Forgind · Pull Request #48255 · dotnet/sdk · GitHub
[go: up one dir, main page]

Skip to content

Encode container image manifests in ImageBuilder via Encoder Fixes #47399 #48255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Forgind
Copy link
Contributor
@Forgind Forgind commented Apr 8, 2025

Fixes #47399

@MattKotsenas @baronfel

I wasn't really able to test this (see here) as I'd like, but does this look like the kind of fix you'd expect?

@ghost ghost added Area-NetSDK untriaged Request triage from a team member labels Apr 8, 2025
@KalleOlaviNiemitalo
Copy link
Contributor
KalleOlaviNiemitalo commented Apr 9, 2025

From the PR title, I assumed this was about graphics images and something like JPEG encoding. Could clarify with "Encode container image manifests".

@@ -91,7 +94,7 @@ internal BuiltImage Build()
Config = imageJsonStr,
ImageDigest = imageDigest,
ImageSha = imageSha,
Manifest = JsonSerializer.SerializeToNode(newManifest)?.ToJsonString() ?? "",
Manifest = JsonSerializer.SerializeToNode(newManifest, serializerOptions)?.ToJsonString() ?? "",
ManifestDigest = newManifest.GetDigest(),
Copy link
Contributor

Choose a reason for hiding this comment

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

GetDigest seems to be using JsonSerializer.SerializeToNode with the default encoder so the digest might not match after this change

public string GetDigest() => KnownDigest ??= DigestUtils.GetDigest(JsonSerializer.SerializeToNode(this)?.ToJsonString() ?? string.Empty);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can change that one to use the same serializer.

I'm a little concerned because I don't really understand how these are deserialized, and I'd want to make sure we are able to read them properly. Do you know more about that?

(Sorry I have stupid questions; I don't know very much about containers 🙂)

Copy link
Member

Choose a reason for hiding this comment

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

my main comment was going to be that all json (de)serialization should happen via the same set of serializer options, so I'm glad @KalleOlaviNiemitalo touched on this.

for other places we deserialize - we do this in a few places, but prominently in Registry.cs, where we take opaque JSON blobs from HTTP APIs and convert them to various structured representations.

Copy link
Member
@MattKotsenas MattKotsenas Apr 18, 2025

Choose a reason for hiding this comment

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

Perhaps consider using the BannedApiAnalyzers for this purpose? It's probably a bit more complicated that it ought to be, since you'll need to ban APIs one-at-a-time, but it's worth at least considering so that usages without the options don't creep in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I know, the only advantage to using JsonSerializer.Serialize(obj) over JsonSerializer.Serialize(obj, JsonSerializerOptions) is brevity. Even if you just want the standard, default JsonSerializerOptions, you can pass in JsonSerializerOptions.Default, and I believe it works the same way. For that reason, I think adding it to our BannedApiAnalyzers might be a reasonable approach.

Any concerns @baronfel?

Copy link
Member

Choose a reason for hiding this comment

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

Bring down the banhammer :) I'm happy preventing the sue of the convenience API throughout this component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we don't seem to have infrastructure for this set up at the moment, I think I wouldn't set it up in this PR regardless, so I may as well make an issue to record the suggestion for discussion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Forgind Forgind changed the title Encode images in ImageBuilder via Encoder Fixes #47399 Encode container image manifests in ImageBuilder via Encoder Fixes #47399 Apr 9, 2025
@Forgind Forgind changed the base branch from release/9.0.3xx to main April 21, 2025 19:10
@marcpopMSFT
Copy link
Member

Note: Requires additional testing and a review CC @dotnet/sdk-container-builds-maintainers Who should I assign this to?

@baronfel
Copy link
Member

@surayya-MS would be the go-to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Encoded plus sign in image mediaType for container publish
5 participants
0