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

add Extensions (no DetectionOrder yet) #1580

Closed
Closed
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
2 changes: 2 additions & 0 deletions internal/builder/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Info struct {
BuildpackLayers dist.ModuleLayers
Lifecycle LifecycleDescriptor
CreatedBy CreatorMetadata
Extensions []dist.ModuleInfo
}

type Inspectable interface {
Expand Down Expand Up @@ -127,6 +128,7 @@ func (i *Inspector) Inspect(name string, daemon bool, orderDetectionDepth int) (
BuildpackLayers: layers,
Lifecycle: lifecycle,
CreatedBy: metadata.CreatedBy,
Extensions: metadata.Extensions,
}, nil
}

Expand Down
53 changes: 52 additions & 1 deletion internal/builder/writer/human_readable.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
writerMinWidth = 0
writerTabWidth = 0
buildpacksTabWidth = 8
extensionsTabWidth = 8
defaultTabWidth = 4
writerPadChar = ' '
writerFlags = 0
Expand Down Expand Up @@ -59,7 +60,8 @@ Stack:
{{ .Lifecycle }}
{{ .RunImages }}
{{ .Buildpacks }}
{{ .Order }}`
{{ .Order }}
{{ .Extensions }}`
)

type HumanReadable struct{}
Expand Down Expand Up @@ -132,10 +134,16 @@ func writeBuilderInfo(
}
lifecycleString, lifecycleWarnings := lifecycleOutput(info.Lifecycle, sharedInfo.Name)

extensionsString, extensionsWarnings, err := extensionsOutput(info.Extensions, sharedInfo.Name)
if err != nil {
return fmt.Errorf("compiling extensions output: %w", err)
}

warnings = append(warnings, runImagesWarnings...)
warnings = append(warnings, orderWarnings...)
warnings = append(warnings, buildpacksWarnings...)
warnings = append(warnings, lifecycleWarnings...)
warnings = append(warnings, extensionsWarnings...)

outputTemplate, _ := template.New("").Parse(outputTemplate)
err = outputTemplate.Execute(
Expand All @@ -148,6 +156,7 @@ func writeBuilderInfo(
Order string
Trusted string
Lifecycle string
Extensions string
}{
*info,
logger.IsVerbose(),
Expand All @@ -156,6 +165,7 @@ func writeBuilderInfo(
orderString,
stringFromBool(sharedInfo.Trusted),
lifecycleString,
extensionsString,
},
)

Expand Down Expand Up @@ -273,6 +283,47 @@ func writeLocalMirrors(logWriter io.Writer, runImage string, localRunImages []co
return nil
}

func extensionsOutput(extensions []dist.ModuleInfo, builderName string) (string, []string, error) {
output := "Extensions:\n"

if len(extensions) == 0 {
warnings := []string{
fmt.Sprintf("%s has no buildpacks", builderName),
"",
}

return fmt.Sprintf("%s %s\n", output, none), warnings, nil
}

var (
tabWriterBuf = bytes.Buffer{}
spaceStrippingWriter = &trailingSpaceStrippingWriter{
output: &tabWriterBuf,
}
extensionsTabWriter = tabwriter.NewWriter(spaceStrippingWriter, writerMinWidth, writerPadChar, buildpacksTabWidth, writerPadChar, writerFlags)
)

_, err := fmt.Fprint(extensionsTabWriter, " ID\tNAME\tVERSION\tHOMEPAGE\n")
if err != nil {
return "", []string{}, fmt.Errorf("writing to tab writer: %w", err)
}

for _, b := range extensions {
_, err = fmt.Fprintf(extensionsTabWriter, " %s\t%s\t%s\t%s\n", b.ID, strs.ValueOrDefault(b.Name, "-"), b.Version, strs.ValueOrDefault(b.Homepage, "-"))
if err != nil {
return "", []string{}, fmt.Errorf("writing to tab writer: %w", err)
}
}

err = extensionsTabWriter.Flush()
if err != nil {
return "", []string{}, fmt.Errorf("flushing tab writer: %w", err)
}

output += tabWriterBuf.String()
return output, []string{}, nil
}

func buildpacksOutput(buildpacks []dist.ModuleInfo, builderName string) (string, []string, error) {
output := "Buildpacks:\n"

Expand Down
18 changes: 18 additions & 0 deletions internal/builder/writer/human_readable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ Detection Order:
│ │ └ test.bp.one@test.bp.one.version (optional)[cyclic]
│ └ test.bp.two@test.bp.two.version (optional)
└ test.bp.three@test.bp.three.version

Extensions:
ID NAME VERSION HOMEPAGE
test.top.nested - test.top.nested.version -
test.nested - http://geocities.com/top-bp
test.bp.one - test.bp.one.version http://geocities.com/cool-bp
test.bp.two - test.bp.two.version -
test.bp.three - test.bp.three.version -
`

expectedLocalOutput = `
Expand Down Expand Up @@ -139,6 +147,14 @@ Detection Order:
│ │ └ test.bp.one@test.bp.one.version (optional)[cyclic]
│ └ test.bp.two@test.bp.two.version (optional)
└ test.bp.three@test.bp.three.version

Extensions:
ID NAME VERSION HOMEPAGE
test.top.nested - test.top.nested.version -
test.nested - http://geocities.com/top-bp
test.bp.one - test.bp.one.version http://geocities.com/cool-bp
test.bp.two - test.bp.two.version -
test.bp.three - test.bp.three.version -
`
expectedVerboseStack = `
Stack:
Expand Down Expand Up @@ -185,6 +201,7 @@ REMOTE:
RunImageMirrors: []string{"first/default", "second/default"},
Buildpacks: buildpacks,
Order: order,
Extensions: buildpacks,
BuildpackLayers: dist.ModuleLayers{},
Lifecycle: builder.LifecycleDescriptor{
Info: builder.LifecycleInfo{
Expand Down Expand Up @@ -217,6 +234,7 @@ REMOTE:
RunImageMirrors: []string{"first/local-default", "second/local-default"},
Buildpacks: buildpacks,
Order: order,
Extensions: buildpacks,
BuildpackLayers: dist.ModuleLayers{},
Lifecycle: builder.LifecycleDescriptor{
Info: builder.LifecycleInfo{
Expand Down
5 changes: 5 additions & 0 deletions pkg/client/inspect_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ type BuilderInfo struct {
// Name and Version information from tooling used
// to produce this builder.
CreatedBy builder.CreatorMetadata

// Extension (metadata?) included with builder image
// to be displayed in cmd line
Extensions []dist.ModuleInfo
}

// BuildpackInfoKey contains all information needed to determine buildpack equivalence.
Expand Down Expand Up @@ -102,5 +106,6 @@ func (c *Client) InspectBuilder(name string, daemon bool, modifiers ...BuilderIn
BuildpackLayers: info.BuildpackLayers,
Lifecycle: info.Lifecycle,
CreatedBy: info.CreatedBy,
Extensions: info.Extensions,
}, nil
}