Skip to content

Commit

Permalink
Merge pull request #2043 from colincasey/1500_separate_suggested_and_…
Browse files Browse the repository at this point in the history
…trusted_builders

Separate suggested builders from default trusted builders
  • Loading branch information
jjbustamante authored Feb 7, 2024
2 parents c45c3cf + bdaaead commit cc4647d
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 23 deletions.
1 change: 0 additions & 1 deletion acceptance/assertions/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ func (o OutputAssertionManager) IncludesPrefixedGoogleBuilder() {
}

var herokuBuilders = []string{
"heroku/builder:20",
"heroku/builder:22",
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,61 @@
package builder

type SuggestedBuilder struct {
type KnownBuilder struct {
Vendor string
Image string
DefaultDescription string
Suggested bool
Trusted bool
}

var SuggestedBuilders = []SuggestedBuilder{
var KnownBuilders = []KnownBuilder{
{
Vendor: "Google",
Image: "gcr.io/buildpacks/builder:v1",
DefaultDescription: "GCP Builder for all runtimes",
Suggested: true,
Trusted: true,
},
{
Vendor: "Heroku",
Image: "heroku/builder:22",
DefaultDescription: "Heroku-22 (Ubuntu 22.04) base image with buildpacks for Go, Java, Node.js, PHP, Python, Ruby & Scala",
Suggested: true,
Trusted: true,
},
{
Vendor: "Heroku",
Image: "heroku/builder:20",
DefaultDescription: "Heroku-20 (Ubuntu 20.04) base image with buildpacks for Go, Java, Node.js, PHP, Python, Ruby & Scala",
Suggested: false,
Trusted: true,
},
{
Vendor: "Paketo Buildpacks",
Image: "paketobuildpacks/builder-jammy-base",
DefaultDescription: "Small base image with buildpacks for Java, Node.js, Golang, .NET Core, Python & Ruby",
Suggested: true,
Trusted: true,
},
{
Vendor: "Paketo Buildpacks",
Image: "paketobuildpacks/builder-jammy-full",
DefaultDescription: "Larger base image with buildpacks for Java, Node.js, Golang, .NET Core, Python, Ruby, & PHP",
Suggested: true,
Trusted: true,
},
{
Vendor: "Paketo Buildpacks",
Image: "paketobuildpacks/builder-jammy-tiny",
DefaultDescription: "Tiny base image (jammy build image, distroless run image) with buildpacks for Golang & Java",
Suggested: true,
Trusted: true,
},
{
Vendor: "Paketo Buildpacks",
Image: "paketobuildpacks/builder-jammy-buildpackless-static",
DefaultDescription: "Static base image (jammy build image, distroless run image) suitable for static binaries like Go or Rust",
Suggested: true,
Trusted: true,
},
}
1 change: 0 additions & 1 deletion internal/commands/builder_inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ func testBuilderInspectCommand(t *testing.T, when spec.G, it spec.S) {

assert.Matches(outBuf.String(), regexp.MustCompile(`Paketo Buildpacks:\s+'paketobuildpacks/builder-jammy-base'`))
assert.Matches(outBuf.String(), regexp.MustCompile(`Paketo Buildpacks:\s+'paketobuildpacks/builder-jammy-full'`))
assert.Matches(outBuf.String(), regexp.MustCompile(`Heroku:\s+'heroku/builder:20'`))
assert.Matches(outBuf.String(), regexp.MustCompile(`Heroku:\s+'heroku/builder:22'`))
})
})
Expand Down
6 changes: 3 additions & 3 deletions internal/commands/builder_suggest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func testSuggestCommand(t *testing.T, when spec.G, it spec.S) {
})

