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

Bumps imgutil to pick up layout package refactor & local package fix … #1281

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove selective package, use sparse instead
Signed-off-by: Natalie Arellano <narellano@vmware.com>
  • Loading branch information
natalieparellano committed Feb 7, 2024
commit c9c0e18b0c9d42c49a211e5e0e78938c1d693553
8 changes: 4 additions & 4 deletions acceptance/extender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"runtime"
"testing"

"github.com/buildpacks/imgutil/layout/sparse"
"github.com/google/go-containerregistry/pkg/authn"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/empty"
"github.com/google/go-containerregistry/pkg/v1/layout"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/sclevine/spec"
Expand All @@ -22,7 +22,6 @@ import (
"github.com/buildpacks/lifecycle/api"
"github.com/buildpacks/lifecycle/auth"
"github.com/buildpacks/lifecycle/cmd"
"github.com/buildpacks/lifecycle/internal/selective"
"github.com/buildpacks/lifecycle/platform/files"
h "github.com/buildpacks/lifecycle/testhelpers"
)
Expand Down Expand Up @@ -105,9 +104,10 @@ func testExtenderFunc(platformAPI string) func(t *testing.T, when spec.G, it spe
baseCacheDir := filepath.Join(kanikoDir, "cache", "base")
h.AssertNil(t, os.MkdirAll(baseCacheDir, 0755))

layoutPath, err := selective.Write(filepath.Join(baseCacheDir, baseImageDigest), empty.Index)
// write sparse image
layoutImage, err := sparse.NewImage(filepath.Join(baseCacheDir, baseImageDigest), remoteImage)
h.AssertNil(t, err)
h.AssertNil(t, layoutPath.AppendImage(remoteImage))
h.AssertNil(t, layoutImage.Save())

// write image reference in analyzed.toml
analyzedMD := files.Analyzed{
Expand Down
7 changes: 0 additions & 7 deletions internal/selective/layoutpath.go

This file was deleted.

85 changes: 0 additions & 85 deletions internal/selective/write.go

This file was deleted.

119 changes: 0 additions & 119 deletions internal/selective/write_test.go

This file was deleted.

24 changes: 12 additions & 12 deletions phase/extender.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import (

"github.com/BurntSushi/toml"
"github.com/buildpacks/imgutil"
"github.com/buildpacks/imgutil/layout/sparse"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/empty"
"github.com/google/go-containerregistry/pkg/v1/mutate"
"github.com/google/uuid"
"golang.org/x/sync/errgroup"

"github.com/buildpacks/lifecycle/buildpack"
"github.com/buildpacks/lifecycle/internal/extend"
"github.com/buildpacks/lifecycle/internal/selective"
"github.com/buildpacks/lifecycle/launch"
"github.com/buildpacks/lifecycle/layers"
"github.com/buildpacks/lifecycle/log"
Expand Down Expand Up @@ -147,8 +146,8 @@ func (e *Extender) extendRun(logger log.Logger) error {
return fmt.Errorf("extending run image: %w", err)
}

if err = e.saveSelective(extendedImage, origTopLayer); err != nil {
return fmt.Errorf("copying selective image to output directory: %w", err)
if err = e.saveSparse(extendedImage, origTopLayer); err != nil {
return fmt.Errorf("copying extended image to output directory: %w", err)
}
return e.DockerfileApplier.Cleanup()
}
Expand All @@ -166,22 +165,23 @@ func topLayer(image v1.Image) (string, error) {
return layer.Digest.String(), nil
}

func (e *Extender) saveSelective(image v1.Image, origTopLayerHash string) error {
func (e *Extender) saveSparse(image v1.Image, origTopLayerHash string) error {
// save sparse image (manifest and config)
imageHash, err := image.Digest()
if err != nil {
return fmt.Errorf("getting image hash: %w", err)
}
toPath := filepath.Join(e.ExtendedDir, "run", imageHash.String())
layoutPath, err := selective.Write(toPath, empty.Index) // FIXME: this should use the imgutil layout/sparse package instead, but for some reason sparse.NewImage().Save() fails when the provided base image is already sparse
layoutImage, err := sparse.NewImage(toPath, image)
if err != nil {
return fmt.Errorf("initializing selective image: %w", err)
return fmt.Errorf("failed to initialize image: %w", err)
}
if err = layoutPath.AppendImage(image); err != nil {
return fmt.Errorf("saving selective image: %w", err)
if err := layoutImage.Save(); err != nil {
return fmt.Errorf("failed to save image: %w", err)
}
// get all image layers (we will only copy those following the original top layer)
layers, err := image.Layers()
// copy only the extended layers (those following the original top layer) to the layout path
// FIXME: it would be nice if this were supported natively in imgutil
allLayers, err := image.Layers()
if err != nil {
return fmt.Errorf("getting image layers: %w", err)
}
Expand All @@ -193,7 +193,7 @@ func (e *Extender) saveSelective(image v1.Image, origTopLayerHash string) error
needsCopying = true
}
group, _ := errgroup.WithContext(context.TODO())
for _, currentLayer := range layers {
for _, currentLayer := range allLayers {
currentHash, err = currentLayer.Digest()
if err != nil {
return fmt.Errorf("getting layer hash: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion phase/extender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func testExtender(t *testing.T, when spec.G, it spec.S) {
someFakeImage.ConfigFileReturnsOnCall(3, secondConfig, nil)
someFakeImage.ConfigFileReturnsOnCall(4, secondConfig, nil)

// save selective
// save without base layers

imageHash := v1.Hash{Algorithm: "sha256", Hex: "some-image-hex"}
someFakeImage.DigestReturns(imageHash, nil)
Expand Down
Loading