google / google/go-containerregistry

Replace tarball.LayerFromOpener with stream.NewLayer

Open
#413 1 comment 0 reactions 0 assignees View on GitHub
abstraction lifecycle/frozen
Dominant language
Go
Stars
4k
Forks
686
Avg merge
2d 12h
Merged PRs (30d)
26

Description

The `tarball` package has methods for reading/writing images from/to the `docker save` tarball format. This aligns with how the other packages are organized, for example:
* `remote` is for reading/writing from/to registries.
* `daemon` is for reading/writing from/to container daemons.
* `layout` is for reading/writing from/to OCI image layouts.

However, the `tarball` package _also_ has methods for constructing `v1.Layer`s from a file or from an `Opener`. It _kind of_ makes sense to be in the `tarball` package because the layers happen to be compressed tarballs, but really that's an implementation detail. These functions aren't for tarball-specific layers, they're just for layers in general.

We should try to replace these with `stream.Layer` wherever we can. The `tarball.Layer` currently reads the whole tarball twice because it eagerly computes the digest/size/diffid. For uncompressed layers, `stream.Layer` is just better.

For compressed layers, we usually have some metadata that makes eagerly computing those things unnecessary (e.g. `remoteLayer`). For reading compressed layer from a `tarball.Image`, we should know the diffids from the config file.

tl;dr `LayerFromOpener` is bad, let's make `stream.Layer` work. I elaborated on this a bit [here](https://github.com/google/go-containerregistry/issues/412#issuecomment-474043461).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.