it("displays descriptions from metadata", func() {
commands.WriteSuggestedBuilder(logger, mockClient, []bldr.SuggestedBuilder{{
commands.WriteSuggestedBuilder(logger, mockClient, []bldr.KnownBuilder{{
Vendor: "Builder",
Image: "gcr.io/some/builder:latest",
DefaultDescription: "Default description",
Expand All @@ -65,7 +65,7 @@ func testSuggestCommand(t *testing.T, when spec.G, it spec.S) {
})

it("displays default descriptions", func() {
commands.WriteSuggestedBuilder(logger, mockClient, []bldr.SuggestedBuilder{{
commands.WriteSuggestedBuilder(logger, mockClient, []bldr.KnownBuilder{{
Vendor: "Builder",
Image: "gcr.io/some/builder:latest",
DefaultDescription: "Default description",
Expand All @@ -81,7 +81,7 @@ func testSuggestCommand(t *testing.T, when spec.G, it spec.S) {
})

it("displays default descriptions", func() {
commands.WriteSuggestedBuilder(logger, mockClient, []bldr.SuggestedBuilder{{
commands.WriteSuggestedBuilder(logger, mockClient, []bldr.KnownBuilder{{
Vendor: "Builder",
Image: "gcr.io/some/builder:latest",
DefaultDescription: "Default description",
Expand Down
6 changes: 4 additions & 2 deletions internal/commands/config_trusted_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ func listTrustedBuilders(args []string, logger logging.Logger, cfg config.Config
logger.Info("Trusted Builders:")

var trustedBuilders []string
for _, builder := range bldr.SuggestedBuilders {
trustedBuilders = append(trustedBuilders, builder.Image)
for _, knownBuilder := range bldr.KnownBuilders {
if knownBuilder.Trusted {
trustedBuilders = append(trustedBuilders, knownBuilder.Image)
}
}

for _, builder := range cfg.TrustedBuilders {
Expand Down
1 change: 0 additions & 1 deletion internal/commands/inspect_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ func testInspectBuilderCommand(t *testing.T, when spec.G, it spec.S) {

assert.Matches(outBuf.String(), regexp.MustCompile(`Paketo Buildpacks:\s+'paketobuildpacks/builder-jammy-base'`))
assert.Matches(outBuf.String(), regexp.MustCompile(`Paketo Buildpacks:\s+'paketobuildpacks/builder-jammy-full'`))
assert.Matches(outBuf.String(), regexp.MustCompile(`Heroku:\s+'heroku/builder:20'`))
assert.Matches(outBuf.String(), regexp.MustCompile(`Heroku:\s+'heroku/builder:22'`))
})
})
Expand Down
18 changes: 12 additions & 6 deletions internal/commands/suggest_builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ func suggestSettingBuilder(logger logging.Logger, inspector BuilderInspector) {
}

func suggestBuilders(logger logging.Logger, client BuilderInspector) {
WriteSuggestedBuilder(logger, client, bldr.SuggestedBuilders)
suggestedBuilders := []bldr.KnownBuilder{}
for _, knownBuilder := range bldr.KnownBuilders {
if knownBuilder.Suggested {
suggestedBuilders = append(suggestedBuilders, knownBuilder)
}
}
WriteSuggestedBuilder(logger, client, suggestedBuilders)
}

func WriteSuggestedBuilder(logger logging.Logger, inspector BuilderInspector, builders []bldr.SuggestedBuilder) {
func WriteSuggestedBuilder(logger logging.Logger, inspector BuilderInspector, builders []bldr.KnownBuilder) {
sort.Slice(builders, func(i, j int) bool {
if builders[i].Vendor == builders[j].Vendor {
return builders[i].Image < builders[j].Image
Expand All @@ -60,7 +66,7 @@ func WriteSuggestedBuilder(logger logging.Logger, inspector BuilderInspector, bu
wg.Add(len(builders))

for i, builder := range builders {
go func(w *sync.WaitGroup, i int, builder bldr.SuggestedBuilder) {
go func(w *sync.WaitGroup, i int, builder bldr.KnownBuilder) {
descriptions[i] = getBuilderDescription(builder, inspector)
w.Done()
}(&wg, i, builder)
Expand All @@ -78,7 +84,7 @@ func WriteSuggestedBuilder(logger logging.Logger, inspector BuilderInspector, bu
logger.Info("\tpack builder inspect <builder-image>")
}

func getBuilderDescription(builder bldr.SuggestedBuilder, inspector BuilderInspector) string {
func getBuilderDescription(builder bldr.KnownBuilder, inspector BuilderInspector) string {
info, err := inspector.InspectBuilder(builder.Image, false)
if err == nil && info != nil && info.Description != "" {
return info.Description
Expand All @@ -88,8 +94,8 @@ func getBuilderDescription(builder bldr.SuggestedBuilder, inspector BuilderInspe
}

func isSuggestedBuilder(builder string) bool {
for _, sugBuilder := range bldr.SuggestedBuilders {
if builder == sugBuilder.Image {
for _, knownBuilder := range bldr.KnownBuilders {
if builder == knownBuilder.Image && knownBuilder.Suggested {
return true
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/commands/suggest_builders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func testSuggestBuildersCommand(t *testing.T, when spec.G, it spec.S) {
})

it("displays descriptions from metadata", func() {
commands.WriteSuggestedBuilder(logger, mockClient, []bldr.SuggestedBuilder{{
commands.WriteSuggestedBuilder(logger, mockClient, []bldr.KnownBuilder{{
Vendor: "Builder",
Image: "gcr.io/some/builder:latest",
DefaultDescription: "Default description",
Expand All @@ -65,7 +65,7 @@ func testSuggestBuildersCommand(t *testing.T, when spec.G, it spec.S) {
})

it("displays default descriptions", func() {
commands.WriteSuggestedBuilder(logger, mockClient, []bldr.SuggestedBuilder{{
commands.WriteSuggestedBuilder(logger, mockClient, []bldr.KnownBuilder{{
Vendor: "Builder",
Image: "gcr.io/some/builder:latest",
DefaultDescription: "Default description",
Expand All @@ -81,7 +81,7 @@ func testSuggestBuildersCommand(t *testing.T, when spec.G, it spec.S) {
})

it("displays default descriptions", func() {
commands.WriteSuggestedBuilder(logger, mockClient, []bldr.SuggestedBuilder{{
commands.WriteSuggestedBuilder(logger, mockClient, []bldr.KnownBuilder{{
Vendor: "Builder",
Image: "gcr.io/some/builder:latest",
DefaultDescription: "Default description",
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ type layoutPathConfig struct {
targetRunImagePath string
}

var IsSuggestedBuilderFunc = func(b string) bool {
for _, suggestedBuilder := range builder.SuggestedBuilders {
if b == suggestedBuilder.Image {
var IsTrustedBuilderFunc = func(b string) bool {
for _, knownBuilder := range builder.KnownBuilders {
if b == knownBuilder.Image && knownBuilder.Trusted {
return true
}
}
Expand Down Expand Up @@ -384,7 +384,7 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {

// Default mode: if the TrustBuilder option is not set, trust the suggested builders.
if opts.TrustBuilder == nil {
opts.TrustBuilder = IsSuggestedBuilderFunc
opts.TrustBuilder = IsTrustedBuilderFunc
}

// Ensure the builder's platform APIs are supported
Expand Down

0 comments on commit cc4647d

Please sign in to comment.