Documentation
¶
Overview ¶
Package models provides data structures for Docker image analysis.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnalysisResult ¶
type AnalysisResult struct {
// Image contains the analyzed image data.
Image Image `json:"image"`
// Suggestions contains all optimization recommendations.
Suggestions []Suggestion `json:"suggestions,omitempty"`
// WastedSpace is the estimated bytes that could be saved.
WastedSpace int64 `json:"wasted_space"`
// Score is an overall optimization score (0-100).
Score int `json:"score"`
// Version is the version of the analysis format.
Version string `json:"version"`
}
AnalysisResult contains the complete analysis of an image.
func (*AnalysisResult) GetSuggestionsByPriority ¶
func (ar *AnalysisResult) GetSuggestionsByPriority(priority Priority) []Suggestion
GetSuggestionsByPriority returns suggestions filtered by priority.
func (*AnalysisResult) GetTotalEstimatedSavings ¶
func (ar *AnalysisResult) GetTotalEstimatedSavings() int64
GetTotalEstimatedSavings returns the total estimated savings across all suggestions.
type Image ¶
type Image struct {
// ID is the image ID (digest).
ID string `json:"id"`
// Tags are the repository tags associated with the image.
Tags []string `json:"tags"`
// TotalSize is the total size of the image in bytes.
TotalSize int64 `json:"total_size"`
// Layers contains all layers in the image (base to top).
Layers []Layer `json:"layers"`
// BaseImage is the name of the base image (detected).
BaseImage string `json:"base_image,omitempty"`
// Efficiency is a score from 0-100 indicating layer efficiency.
Efficiency float64 `json:"efficiency"`
// CreatedAt is when the image was created.
CreatedAt time.Time `json:"created_at"`
// Author is the image author.
Author string `json:"author,omitempty"`
// Architecture is the CPU architecture (amd64, arm64, etc.).
Architecture string `json:"architecture"`
// OS is the operating system.
OS string `json:"os"`
// Config contains image configuration.
Config ImageConfig `json:"config,omitempty"`
}
Image represents a Docker image with its metadata and layers.
func (*Image) GetLayerByIndex ¶
GetLayerByIndex returns the layer at the given index.
func (*Image) GetLayerCount ¶
GetLayerCount returns the total number of layers.
func (*Image) GetSizeByLayerType ¶
GetSizeByLayerType calculates total size for each layer type.
func (*Image) GetTopNLayers ¶
GetTopNLayers returns the top N largest layers by size.
type ImageConfig ¶
type ImageConfig struct {
// ExposedPorts lists the ports exposed by the image.
ExposedPorts []string `json:"exposed_ports,omitempty"`
// Env contains environment variables.
Env []string `json:"env,omitempty"`
// Entrypoint is the default entrypoint.
Entrypoint []string `json:"entrypoint,omitempty"`
// Cmd is the default command.
Cmd []string `json:"cmd,omitempty"`
// WorkingDir is the working directory.
WorkingDir string `json:"working_dir,omitempty"`
// User is the default user.
User string `json:"user,omitempty"`
}
ImageConfig contains configuration details for the image.
type Layer ¶
type Layer struct {
// ID is the layer ID (empty for some layer types).
ID string `json:"id"`
// Command is the Dockerfile command that created this layer.
Command string `json:"command"`
// Size is the size of this layer in bytes.
Size int64 `json:"size"`
// CumulativeSize is the total size from this layer to the base.
CumulativeSize int64 `json:"cumulative_size"`
// CreatedAt is when the layer was created.
CreatedAt time.Time `json:"created_at"`
// Author is the author of the layer.
Author string `json:"author,omitempty"`
// Comment provides additional context about the layer.
Comment string `json:"comment,omitempty"`
// Empty indicates if this is an empty/meta layer.
Empty bool `json:"empty"`
}
Layer represents a single layer in a Docker image.
func (*Layer) GetLayerType ¶
GetLayerType determines the type of layer from its command.
type LayerType ¶
type LayerType string
LayerType categorizes the type of layer based on its command.
const ( // LayerTypeRUN represents a RUN command layer. LayerTypeRUN LayerType = "RUN" // LayerTypeCOPY represents a COPY command layer. LayerTypeCOPY LayerType = "COPY" // LayerTypeADD represents an ADD command layer. LayerTypeADD LayerType = "ADD" // LayerTypeFROM represents the base image layer. LayerTypeFROM LayerType = "FROM" // LayerTypeWORKDIR represents a WORKDIR command. LayerTypeWORKDIR LayerType = "WORKDIR" // LayerTypeENV represents an ENV command. LayerTypeENV LayerType = "ENV" // LayerTypeLABEL represents a LABEL command. LayerTypeLABEL LayerType = "LABEL" // LayerTypeEXPOSE represents an EXPOSE command. LayerTypeEXPOSE LayerType = "EXPOSE" // LayerTypeVOLUME represents a VOLUME command. LayerTypeVOLUME LayerType = "VOLUME" // LayerTypeUSER represents a USER command. LayerTypeUSER LayerType = "USER" // LayerTypeENTRYPOINT represents an ENTRYPOINT command. LayerTypeENTRYPOINT LayerType = "ENTRYPOINT" // LayerTypeCMD represents a CMD command. LayerTypeCMD LayerType = "CMD" // LayerTypeOther represents any other command type. LayerTypeOther LayerType = "OTHER" // LayerTypeEmpty represents an empty/meta layer. LayerTypeEmpty LayerType = "EMPTY" )
type Suggestion ¶
type Suggestion struct {
// RuleID is the unique identifier for this rule.
RuleID string `json:"rule_id"`
// Title is a short summary of the suggestion.
Title string `json:"title"`
// Description provides detailed explanation.
Description string `json:"description"`
// Priority indicates the importance of this suggestion.
Priority Priority `json:"priority"`
// EstimatedSavings is the estimated size reduction in bytes.
EstimatedSavings int64 `json:"estimated_savings"`
// CurrentValue shows the current problematic value.
CurrentValue string `json:"current_value,omitempty"`
// RecommendedValue shows the suggested fix.
RecommendedValue string `json:"recommended_value,omitempty"`
// Example provides a code example of the fix.
Example string `json:"example,omitempty"`
// References contains links to documentation.
References []string `json:"references,omitempty"`
// AffectedLayers contains indices of layers related to this suggestion.
AffectedLayers []int `json:"affected_layers,omitempty"`
}
Suggestion represents an optimization recommendation.