Support stargz snapshotter for dev stages#1402
Conversation
8ed56b6 to
9deafbb
Compare
|
Can we have integration tests? |
cmd/buildkitd/main_oci_worker.go
Outdated
| newFunc := func(root string) (ctdsnapshot.Snapshotter, error) { | ||
| gopts := []grpc.DialOption{ | ||
| grpc.WithInsecure(), | ||
| grpc.WithBackoffMaxDelay(3 * time.Second), |
There was a problem hiding this comment.
WithBackoffMaxDelay is deprecated
There was a problem hiding this comment.
There was a problem hiding this comment.
Thanks for your feedback. I fixed it.
cmd/buildkitd/main_oci_worker.go
Outdated
| }, | ||
| cli.StringFlag{ | ||
| Name: "oci-worker-proxy-snapshotter-address", | ||
| Usage: "use proxy snapshotter at specified address", |
There was a problem hiding this comment.
Thanks for your feedback. Explicitly described not to include unix:// prefix and added small validation against the specified path.
There was a problem hiding this comment.
imho *-address should have protocol, *-path or *-socket doesn't need to.
a58eebe to
425c1c7
Compare
|
I'm currently working on the benchmarking and let me share the latest benchmarking results for building sample images(benchmarking scripts are here). I'll work on integration tests soon.
Please note each build's initial state; there is no content on the cache(so pulling base images occur for each build). With OCI workerWith containerd worker |
2398937 to
d8135be
Compare
|
Added unit and integration testes and fixed some bugs to make them happy. Containerd hasn't released remote-snapshots-related patches yet(but already merged) so current integration testes are for oci worker. After these patches are released, we can apply tests for containerd worker with another PR. PTAL:pray: |
|
@tonistiigi WDYT? |
tonistiigi
left a comment
There was a problem hiding this comment.
I don't like that this is controlled from the Dockerfile frontend. Frontends/LLB shouldn't optimize for a specific backend implementation. Not sure how it even works, if you rebuild with different targets and get previous cache. And layer being in a target stage does not mean it is exported (same as it not being it target stage doesn't mean it never will be exported). Every record should be exportable with every exporter (the timing can be different for different implementations, eg. #870 )
This is based on a very minimal review, so lmk if I missed anything.
|
@tonistiigi Thanks for you feedbacks and pointer! #870 seems to have same motivation with this patch in terms of defering pulling layers until when it's actually needed. From #870,
Now containerd doesn't require layers being locally available even to exec something on them if these layers are remote snapshots. So in this case, we can hopefully defer the pulling (= changing the type from remote to immutableref) even until export occurs and we don't need to pull nor have immutablerefs for all unexported layers, without inconsistency. This patch initially aimed to enable bulidkit to use the containerd's remote snapshots from scratch but now I think this feature can be applied more simply on #870 as an advanced optimization as mentioned above. Do you have plans to move #870 forward? |
Yes, it is fine to run a container without all the snapshots/blobs locally if the implementation supports it. But at any point the record used by that container or any other part of the build should remain exportable. This also complicates caching a lot. It is possible that the cache needs to store the registry ref where the rest of the data can be pulled and loading from a cache needs to check if the new build still has access to the remote resource.
More likely I think the design is that immutableref can have this separate implementation. If you would make some parts of build work on something else than immutableref this would be a lot of exceptions.
I probably don't have time to work on it on near future. But I can give you design direction if you are interested. @hinshun and I have also been discussing something called |
|
Thanks! I'll take a look at. |
e21ee71 to
46c4626
Compare
|
I've ported this PR over the lazy ref logic (#1475). Thanks for the great work! Based on that logic, the new patch doesn't require changes on the frontend and remote snapshots seem to be able to be used with immutableRefs with keeping them safely exportable. The following is a summary of the design in the new patch.
@tonistiigi @AkihiroSuda What do you think about the above design? Please tell me if I'm missing something. |
|
cc @sipsma |
|
@ktock panic in CI |
46c4626 to
6902261
Compare
|
@tonistiigi Thanks for the comment. Fixed the panic. |
source/containerimage/pull.go
Outdated
| for _, desc := range p.manifest.Remote.Descriptors { | ||
| layers += fmt.Sprintf("%s,", desc.Digest.String()) | ||
| } | ||
| if len(layers) >= 1 { |
There was a problem hiding this comment.
use strings.TrimSuffix to trim the extra ,.
Or consider using strings.Join
6902261 to
b81e1a3
Compare
| return sr.extract(ctx, sr.descHandlers) | ||
| } | ||
|
|
||
| func (sr *immutableRef) prepareRemoteSnapshots(ctx context.Context, dhs DescHandlers) (bool, error) { |
There was a problem hiding this comment.
nit: I think this method may as well be wrapped in a flightcontrol.Group, similar to sr.extract, just to de-dupe some work when possible.
There was a problem hiding this comment.
Thanks for the feedback! Fixed to use fileghtcontrol.Group.
b81e1a3 to
a2415fc
Compare
Signed-off-by: ktock <ktokunaga.mail@gmail.com>
6388c6c to
7e25d84
Compare
|
Thanks for the feedback. Added test for this PR. |
|
|
||
| // Check if image layers are lazy | ||
| var layers []ocispec.Descriptor | ||
| for _, layer := range manifest.Layers[:len(manifest.Layers)-1] { |
There was a problem hiding this comment.
Why check all but the last layer? Something to do with stargz? Would be good to have a comment for.
There was a problem hiding this comment.
Thanks for the comment. This is because the topmost layer (created by running a command on that stargz image) isn't lazy. I added comments about this and also added a check to make sure that the topmost layer isn't lazy.
There was a problem hiding this comment.
Ohh duh, forgot that the topmost layer was created by run, makes sense, thanks
7e25d84 to
95add53
Compare
Signed-off-by: ktock <ktokunaga.mail@gmail.com>
95add53 to
7618920
Compare


Related issues:
Throughout building steps, "pulling base image" is one of the time-consuming steps.
Recently, containerd community started "Stargz Snapshotter" (containerd/stargz-snapshotter) non-core subproject for speeding up image pulling. With this snapshotter, we can directly mount stargz-formatted (but still docker-compatible) image to nodes, which takes much shorter than downloading the whole of the image to nodes.
This commit solves the performance problem on pulling base images for "dev" stages using stargz snapshotter.
We introduced new RecordType "snapshot" for unexported base images. These images aren't guaranteed to have their whole contents in the content store but snapshots (possibly "remote" snapshots) are provided. Target (exported) base images don't have this type because its contents need to be fully available on the node for exportation.
We can test this patch with stargz snapshotter on this branch (Please also see this instruction).
We can see the benchmarking result with sample image on containerd/stargz-snapshotter#53 (comment).
This PR also intends to be a discussion thread for the design and implementation strategies of this feature so if there is a better one please tell us.