Skip to content

Commit

Permalink
show extensions when pack inspect
Browse files Browse the repository at this point in the history
Signed-off-by: Darshan Kumar <itsdarshankumar@gmail.com>
  • Loading branch information
itsdarshankumar committed Jan 28, 2023
1 parent 2e7e9b6 commit 7fd3894
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
14 changes: 14 additions & 0 deletions internal/inspectimage/info_display.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type InfoDisplay struct {
Base BaseDisplay `json:"base_image" yaml:"base_image" toml:"base_image"`
RunImageMirrors []RunImageMirrorDisplay `json:"run_images" yaml:"run_images" toml:"run_images"`
Buildpacks []dist.ModuleInfo `json:"buildpacks" yaml:"buildpacks" toml:"buildpacks"`
Extensions []dist.ModuleInfo `json:"extensions" yaml:"extensions" toml:"extensions"`
Processes []ProcessDisplay `json:"processes" yaml:"processes" toml:"processes"`
}

Expand All @@ -62,6 +63,7 @@ func NewInfoDisplay(info *client.ImageInfo, generalInfo GeneralInfo) *InfoDispla
Base: displayBase(info.Base),
RunImageMirrors: displayMirrors(info, generalInfo),
Buildpacks: displayBuildpacks(info.Buildpacks),
Extensions: displayExtensions(info.Extensions),
Processes: displayProcesses(info.Processes),
}
}
Expand Down Expand Up @@ -140,6 +142,18 @@ func displayBuildpacks(buildpacks []buildpack.GroupElement) []dist.ModuleInfo {
return result
}

func displayExtensions(extensions []buildpack.GroupElement) []dist.ModuleInfo {
var result []dist.ModuleInfo
for _, extension := range extensions {
result = append(result, dist.ModuleInfo{
ID: extension.ID,
Version: extension.Version,
Homepage: extension.Homepage,
})
}
return result
}

func displayProcesses(details client.ProcessDetails) []ProcessDisplay {
var result []ProcessDisplay
detailsArray := details.OtherProcesses
Expand Down
16 changes: 15 additions & 1 deletion internal/inspectimage/writer/human_readable.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func writeImageInfo(
Parse(runImagesTemplate))
imgTpl = template.Must(imgTpl.New("buildpacks").
Parse(buildpacksTemplate))
imgTpl = template.Must(imgTpl.New("extensions").Parse(extensionsTemplate))
imgTpl = template.Must(imgTpl.New("processes").
Parse(processesTemplate))
imgTpl = template.Must(imgTpl.New("image").
Expand Down Expand Up @@ -127,6 +128,17 @@ Buildpacks:
(buildpack metadata not present)
{{- end }}`

var extensionsTemplate = `
Extensions:
{{- if .Info.Extensions }}
ID VERSION HOMEPAGE
{{- range $_, $b := .Info.Extensions }}
{{ $b.ID }} {{ $b.Version }} {{ StringsValueOrDefault $b.Homepage "-" }}
{{- end }}
{{- else }}
(extension metadata not present)
{{- end }}`

var processesTemplate = `
{{- if .Info.Processes }}
Expand All @@ -150,4 +162,6 @@ Base Image:
{{- end}}
Top Layer: {{ .Info.Base.TopLayer }}
{{ template "runImages" . }}
{{ template "buildpacks" . }}{{ template "processes" . }}`
{{ template "buildpacks" . }}
{{ template "extensions" . }}
{{ template "processes" . }}`
5 changes: 5 additions & 0 deletions pkg/client/inspect_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ type ImageInfo struct {
// phases and made a contribution to this image.
Buildpacks []buildpack.GroupElement

// List of extensions that passed detection, ran their generate
// phases and made a contribution to this image.
Extensions []buildpack.GroupElement

// Base includes two references to the run image,
// - the Run Image ID,
// - the hash of the last layer in the app image that belongs to the run image.
Expand Down Expand Up @@ -178,6 +182,7 @@ func (c *Client) InspectImage(name string, daemon bool) (*ImageInfo, error) {
Base: layersMd.RunImage,
BOM: buildMD.BOM,
Buildpacks: buildMD.Buildpacks,
Extensions: buildMD.Extensions,
Processes: processDetails,
}, nil
}

0 comments on commit 7fd3894

Please sign in to comment.