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

Implement gz compression #153

Merged
merged 3 commits into from
Sep 12, 2022
Merged

Implement gz compression #153

merged 3 commits into from
Sep 12, 2022

Conversation

eerhardt
Copy link
Member

@eerhardt eerhardt commented Aug 29, 2022

Compressing the .tar files to make the layer files smaller.

Fix #29

cc @rainersigwald

Are there other tests I should be adding / modifying?

Add test for UncompressedDigest

Fix dotnet#29
Fix tests
Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

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

Thanks!

@eerhardt
Copy link
Member Author

Are there instructions to manually test this out myself? Or are the automated tests good enough?

@rainersigwald
Copy link
Member

@benvillalobos do you have the manual use-just-built-package steps written down? If not can you?

@rainersigwald
Copy link
Member

However I'd expect the push-to-local-Docker-registry tests to exercise this codepath--if you can validate that with a breakpoint @eerhardt I think we'd be good to move forward.

@baronfel
Copy link
Member

baronfel commented Aug 31, 2022

We should add something to to devguide here, but my overall process is:

  • have a machine-level nuget source: dotnet nuget add source <PATH> -n local
  • build this repo and note the package path and version
  • push the generated package to the local source: dotnet nuget push <path to nupkg> -s local
  • in a test project add the new package version: dotnet add package Microsoft.NET.Build.Containers --version <version>
  • publish the test project (probably with a binlog): dotnet publish -p:PublishProfile=DefaultContainer --os linux --arch x64 -c Release -bl

one downside to this is that you pollute your global nuget cache with the intermediate packages, but that's a failing of the overall nuget cache design and not something we can really mitigate. just gotta purge it every so often I suppose.

@eerhardt
Copy link
Member Author

However I'd expect the push-to-local-Docker-registry tests to exercise this codepath--if you can validate that with a breakpoint @eerhardt I think we'd be good to move forward.

This test was definitely broken when my code wasn't working:

public async Task ApiEndToEndWithRegistryPushAndPull()
{
string publishDirectory = await BuildLocalApp();
// Build the image
Registry registry = new Registry(new Uri($"http://{DockerRegistryManager.LocalRegistry}"));
Image x = await registry.GetImageManifest(DockerRegistryManager.BaseImage, DockerRegistryManager.BaseImageTag);
Layer l = Layer.FromDirectory(publishDirectory, "/app");
x.AddLayer(l);
x.SetEntrypoint(new [] {"/app/MinimalTestApp" });
// Push the image back to the local registry
await registry.Push(x, NewImageName, "latest", DockerRegistryManager.BaseImage);
// pull it back locally
Process pull = Process.Start("docker", $"pull {DockerRegistryManager.LocalRegistry}/{NewImageName}:latest");
Assert.IsNotNull(pull);
await pull.WaitForExitAsync();
Assert.AreEqual(0, pull.ExitCode);
// Run the image
ProcessStartInfo runInfo = new("docker", $"run --rm --tty {DockerRegistryManager.LocalRegistry}/{NewImageName}:latest");
Process run = Process.Start(runInfo);
Assert.IsNotNull(run);
await run.WaitForExitAsync();
Assert.AreEqual(0, run.ExitCode);
}

We should add something to to devguide here

I can try out these steps and submit a PR to update the dev guide.

@benvillalobos
Copy link
Member

benvillalobos commented Aug 31, 2022

@rainersigwald I do not! The steps would be in our E2E tests. Something very close to:

dotnet new webapi -f net7.0
dotnet new nugetconfig
dotnet add source path/to/local/folder-for-nuget-source --name foo Create a local source to push to
dotnet nuget push path/to/this-repo/bin/Microsoft.NET.Build.Containers.nupkg --source foo Push package to that local folder source.
dotnet add package add Microsoft.NET.Build.Containers --prerelease Add the package to your test project. NOTE: This will also add it to your nuget cache, so you'll need to clear this package after each test.
dotnet publish /p:publishprofile=defaultcontainer /p:runtimeidentifier=linux-x64 /p:ContainerBaseImage=<> /p:ContainerRegistry=<> /p:ContainerImageName=<> /p:Version=<> /bl

This is how I went about testing before we had UT's, starting from scratch.

cc @eerhardt

edit: looks like I missed #154 :)

Copy link
Member

@carlossanlop carlossanlop left a comment

Choose a reason for hiding this comment

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

LGTM. Nothing blocking. Left 3 questions.

Microsoft.NET.Build.Containers/Layer.cs Show resolved Hide resolved
Microsoft.NET.Build.Containers/Layer.cs Show resolved Hide resolved
Comment on lines +41 to +42
// Docker treats a COPY instruction that copies to a path like `/app` by
// including `app/` as a directory, with no leading slash. Emulate that here.
Copy link
Member

Choose a reason for hiding this comment

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

@rainersigwald I know this was before the PR, but I'm not understanding this comment clearly: Is /app being prefixed or suffixed to the file path?

I ask because if it's a prefix, and it needs to be removed, we could try using the stream-based TarFile.CreateFromDirectory with includeBaseDirectory=false, see if that works.

If that's not what the comment meant, then nothing to do here.

@eerhardt
Copy link
Member Author

eerhardt commented Sep 1, 2022

I was able to test this end-to-end with a basic ASP.NET app that uses ML.NET (using the above instructions).

Using the 1.8.0 version from nuget.org, the .tar file in my %TEMP%\Containers\Content is 15.8 MB.

Using my local build of this PR with the exact same app, the .tar file in my %TEMP%\Containers\Content is 4.58 MB.

@eerhardt
Copy link
Member Author

eerhardt commented Sep 8, 2022

Any thoughts on when this can be merged?

@baronfel
Copy link
Member

This LGTM and @rainersigwald approved, so I'm merging.

@baronfel baronfel merged commit 33bda06 into dotnet:main Sep 12, 2022
@eerhardt eerhardt deleted the UseGZ branch September 12, 2022 19:08
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.

Enable gzip for layers
5 participants