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

Use draft.Planner from packit directly #213

Merged
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
16 changes: 5 additions & 11 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,17 @@ import (

"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/chronos"
"github.com/paketo-buildpacks/packit/v2/draft"
"github.com/paketo-buildpacks/packit/v2/postal"
"github.com/paketo-buildpacks/packit/v2/sbom"
"github.com/paketo-buildpacks/packit/v2/scribe"
)

//go:generate faux --interface EntryResolver --output fakes/entry_resolver.go
//go:generate faux --interface DependencyManager --output fakes/dependency_manager.go
//go:generate faux --interface InstallProcess --output fakes/install_process.go
//go:generate faux --interface SitePackageProcess --output fakes/site_package_process.go
//go:generate faux --interface SBOMGenerator --output fakes/sbom_generator.go

// EntryResolver defines the interface for picking the most relevant entry from
// the Buildpack Plan entries.
type EntryResolver interface {
Resolve(string, []packit.BuildpackPlanEntry, []interface{}) (packit.BuildpackPlanEntry, []packit.BuildpackPlanEntry)
MergeLayerTypes(string, []packit.BuildpackPlanEntry) (launch, build bool)
}

// DependencyManager defines the interface for picking the best matching
// dependency and installing it.
type DependencyManager interface {
Expand Down Expand Up @@ -56,7 +49,6 @@ type SBOMGenerator interface {
// layer, and generate Bill-of-Materials. It also makes use of the checksum of
// the dependency to reuse the layer when possible.
func Build(
entryResolver EntryResolver,
dependencyManager DependencyManager,
installProcess InstallProcess,
siteProcess SitePackageProcess,
Expand All @@ -67,8 +59,10 @@ func Build(
return func(context packit.BuildContext) (packit.BuildResult, error) {
logger.Title("%s %s", context.BuildpackInfo.Name, context.BuildpackInfo.Version)

planner := draft.NewPlanner()

logger.Process("Resolving Pipenv version")
entry, sortedEntries := entryResolver.Resolve(Pipenv, context.Plan.Entries, Priorities)
entry, sortedEntries := planner.Resolve(Pipenv, context.Plan.Entries, Priorities)

logger.Candidates(sortedEntries)

Expand All @@ -82,7 +76,7 @@ func Build(
logger.SelectedDependency(entry, dependency, clock.Now())

legacySBOM := dependencyManager.GenerateBillOfMaterials(dependency)
launch, build := entryResolver.MergeLayerTypes(Pipenv, context.Plan.Entries)
launch, build := planner.MergeLayerTypes(Pipenv, context.Plan.Entries)

var launchMetadata packit.LaunchMetadata
if launch {
Expand Down
30 changes: 6 additions & 24 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
layersDir string
cnbDir string

entryResolver *fakes.EntryResolver
dependencyManager *fakes.DependencyManager
installProcess *fakes.InstallProcess
siteProcess *fakes.SitePackageProcess
Expand All @@ -52,11 +51,6 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
cnbDir, err = os.MkdirTemp("", "cnb")
Expect(err).NotTo(HaveOccurred())

entryResolver = &fakes.EntryResolver{}
entryResolver.ResolveCall.Returns.BuildpackPlanEntry = packit.BuildpackPlanEntry{
Name: "pipenv",
}

dependencyManager = &fakes.DependencyManager{}
dependencyManager.ResolveCall.Returns.Dependency = postal.Dependency{
ID: "pipenv",
Expand Down Expand Up @@ -95,7 +89,6 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
siteProcess.ExecuteCall.Returns.String = filepath.Join(layersDir, "pipenv", "lib", "python3.8", "site-packages")

build = pipenv.Build(
entryResolver,
dependencyManager,
installProcess,
siteProcess,
Expand Down Expand Up @@ -166,12 +159,6 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
},
}))

Expect(entryResolver.ResolveCall.Receives.String).To(Equal("pipenv"))
Expect(entryResolver.ResolveCall.Receives.BuildpackPlanEntrySlice).To(Equal([]packit.BuildpackPlanEntry{
{Name: "pipenv"},
}))
Expect(entryResolver.ResolveCall.Receives.InterfaceSlice).To(Equal([]interface{}{"BP_PIPENV_VERSION"}))

Expect(dependencyManager.ResolveCall.Receives.Path).To(Equal(filepath.Join(cnbDir, "buildpack.toml")))
Expect(dependencyManager.ResolveCall.Receives.Id).To(Equal("pipenv"))
Expect(dependencyManager.ResolveCall.Receives.Version).To(Equal(""))
Expand All @@ -188,13 +175,6 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
},
}))

Expect(entryResolver.MergeLayerTypesCall.Receives.String).To(Equal("pipenv"))
Expect(entryResolver.MergeLayerTypesCall.Receives.BuildpackPlanEntrySlice).To(Equal([]packit.BuildpackPlanEntry{
{
Name: "pipenv",
},
}))

Expect(dependencyManager.DeliverCall.Receives.Dependency).To(Equal(postal.Dependency{
ID: "pipenv",
Name: "pipenv-dependency-name",
Expand All @@ -215,8 +195,9 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {

context("when build plan entries require pipenv at build/launch", func() {
it.Before(func() {
entryResolver.MergeLayerTypesCall.Returns.Build = true
entryResolver.MergeLayerTypesCall.Returns.Launch = true
buildContext.Plan.Entries[0].Metadata = make(map[string]interface{})
joshuatcasey marked this conversation as resolved.
Show resolved Hide resolved
buildContext.Plan.Entries[0].Metadata["build"] = true
buildContext.Plan.Entries[0].Metadata["launch"] = true
})

it("makes the layer available at the right times", func() {
Expand Down Expand Up @@ -275,8 +256,9 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
`, pipenv.DependencySHAKey)), os.ModePerm)
Expect(err).NotTo(HaveOccurred())

entryResolver.MergeLayerTypesCall.Returns.Build = true
entryResolver.MergeLayerTypesCall.Returns.Launch = false
buildContext.Plan.Entries[0].Metadata = make(map[string]interface{})
buildContext.Plan.Entries[0].Metadata["build"] = true
buildContext.Plan.Entries[0].Metadata["launch"] = false
})

it("skips the build process if the cached dependency sha matches the selected dependency sha", func() {
Expand Down
64 changes: 0 additions & 64 deletions fakes/entry_resolver.go

This file was deleted.

2 changes: 0 additions & 2 deletions run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/cargo"
"github.com/paketo-buildpacks/packit/v2/chronos"
"github.com/paketo-buildpacks/packit/v2/draft"
"github.com/paketo-buildpacks/packit/v2/pexec"
"github.com/paketo-buildpacks/packit/v2/postal"
"github.com/paketo-buildpacks/packit/v2/sbom"
Expand All @@ -26,7 +25,6 @@ func main() {
packit.Run(
pipenv.Detect(),
pipenv.Build(
draft.NewPlanner(),
postal.NewService(cargo.NewTransport()),
pipenv.NewPipenvInstallProcess(pexec.NewExecutable("pip")),
pipenv.NewSiteProcess(pexec.NewExecutable("python")),
Expand Down