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

Move logic out of cmd/lifecycle/analyzer.go #805

Merged
merged 35 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5a4832b
Acceptance tests pass with creator commented out
natalieparellano Feb 22, 2022
ed1b3a7
Fix creator
natalieparellano Feb 22, 2022
fc4a7e3
Add unit tests for analyze inputs
natalieparellano Feb 22, 2022
2b505c6
Add scaffold for analyzer builder unit tests
natalieparellano Feb 22, 2022
6fef994
Add many unit tests, still have some TODOs
natalieparellano Feb 23, 2022
043974b
Address most TODOs
natalieparellano Feb 23, 2022
02a5c74
Acceptance tests pass
natalieparellano Feb 23, 2022
785d81a
A few more TODOs
natalieparellano Feb 23, 2022
e58d007
Bring back go 1.16
natalieparellano Feb 23, 2022
125f01f
Add unit test
natalieparellano Feb 23, 2022
4b4e816
Fix acceptance tests
natalieparellano Feb 24, 2022
8294ea5
Fix units
natalieparellano Feb 24, 2022
fd6beb3
Remove nolint
natalieparellano Feb 24, 2022
8335a56
Remove unneeded things
natalieparellano Feb 24, 2022
9ee1dfd
Use operations pattern
natalieparellano Mar 3, 2022
d21352f
Refactor tests to take advantage of operations pattern
natalieparellano Mar 3, 2022
d81cb6c
Add missing tests
natalieparellano Mar 4, 2022
d815707
Fix lint
natalieparellano Mar 4, 2022
46a24ae
Analyzer factory assigns "nop" services by default
natalieparellano Mar 4, 2022
fe83502
Try to fix registry handler test
natalieparellano Mar 4, 2022
f72848d
Move new package from cmd/lifecycle/platform to platform/inputs
natalieparellano Mar 8, 2022
a457244
Merge branch 'main' into cmd-package
natalieparellano Mar 30, 2022
c828d03
Updates per PR review
natalieparellano Apr 26, 2022
e0e8d8a
Test the platform instead of the exiter
natalieparellano Apr 26, 2022
0af8ab2
Combine cmd/lifecycle/platform and platform
natalieparellano Apr 27, 2022
fcac2e3
Clean up constructors
natalieparellano Apr 27, 2022
59097ca
Remove ForAnalyzer struct
natalieparellano Apr 27, 2022
76811ce
Combine cmd/launcher/platform and platform
natalieparellano Apr 27, 2022
2d4a9bc
Remove comment
natalieparellano Apr 27, 2022
e06cb9c
Remove spec alias
natalieparellano Apr 27, 2022
c982fb1
Move cache metadata back to platform
natalieparellano Apr 28, 2022
4aa3115
Add comment and remove unused vars
natalieparellano Apr 28, 2022
2078007
Merge branch 'main' into cmd-package
natalieparellano Apr 28, 2022
352b6ab
Add test for buildpack incompatibility error
natalieparellano May 3, 2022
20a0110
Fix typo
natalieparellano May 3, 2022
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
10 changes: 5 additions & 5 deletions acceptance/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func testAnalyzerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe
output, err := cmd.CombinedOutput()
h.AssertNotNil(t, err)

h.AssertStringContains(t, string(output), "failed to : ensure registry read access to some-run-image") // TODO: update some-run-image to have explicit permissions when https://github.com/buildpacks/lifecycle/pull/685 is merged
h.AssertStringContains(t, string(output), "ensure registry read access to some-run-image") // TODO: update some-run-image to have explicit permissions when https://github.com/buildpacks/lifecycle/pull/685 is merged
})

when("stack.toml not present", func() {
Expand Down Expand Up @@ -383,7 +383,7 @@ func testAnalyzerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe
})
})

when("the provided destination tags are on different registries", func() {
when.Pend("the provided destination tags are on different registries", func() {
natalieparellano marked this conversation as resolved.
Show resolved Hide resolved
it("errors", func() {
h.SkipIf(t, api.MustParse(platformAPI).LessThan("0.7"), "Platform API < 0.7 does not accept destination tags")

Expand Down Expand Up @@ -931,7 +931,7 @@ func testAnalyzerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe
output, err := cmd.CombinedOutput()

h.AssertNotNil(t, err)
expected := "failed to : ensure registry read access to " + analyzeRegFixtures.InaccessibleImage
expected := "ensure registry read access to " + analyzeRegFixtures.InaccessibleImage
h.AssertStringContains(t, string(output), expected)
})
})
Expand Down Expand Up @@ -1031,7 +1031,7 @@ func testAnalyzerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe
output, err := cmd.CombinedOutput()

h.AssertNotNil(t, err)
expected := "failed to : ensure registry read/write access to " + analyzeRegFixtures.ReadOnlyCacheImage
expected := "ensure registry read/write access to " + analyzeRegFixtures.ReadOnlyCacheImage
h.AssertStringContains(t, string(output), expected)
})
})
Expand Down Expand Up @@ -1104,7 +1104,7 @@ func testAnalyzerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe
output, err := cmd.CombinedOutput()

h.AssertNotNil(t, err)
expected := "failed to : ensure registry read/write access to " + analyzeRegFixtures.InaccessibleImage
expected := "ensure registry read/write access to " + analyzeRegFixtures.InaccessibleImage
h.AssertStringContains(t, string(output), expected)
})
})
Expand Down
9 changes: 5 additions & 4 deletions analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@ func (a *Analyzer) Analyze() (platform.AnalyzedMetadata, error) {
)

if a.PreviousImage != nil { // Previous image is optional in Platform API >= 0.7
previousImageID, err = a.getImageIdentifier(a.PreviousImage)
if err != nil {
if previousImageID, err = a.getImageIdentifier(a.PreviousImage); err != nil {
return platform.AnalyzedMetadata{}, errors.Wrap(err, "retrieving image identifier")
}

// continue even if the label cannot be decoded
if err := image.DecodeLabel(a.PreviousImage, platform.LayerMetadataLabel, &appMeta); err != nil {
if err = image.DecodeLabel(a.PreviousImage, platform.LayerMetadataLabel, &appMeta); err != nil {
appMeta = platform.LayersMetadata{}
}

if err := a.SBOMRestorer.RestoreFromPrevious(a.PreviousImage, bomSHA(appMeta)); err != nil {
if a.SBOMRestorer == nil {
// nop
} else if err = a.SBOMRestorer.RestoreFromPrevious(a.PreviousImage, bomSHA(appMeta)); err != nil {
return platform.AnalyzedMetadata{}, errors.Wrap(err, "retrieving launch sBOM layer")
}
} else {
Expand Down
14 changes: 7 additions & 7 deletions cache/caching_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import (
"github.com/pkg/errors"
)

type cachingImage struct {
type CachingImage struct {
imgutil.Image
cache *VolumeCache
}

func NewCachingImage(image imgutil.Image, cache *VolumeCache) imgutil.Image {
return &cachingImage{
return &CachingImage{
Image: image,
cache: cache,
}
}

func (c *cachingImage) AddLayer(path string) error {
func (c *CachingImage) AddLayer(path string) error {
f, err := os.Open(path)
if err != nil {
return errors.Wrap(err, "opening layer file")
Expand All @@ -38,15 +38,15 @@ func (c *cachingImage) AddLayer(path string) error {
return c.AddLayerWithDiffID(path, diffID)
}

func (c *cachingImage) AddLayerWithDiffID(path string, diffID string) error {
func (c *CachingImage) AddLayerWithDiffID(path string, diffID string) error {
if err := c.cache.AddLayerFile(path, diffID); err != nil {
return err
}

return c.Image.AddLayerWithDiffID(path, diffID)
}

func (c *cachingImage) ReuseLayer(diffID string) error {
func (c *CachingImage) ReuseLayer(diffID string) error {
found, err := c.cache.HasLayer(diffID)
if err != nil {
return err
Expand All @@ -73,7 +73,7 @@ func (c *cachingImage) ReuseLayer(diffID string) error {
return c.cache.AddLayer(rc, diffID)
}

func (c *cachingImage) GetLayer(diffID string) (io.ReadCloser, error) {
func (c *CachingImage) GetLayer(diffID string) (io.ReadCloser, error) {
if found, err := c.cache.HasLayer(diffID); err != nil {
return nil, fmt.Errorf("layer with SHA '%s' not found", diffID)
} else if found {
Expand All @@ -82,7 +82,7 @@ func (c *cachingImage) GetLayer(diffID string) (io.ReadCloser, error) {
return c.Image.GetLayer(diffID)
}

func (c *cachingImage) Save(additionalNames ...string) error {
func (c *CachingImage) Save(additionalNames ...string) error {
err := c.Image.Save(additionalNames...)

if saveSucceededFor(c.Name(), err) {
Expand Down
16 changes: 5 additions & 11 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package cmd

import (
"flag"
"fmt"
"os"
"path/filepath"
"strconv"

"github.com/buildpacks/lifecycle/api"
"github.com/buildpacks/lifecycle/internal/str"
)

var (
Expand Down Expand Up @@ -180,7 +180,7 @@ func FlagStackPath(stackPath *string) {
flagSet.StringVar(stackPath, "stack", EnvOrDefault(EnvStackPath, DefaultStackPath), "path to stack.toml")
}

func FlagTags(tags *StringSlice) {
func FlagTags(tags *str.Slice) {
flagSet.Var(tags, "tag", "additional tags")
}

Expand Down Expand Up @@ -216,15 +216,9 @@ func DeprecatedFlagRunImage(image *string) {
flagSet.StringVar(image, "image", "", "reference to run image")
}

type StringSlice []string

func (s *StringSlice) String() string {
return fmt.Sprintf("%+v", *s)
}

func (s *StringSlice) Set(value string) error {
*s = append(*s, value)
return nil
type StringSlice interface {
String() string
Set(value string) error
}

func intEnv(k string) int {
Expand Down
Loading