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

Separate suggested builders from default trusted builders #2043

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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: true,
colincasey marked this conversation as resolved.
Show resolved Hide resolved
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,
},
}
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
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
Loading