Skip to content
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

oci exporter: support exporting directories #3162

Merged
merged 4 commits into from
Nov 18, 2022

Conversation

jedevc
Copy link
Member

@jedevc jedevc commented Oct 11, 2022

Fixes #1219.

This feature adds support for specifying unpack=true to the oci exporter options to unpack the resulting result for the client.

This requires changes to the client to ensure that when unpack=true is provided, we expose a directory instead of a single file.

Because of how the containerd API is designed, the image layout file structure is only directly exposed as part of the archiveexporter.Export method which produces a tar - so we need to unpack it on the buildkit server before syncing it back to the client. I can't quite work out if there's a better way to do this without needing to change the containerd API.

@jedevc jedevc force-pushed the oci-unpack-tar branch 2 times, most recently from fbb2535 to fac3190 Compare October 12, 2022 15:59
@jedevc jedevc marked this pull request as ready for review October 12, 2022 16:00
Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

I imagined this a bit differently. Instead of unpacking and transferring files via local exporter the client side could open up a contentstore (see how --cache-to type=local works) and instead of setting up tarball at all the daemon side would copy the blobs over to the client-side contentstore. So there is no tarball or extract and when exporting blobs that are already available on the client side they would be just skipped.

The current implementation is just equivalent to build | tar x iiuc.

@jedevc jedevc force-pushed the oci-unpack-tar branch 3 times, most recently from b5ef5ea to 95e8133 Compare October 18, 2022 13:43
@jedevc
Copy link
Member Author

jedevc commented Oct 18, 2022

Have done an update to use a contentstore, the oci exporter can then use the contentutil.CopyChain function to copy everything over to the client properly. I've also added support for writing back an index.json file similar to the local cache. I think I'll come back and do a refactor of some of that code at some point, probably once #3118 merges, since the code touches similar parts of the codebase.

I've also added a commit to fix an inconsistency - we were prefixing the stores for local cache with local:, but weren't doing the same for OCI stores specified on the command line. I've fixed that so we prefix with oci: (which means we can't get any naming clashes as well) - this will need a corresponding update in buildx if we go through with that.

@tonistiigi tonistiigi added this to the v0.11.0 milestone Nov 7, 2022
client/client_test.go Outdated Show resolved Hide resolved
if err != nil {
return nil, err
}
contentStores["export"] = cs
Copy link
Member

Choose a reason for hiding this comment

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

If you want to make sure this does not collide then add a random suffix and send the full contentstore id in exporter attributes.

}
switch ex.Type {
case ExporterOCI, ExporterDocker:
if err := os.MkdirAll(ex.OutputDir, 0755); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Is this a different behavior from local where directory is created early even for broken builds(not a big issue).

Also looks like local defaults to 0700? https://github.com/moby/buildkit/blob/master/session/filesync/diffcopy.go#L102

Copy link
Member Author

Choose a reason for hiding this comment

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

As written the oci unpack=true is more similar to --export-cache type=local than it is to --output type=local (since it uses a content store).

See https://github.com/jedevc/buildkit/blob/oci-unpack-tar/client/solve.go#L466-L472 for how we create the directory using 0755 - maybe it's worth consistentizing all of these?

I don't think we can avoid not making the directory here, we'd otherwise have to wait until the first write to the content store by creating a new interface to defer the creation of the directory.

@jedevc jedevc force-pushed the oci-unpack-tar branch 2 times, most recently from 7a777ec to e7064e2 Compare November 15, 2022 16:40
This feature adds support for specifying unpack=true to the oci exporter
options to unpack the resulting result for the client.

To do this, we setup a content store on the client, and forward it
through to the server, which can then copy the exported data into the
content store.

Signed-off-by: Justin Chadwell <me@jedevc.com>
Signed-off-by: Justin Chadwell <me@jedevc.com>
This mirrors the structure of the names for the local cache directory,
as well as the names for the oci exporter (when using a content store).
This ensures that we cannot encounter name collisions (intentionally or
unintentionally).

Signed-off-by: Justin Chadwell <me@jedevc.com>
Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

Is there another name we could use here? The current name suggests that the tar is unpacked(and that this feature is much less useful). tar=false ?

@jedevc
Copy link
Member Author

jedevc commented Nov 17, 2022

Agreed, tar=false feels easier.

I think it might be worth revisiting some of the exporters at some point, especially tar + local, to see if we can merge similar behaviour, since a tar=<bool> there might also make sense.

cmd/buildctl/build/output.go Outdated Show resolved Hide resolved
Signed-off-by: Justin Chadwell <me@jedevc.com>
@tonistiigi tonistiigi merged commit f3c07ce into moby:master Nov 18, 2022
@tonistiigi
Copy link
Member

@jedevc Note that this needs buildx update as well.

@alexcb alexcb mentioned this pull request Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow outputting an OCI image layout directory
2 participants