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 all commits
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
2 changes: 1 addition & 1 deletion acceptance/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func testAnalyzerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe
analyzer := assertAnalyzedMetadata(t, filepath.Join(copyDir, "analyzed.toml"))
h.AssertNotNil(t, analyzer.RunImage)
analyzedImagePath := filepath.Join(path.RootDir, "layout-repo", "index.docker.io", "library", "busybox", "latest")
reference := fmt.Sprintf("%s@%s", analyzedImagePath, "sha256:834f8848308af7090ed7b2270071d28411afc42078e3ba395b1b0a78e2f8b0e2")
reference := fmt.Sprintf("%s@%s", analyzedImagePath, "sha256:f75f3d1a317fc82c793d567de94fc8df2bece37acd5f2bd364a0d91a0d1f3dab")
Copy link
Member Author

Choose a reason for hiding this comment

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

The previous version of imgutil did not have buildpacks/imgutil#233 and so we mutated the media types, mutating the digest

h.AssertEq(t, analyzer.RunImage.Reference, reference)
})
})
Expand Down
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
2 changes: 1 addition & 1 deletion cmd/lifecycle/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func (e *exportCmd) customSourceDateEpoch() time.Time {
}

func (e *exportCmd) supportsRunImageExtension() bool {
return e.PlatformAPI.AtLeast("0.12") && !e.UseLayout // FIXME: add layout support as part of https://github.com/buildpacks/lifecycle/issues/1057
return e.PlatformAPI.AtLeast("0.12") && !e.UseLayout // FIXME: add layout support as part of https://github.com/buildpacks/lifecycle/issues/1102
}

func (e *exportCmd) supportsHistory() bool {
Expand Down
2 changes: 1 addition & 1 deletion cmd/lifecycle/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (r *restoreCmd) supportsBuildImageExtension() bool {
}

func (r *restoreCmd) supportsRunImageExtension() bool {
return r.PlatformAPI.AtLeast("0.12") && !r.UseLayout // FIXME: add layout support as part of https://github.com/buildpacks/lifecycle/issues/1057
return r.PlatformAPI.AtLeast("0.12") && !r.UseLayout // FIXME: add layout support as part of https://github.com/buildpacks/lifecycle/issues/1102
}

func (r *restoreCmd) supportsTargetData() bool {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require (
github.com/GoogleContainerTools/kaniko v1.20.0
github.com/apex/log v1.9.0
github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.0.0-20231213181459-b0fcec718dc6
github.com/buildpacks/imgutil v0.0.0-20230919143643-4ec9360d5f02
github.com/buildpacks/imgutil v0.0.0-20240206215312-f8d38e1de03d
github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589
github.com/containerd/containerd v1.7.12
github.com/docker/docker v24.0.7+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/buildpacks/imgutil v0.0.0-20230919143643-4ec9360d5f02 h1:Ac/FoFzAhz34zIDvrC3ivShQgoywg/HrA+Kkcb13Mr4=
github.com/buildpacks/imgutil v0.0.0-20230919143643-4ec9360d5f02/go.mod h1:Ade+4Q1OovFw6Zdzd+/UVaqWptZSlpnZ8n/vlkgS7M8=
github.com/buildpacks/imgutil v0.0.0-20240206215312-f8d38e1de03d h1:b/tiReZf9jorbpaOwVw9MX3n99w7Ta4u+SVV7yy6XCE=
github.com/buildpacks/imgutil v0.0.0-20240206215312-f8d38e1de03d/go.mod h1:7zUmt4wkVJNuXCZhQndEd3kvVGmWLVyzRFIQXTaeXlU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
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 @@

"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 @@
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)

Check warning on line 150 in phase/extender.go

View check run for this annotation

Codecov / codecov/patch

phase/extender.go#L150

Added line #L150 was not covered by tests
}
return e.DockerfileApplier.Cleanup()
}
Expand All @@ -166,22 +165,23 @@
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)

Check warning on line 177 in phase/extender.go

View check run for this annotation

Codecov / codecov/patch

phase/extender.go#L177

Added line #L177 was not covered by tests
}
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)

Check warning on line 180 in phase/extender.go

View check run for this annotation

Codecov / codecov/patch

phase/extender.go#L180

Added line #L180 was not covered by tests
}
// 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 @@
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