-
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
buildinfo: add build attributes and frontend #2476
Conversation
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 think we should pick all build-args + known opts like context, filename etc only. If variable changes build result then it should be picked.
Need to think about what to do with frontend inputs. We should at least mark somehow that they were used. DefinitionOp
should carry the buildinfo of the inputs so it could be added to the main one.
We also discussed that a client should be able to send its own data for this. Eg. bake
to send its args/target. This can be follow-up as well.
8117e19
to
da5482f
Compare
da5482f
to
e08215d
Compare
e08215d
to
311992f
Compare
@tonistiigi I wonder where we should add the opt-in. New image output key? (e.g., |
I think opt-in should be just for the image inline. So as we currently have |
311992f
to
3e718e7
Compare
9ac574e
to
1b1e589
Compare
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 about the special InlineBuildInfoAttrs
handling. It looks out of place compared to the other exporter attrs.
I think we should just use the regular exporter attr for image exporter like we do today for the image exporter. Just the regular map like for other options.
The frontend(dockerfile) shouldn't check if attr exporting is enabled or not, just like for buildinfo
. It just always sets it and if there is no opt-in then the image exporter just clears the whole attr section.
So the base opt-in will be with output option. For the build-arg opt-in we can make it in buildx like for the inline cache https://github.com/docker/buildx/blob/4c938c77bab00dbe983597b7d29f2e2eb19e8000/build/build.go#L358 .
Not for this PR but looking at the current buildinfo
exporter attr buildinfo=[all,imageconfig,metadata,none]
, I'm not sure what the point of the buildinfo=metadata
was for there. Doesn't it make more sense to have it as bool and metadata is just always enabled. What does image exporter have to do with exporting metadata.json
at all? I assume that other than inlining in config this all still works when I'm not exporting an image. In that case we would have 2 exporter attr buildinfo
, buildinfo-attrs
. Currently by default buildinfo
would default to true and buildinfo-attrs
to false. We could even add build-arg config for both of them.
Yes, it looks better that way, thanks for pointing that out.
Yes, initially the idea was to be able to choose the export mode. I agree a bool is enough to enable/disable inline buildinfo in image config. Will work on that in a follow-up.
That's the tricky part. The metadata response is always null if no exporter is specified. We need at least one of them (oci, local, image, tar) otherwise the solver is never called iiuc.
SGTM |
I think we should try to fix this. I don't know exactly what the issue is in here, maybe we need like a exporter post-step. I can see it being useful without exporting an image as well. But let's address this part in a follow-up PR. |
1b1e589
to
839cc67
Compare
"attrs": { | ||
"build-arg:foo": "bar", | ||
"cmdline": "crazymax/dockerfile:master", | ||
"context": "https://github.com/crazy-max/buildkit-buildsources-test.git#master", |
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.
something to think about: would be good if we could capture if build used a local context or no context. That is important info for replay.
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.
If a local context is being used then context
field is not set:
"attrs": {
"cmdline": "crazymax/dockerfile:buildattrs",
"filename": "Dockerfile",
"source": "crazymax/dockerfile:buildattrs"
}
Do you think it's worth adding something like "context": "local"
?
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.
If a local context is being used then context field is not set:
Yes but it might also be that there is no local context at all. Where you just build from Dockerfile with no COPY
commands from context. On replay, we should be able to give an error when the local source is not passed by the user and required for replay, but not when it is not required at all.
} | ||
return bi, nil | ||
} | ||
|
||
var knownAttrs = []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.
Is this list Dockerfile specific or generic enough to be in here?
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.
Yes this is Dockerfile specific atm:
buildkit/frontend/dockerfile/builder/build.go
Lines 44 to 61 in ffe2301
keyTarget = "target" | |
keyFilename = "filename" | |
keyCacheFrom = "cache-from" // for registry only. deprecated in favor of keyCacheImports | |
keyCacheImports = "cache-imports" // JSON representation of []CacheOptionsEntry | |
keyCgroupParent = "cgroup-parent" | |
keyContextSubDir = "contextsubdir" | |
keyForceNetwork = "force-network-mode" | |
keyGlobalAddHosts = "add-hosts" | |
keyHostname = "hostname" | |
keyImageResolveMode = "image-resolve-mode" | |
keyMultiPlatform = "multi-platform" | |
keyNameContext = "contextkey" | |
keyNameDockerfile = "dockerfilekey" | |
keyNoCache = "no-cache" | |
keyOverrideCopyImage = "override-copy-image" // remove after CopyOp implemented | |
keyShmSize = "shm-size" | |
keyTargetPlatform = "platform" | |
keyUlimit = "ulimit" |
c190de4
to
4d0a96c
Compare
4b5bd4f
to
94e9bbd
Compare
6b4d2bc
to
0a33a83
Compare
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.
Could we have some integration tests for this. Something that tests the opt-in, default behavior, inlining. If we add the case where frontend can also provide state via Metadata
then that case as well (with a client.Build
you can return the result metadata, look a build-context tests for example).
0a33a83
to
6c3abec
Compare
util/buildinfo/buildinfo.go
Outdated
} | ||
|
||
// ReduceMap joins map string (union) | ||
func ReduceMap(m1, m2 map[string]string) map[string]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.
if m1 is map[string]*string
then we can remove the key if it is nil.
22de8fd
to
70703d4
Compare
70703d4
to
246bd15
Compare
246bd15
to
409c28c
Compare
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
ac1f35b
to
e6efbe0
Compare
0440083
to
6089f8a
Compare
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
6089f8a
to
9cd97fb
Compare
follow-up #2311
store additional build dependencies such as
frontend
andattrs
.Pre-built frontend
# syntax=crazymax/dockerfile:buildattrs
and BuildKit imagecrazymax/buildkit:buildattrs
can be used to test this feature: