optimizer

package
v0.0.0-...-60f03bf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnalyzeIssues

func AnalyzeIssues(df *ParsedDockerfile) []string

AnalyzeIssues returns a list of human-readable improvement suggestions.

func FormatBytes

func FormatBytes(b int64) string

FormatBytes is the exported variant of humanBytes for use in cmd packages.

Types

type ComparisonResult

type ComparisonResult struct {
	Before       *ImageStats
	After        *ImageStats
	SavedBytes   int64
	ReductionPct float64
}

CompareImages measures two images and returns the reduction statistics.

func CompareImages

func CompareImages(ctx context.Context, beforeRef, afterRef string) (*ComparisonResult, error)

CompareImages inspects both images and computes the size delta.

type ImageStats

type ImageStats struct {
	Ref          string
	ID           string
	SizeBytes    int64
	Layers       int
	Architecture string
	OS           string
}

ImageStats holds size information retrieved from the Docker daemon.

func InspectImage

func InspectImage(ctx context.Context, imageRef string) (*ImageStats, error)

InspectImage connects to the local Docker daemon and returns size metadata for the given image reference (e.g. "myapp:latest" or a digest).

func (*ImageStats) HumanSize

func (s *ImageStats) HumanSize() string

HumanSize returns a human-readable size string (KB / MB / GB).

type Instruction

type Instruction struct {
	Command string
	Args    string
}

Instruction represents a Dockerfile instruction

type Optimizer

type Optimizer struct {
	// contains filtered or unexported fields
}

Optimizer analyzes and optimizes Dockerfile instructions

func NewOptimizer

func NewOptimizer(baseImage string) *Optimizer

func (*Optimizer) CleanCommands

func (o *Optimizer) CleanCommands(pkgManager string) string

CleanCommands returns optimized shell commands (removing caches, temporary files)

func (*Optimizer) Optimize

func (o *Optimizer) Optimize(artifacts []string, envVars map[string]string) string

Optimize generates a multi-stage Dockerfile based on analyzed artifacts

type ParsedDockerfile

type ParsedDockerfile struct {
	BaseImage      string
	IsMultiStage   bool
	HasDistroless  bool
	HasNobodyUser  bool
	PackageManager string
	Stages         []Stage
}

ParsedDockerfile holds structured information extracted from an existing Dockerfile.

func ParseFile

func ParseFile(path string) (*ParsedDockerfile, error)

ParseFile reads a Dockerfile from disk and returns structured metadata.

func ParseString

func ParseString(content string) *ParsedDockerfile

ParseString parses Dockerfile content from a string (useful in tests).

type Stage

type Stage struct {
	Name  string
	Image string
	Lines []string
}

Stage represents one FROM block in a Dockerfile.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL