-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
image exporter: return image descriptor in response #2610
Conversation
94e70da
to
a38522c
Compare
a38522c
to
8331e31
Compare
254b272
to
65ec0e5
Compare
Not sure if |
Talked with @tonistiigi about this in Slack a few days ago when he encountered a similar stack trace in the |
cmd/buildctl/build.go
Outdated
continue | ||
} | ||
var raw json.RawMessage | ||
if err = json.Unmarshal(dt, &raw); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RawMessage.UnmarshalJSON()
doesn't actually parse any JSON https://cs.opensource.google/go/go/+/refs/tags/go1.17.6:src/encoding/json/stream.go;l=271 . This seems to still work but I'm not sure how 🤔 (or maybe just small inputs work) . But I think anyway it is safer to try parsing it to actual map interface. I think it is enough if we validate that it is a JSON object and don't handle liternals and arrays. That should minimize any possibility of randomly hitting this. Eg. "MTIK" is a valid base64 encoded JSON. (You can actually add it as a test case).
If the parsing is ok then use the data as RawMessage
and discard the parsing result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a JSON object
Let's also make sure it is a non-zero length JSON object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^
34a2e1e
to
3b96419
Compare
3b96419
to
1f655b2
Compare
cmd/buildctl/build.go
Outdated
return continuity.AtomicWriteFile(filename, stripJSONNullProperties(b), 0666) | ||
} | ||
|
||
func stripJSONNullProperties(src []byte) []byte { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not what I meant. Just json.Unmarshal
into a map[string]interface{}
. If it decodes without an error and len(map) > 0
then add the bytes to out as RawMessage
. Otherwise, we show the value as the original string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. For the strip json null props func I was thinking it could be useful for cases like {"foo":null,"bar":"baz"}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what case it is? If the daemon already sends JSON then we should not transform it. The question is only how do we detect what values should be shown as-is and what should be decoded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was just preventive but agree we should not change it.
client/client_test.go
Outdated
require.NoError(t, err) | ||
|
||
require.Contains(t, res.ExporterResponse, exptypes.ExporterImageDescriptorKey) | ||
dt, err := base64.StdEncoding.DecodeString(res.ExporterResponse[exptypes.ExporterImageDescriptorKey]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are integration tests using buildctl
as well https://github.com/moby/buildkit/blob/master/cmd/buildctl/build_test.go#L48 that allow you to also cover the json decoding feature without reimplementing it in a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've already expanded the testBuildMetadataFile
one for the descriptor: https://github.com/moby/buildkit/pull/2610/files#diff-487f6d73514b6a9c5895f8c77586ce38dc2b108fb3ed93bd0d63452667a7c3c3R157-R164. Is it not enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No that is fine. I'm ok with just removing this test completely then. All cases seem to be covered also in that buildctl test.
1f655b2
to
cb8b3ea
Compare
Signed-off-by: CrazyMax <[email protected]>
cb8b3ea
to
3532f5c
Compare
@tonistiigi Done in #2476 (README and build-repro.md): adb6b1d |
fixes #2558
@tonistiigi About
config.digest
as annotation should this be removed like?:buildkit/exporter/oci/export.go
Line 214 in a640b47
Signed-off-by: CrazyMax [email protected]