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

Produce an image as .tar.gz #283

Closed
stan-sz opened this issue Jan 9, 2023 · 7 comments
Closed

Produce an image as .tar.gz #283

stan-sz opened this issue Jan 9, 2023 · 7 comments
Assignees
Labels
Area: Task Partner request Things that internal or external teams have explicitly requested
Milestone

Comments

@stan-sz
Copy link

stan-sz commented Jan 9, 2023

Can the SDK produce the docker image as a local .tar.gz as in docker save comand?

@baronfel
Copy link
Member

Not yet, but it's definitely something that is doable. Jib does it, for example. Is this something you'd be interested in digging into? We'd need

  • a way to signal this from MSBuild properties
  • a new 'output' mechanism in the CreateNewImage build task that would stream the generate archive similar to the existing Docker.Load API, but directly to a file.

@stan-sz
Copy link
Author

stan-sz commented Jan 11, 2023

Thanks for the hints. I cannot dig to it at the moment, but it's up-for-grabs for anyone willing to.

@baronfel baronfel added the Partner request Things that internal or external teams have explicitly requested label Jan 20, 2023
@MattKotsenas
Copy link
Member

This is something I'd be interested in as well. I'm new to this project, but if it's something that is easy for a new person to get ramped up on, I'd be willing to contribute here.

@rainersigwald
Copy link
Member

Awesome @MattKotsenas! I'll assign to you.

This should be fairly straightforward to implement, but will require some thought about how the user will request it.

The implementation will be very close to this part of the LocalDocker workflow:

public static async Task WriteImageToStream(Image x, string name, string tag, Stream imageStream)
{
TarWriter writer = new(imageStream, TarEntryFormat.Gnu, leaveOpen: true);
// Feed each layer tarball into the stream
JsonArray layerTarballPaths = new JsonArray();
foreach (var d in x.LayerDescriptors)
{
if (x.originatingRegistry is {} registry)
{
string localPath = await registry.DownloadBlob(x.OriginatingName, d);
// Stuff that (uncompressed) tarball into the image tar stream
// TODO uncompress!!
string layerTarballPath = $"{d.Digest.Substring("sha256:".Length)}/layer.tar";
await writer.WriteEntryAsync(localPath, layerTarballPath);
layerTarballPaths.Add(layerTarballPath);
}
else

That creates a stream basically equivalent to what docker save does, but doesn't save it to disk, instead it streams it to docker load's stdin. If you were to instead put it in a file, that would be a big step here!

@Danielku15
Copy link
Contributor

I opened a proposal for a new option here: #375

I have successfully used a similar approach on my earlier changes where I added the Windows Container Support and fixed the Tar format writing for LCOW.

There are still some design decisions to take but the PR might give a base for discussion:

  • How to handle the multiple output file naming (is it even needed to have multiple tars for all 'destinations')
  • New dedicated option vs. a local file ILocalDaemon
  • (anything else?)

@stan-sz
Copy link
Author

stan-sz commented Mar 6, 2023

Thank you @Danielku15!

@baronfel
Copy link
Member

baronfel commented Oct 2, 2023

Closing because @Danielku15 implemented this in dotnet/sdk#35151, which will ship in .NET 8.0.100 RC2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Task Partner request Things that internal or external teams have explicitly requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants