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

Conversation

natalieparellano
Copy link
Member

@natalieparellano natalieparellano commented Feb 23, 2022

Resolves #635. By moving logic out of main, we can simplify our acceptance tests. It should also make the logic easier to follow (especially with respect to platform api branching).

This still needs a few unit tests (marked with TODO) but I am marking it ready so as to receive feedback on the general direction.

If we like this, I will follow up with another PR to remove a bunch of tests from acceptance/analyzer_test.go.

I am hoping we could use this as a "template" for updating the other phases.

Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Copy link
Contributor

@jabrown85 jabrown85 left a comment

Choose a reason for hiding this comment

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

I didn't do a full review of every line or anything, but I 👍 the direction.

cmd/lifecycle/analyzer.go Show resolved Hide resolved
cmd/lifecycle/platform/analyze_inputs.go Outdated Show resolved Hide resolved
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
@natalieparellano
Copy link
Member Author

@jabrown85 I think this is ready for another review. My only question at this point - what should be the home of github.com/buildpacks/lifecycle/cmd/lifecycle/platform? I was thinking github.com/buildpacks/lifecycle/platform, but I don't want to increase the dependencies of the launcher, which currently uses this package. What about github.com/buildpacks/lifecycle/platform/build and github.com/buildpacks/lifecycle/platform/launch?

Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Copy link
Contributor

@jabrown85 jabrown85 left a comment

Choose a reason for hiding this comment

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

This looks pretty good to me! It is a lot of changes. The tests are happy and I think it reads and feels better.

As far as the final package location goes, I think I like github.com/buildpacks/lifecycle/platform and github.com/buildpacks/lifecycle/platform/launch for the launcher specific deps. I think the naming is good for the one we use most of time and having a specific /launch package for the launch-specific things feels good. I am also happy to discuss alternatives on naming

@natalieparellano
Copy link
Member Author

natalieparellano commented Mar 7, 2022

@jabrown85 I took a look at this today... the problem with putting everything that's currently in github.com/buildpacks/lifecycle/cmd/lifecycle/platform in github.com/buildpacks/lifecycle/platform is that it creates an import cycle:

package command-line-arguments
        imports github.com/buildpacks/lifecycle
        imports github.com/buildpacks/lifecycle/internal/layer
        imports github.com/buildpacks/lifecycle/platform    <---- things like platform.LayersMetadata
        imports github.com/buildpacks/lifecycle: import cycle not allowed

It also feels weird putting things like AnalyzeInputsResolver and LayersMetadata in the same package, because they have totally different consumers.

What about github.com/buildpacks/lifecycle/platform/cmd and github.com/buildpacks/lifecycle/platform/launch/cmd? Or something else?

Edit: I copy/pasted wrong before... fixed it ^^

@jabrown85
Copy link
Contributor

What about github.com/buildpacks/lifecycle/cmd/lifecycle/platform/cmd and github.com/buildpacks/lifecycle/cmd/lifecycle/platform/launch/cmd? Or something else?

Would github.com/buildpacks/lifecycle/cli and github.com/buildpacks/lifecycle/cli/launch or github.com/buildpacks/lifecycle/cli/platform/github.com/buildpacks/lifecycle/cli/launch work?

If not, I'm also ok with github.com/buildpacks/lifecycle/cmd/lifecycle/platform/cmd, but don't really like the duplicate cmd in the same import. It feels bleh.

Comment on lines +44 to +45
LayersDir: opts.LayersDir,
Logger: opts.Logger,
Copy link
Member Author

Choose a reason for hiding this comment

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

These could maybe be made private

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah - I made them public so they could be tested here:

lifecycle/analyzer_test.go

Lines 104 to 105 in 8b9e787

h.AssertEq(t, sbomRestorer.LayersDir, "some-layers-dir")
h.AssertEq(t, sbomRestorer.Logger, logger)

Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
With some small changes to avoid an import cycle, we can make a meaningful platform package

Signed-off-by: Natalie Arellano <narellano@vmware.com>
Eventually only the platform package should switch on platform api

Signed-off-by: Natalie Arellano <narellano@vmware.com>
Having the analyzer factory take a list of args will ensure we don't forget
to update the creator when things change.

Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
RestoresLayerMetadata bool
}

func (f *AnalyzerFactory) NewAnalyzer(
Copy link
Member Author

Choose a reason for hiding this comment

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

In the past, adding new inputs to the analyzer/restorer/etc. was a source of bugs because we would forget to update the creator. Accepting the inputs as a list, while ugly, can avoid this problem.

return &DefaultConfigHandler{}
}

func (h *DefaultConfigHandler) ReadGroup(path string) ([]buildpack.GroupBuildpack, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted this to be in the lifecycle package, but its dependence on verifyBuildpackApis (and needing to return the correct error code) made things a bit complicated.

Signed-off-by: Natalie Arellano <narellano@vmware.com>
func (p *Platform) API() *api.Version {
return p.api
}

// InputsResolver resolves inputs for each of the lifecycle phases.
Copy link
Member Author

Choose a reason for hiding this comment

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

Hopefully, eventually! (for now just analyze...)

@@ -0,0 +1,56 @@
package platform
Copy link
Member Author

Choose a reason for hiding this comment

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

These functions should eventually go somewhere else... but I think their new homes will be created when we do additional cleanup as part of buildpacks/rfcs#217

The lifecycle shouldn't have to depend on the cache package, just the interface

Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
Copy link
Contributor

@mboldt mboldt left a comment

Choose a reason for hiding this comment

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

Chatted with @natalieparellano - looks good!

Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
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.

Move logic out of cmd/analyzer
3 participants