[Builder] Refactor builder probe cache and container backend#33061
[Builder] Refactor builder probe cache and container backend#33061vdemeester merged 1 commit intomoby:masterfrom
Conversation
2127d05 to
9b8f017
Compare
|
Is this planned to be the base of buildkit? |
|
There are definitely pieces in docker build that could be used as the foundation for buildkit. I don't see much value in starting from scratch if there are pieces we can reuse. |
eaf43ec to
15d35dd
Compare
1188c97 to
64279a0
Compare
64279a0 to
4ea6ca5
Compare
4f6c97b to
e7e4138
Compare
e7e4138 to
201f762
Compare
builder/dockerfile/builder.go
Outdated
There was a problem hiding this comment.
I think these should be passed with Run, there is no constraint that an exec output needs to end up in a central builder output.
There was a problem hiding this comment.
Makes sense, I can pass these as run opts.
There was a problem hiding this comment.
Should move implementation in this file out of /builder. To daemon or a subpkg of daemon.
There was a problem hiding this comment.
There are still a lot of builder specific pieces in here. Logging is a big one.
I understand you don't consider this part of the builder, but I don't think adding to daemon is appropriate either. I see this as part of the adapter in this model.
------------ -------------------- --------------
| builder | --> | builder adaptor | ---> | image API |
------------ -------------------- | --------------
| -----------------
`-> | Container API |
-----------------
(from #32904 (comment))
How about I move it out of dockerfile into something like builder/containeradaptor ?
There was a problem hiding this comment.
Builder doesn't need to depend on one central dependency(builder adaptor). It can just talk with "image API" and "container API" directly. In #32904 the "container API" is Exec() and Debug(). There is nothing builder specific in these methods so it is wrong to call it "builder *". That being said, there is no requirement that "container API" needs to be daemon.Daemon instance. I'd be happy if you can move it anywhere outside of builder/ dir.
There was a problem hiding this comment.
For the logging. The Run() method should just return the context cancellation error.
There was a problem hiding this comment.
I meant the fmt.Fprintf() stuff, but I think it's fine if it's in api/server/backend/build
d4b09ea to
cb2283b
Compare
5e53d71 to
f0948af
Compare
|
Those issues should be fixed. Note that containerBackend does have state that can't be applied to different builds. If a build runs without |
f0948af to
0261586
Compare
There was a problem hiding this comment.
Let's avoid messages like this in here. Just return ctx.Err(), if the builder wants to detect this error as ctx. Canceled it can do that and print a message.
There was a problem hiding this comment.
Holding tmpContainers in here don't seem correct. That seems to be the only reason why these loggers are passed around in rm functions. It should remain part of builder and backend exposes removal by ID without loggers. If it is really simpler like this I'd be ok with it as the whole tmpContainers logic will go away with Exec/Debug. In that case add TODO comments.
There was a problem hiding this comment.
Yes, the entire purpose of this object is to manage the tmpContainers. If we remove them then we are back to the old interface.
I agree this is an incremental change which gets us closer to the final interface.
This was original part of the builder and you asked me to move it out! I can add a TODO on the struct explaining why it exists.
api/server/backend/build/backend.go
Outdated
There was a problem hiding this comment.
This callback logic appears to exists because of the tmpContainers as well. I don't think there is a need for these objects to be stateful. It is dangerous to make such assumptions as 2 build jobs should be able to share each other's resources. ContainerBackend is a dependency on builder, not on the build definition.
There was a problem hiding this comment.
Yes, this callback exists because each build should have it's own containerBackend.
I don't think there is a need for these objects to be stateful
There is a need for some object to be stateful to manage temporary contaienrs. This object is current the containerBackend, so it must be stateful.
It is dangerous to make such assumptions as 2 build jobs should be able to share each other's resources.
I think the problem is that you asked me to move this out of the builder. Previously this made a lot more sense because it was part of the builder and not a dependency.
6ccaba2 to
3f18cf8
Compare
|
This is rebased, and green again. I've moved the containerManager back to the builder since it is still handling responsibilities of the builder. When we have |
6a6d55a to
f7f829b
Compare
tonistiigi
left a comment
There was a problem hiding this comment.
I went through this again, and unfortunately, I'm still confused how this helps. We already discussed that this is not 3rd task of #32904 but even when ignoring that I have some concerns.
First, I don't have any issues with the imageProber part.
For the exec part, it exposes new public interface ContainerBackend with 3 methods but there is no way for the user to ever provide this interface to the builder. Everything that uses it is private to the package.
Then it introduces a concept called containerManager. I don't see why a build operation should depend on a "manager" with state and why anyone would need to implement this state handling if they want to plug custom features in the builder. Keeping track of intermediate containers is an internal feature of builder(and one that can be removed completely). If this manager concept is internal then it should not be exposed as a build option.
The dependency interface for the builder does not change with this PR, so it seems just adding to the confusion that BuildManager now takes multiple inputs. It is good to split into smaller interfaces so parts of the code can have smaller dependency but with the current code the input interface for builder should just be a combination of them as nothing has actually changed.
So my suggestions:
- Remove
ContainerBackendinterface - Make
ContainerManagercompletely internal helper(egimageSourcestoday) - Comment on
containerManagerthat this is supposed to go away to avoid anyone adding features to it. /s/ContainerComponent/ExecBackendthat extends theBackend(same way asImageBackendfor example)- Remove changes under api/dockerd.
|
Ok, I think that is a fair compromise. I will make those changes. |
Extract a common function for builder.createContainer Extract imageCache for doing cache probes Removes the cacheBuested field from Builder Create a new containerManager class which reduces the interface between the builder and managing containers to 3 functions (from 6) Signed-off-by: Daniel Nephin <[email protected]>
f7f829b to
19f3b07
Compare
|
I've made those changes, and the build still looks to be green |
Part of the first task in #32904
Remove
tmpContainersfromBuilderand 6 container methods frombuilder.Backend. Replaced withContainerBackendwhich has 3 methods.Remove
cacheBustedandimageCachefromBuilder, replaced with animageProberwhich exposes the cache toBuilder.