image

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package image provides auto-detection of Docker base images based on workspace language/framework signals.

Package image provides version parsing and normalization for language version detection.

Index

Constants

View Source
const DefaultImage = "golang:1.22"

DefaultImage is the fallback Docker image used when no language signal is detected.

Variables

This section is empty.

Functions

func FormatResult

func FormatResult(result *DetectResult) string

FormatResult formats a DetectResult as a human-readable string.

func NormalizeVersionRange

func NormalizeVersionRange(versionRange string, ltsVersion string) string

NormalizeVersionRange attempts to normalize a version range to a specific version. For broad ranges (e.g., "^1.0.0", ">=2"), it returns a suggested LTS version. Returns empty string if the range is too broad and a default should be used.

Types

type DebugDetectResult added in v0.6.0

type DebugDetectResult struct {
	*DetectResult

	// ScannedSignals lists all signals found during scanning
	ScannedSignals []SignalMatch `json:"scanned_signals"`

	// VersionInfo contains version detection details
	VersionInfo *VersionDebugInfo `json:"version_info,omitempty"`

	// FileCount is the total number of files scanned
	FileCount int `json:"file_count"`

	// DurationMs is how long the detection took
	DurationMs int64 `json:"duration_ms"`

	// ScanMode indicates which scanning strategy was used (root-only or full-recursive)
	ScanMode string `json:"scan_mode"`
}

DebugDetectResult contains detailed detection information for debugging.

type DetectResult

type DetectResult struct {
	Image     string   // Detected Docker image (e.g., image.DefaultImage)
	Signals   []string // List of signals that contributed to this detection
	Rationale string   // Human-readable explanation of the detection
	Disabled  bool     // True if auto-detection is disabled
}

DetectResult contains the detected image and detection rationale.

func Detect

func Detect(workspace string) *DetectResult

Detect is a convenience function that detects the image for a workspace.

type Detector

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

Detector detects the appropriate Docker base image for a workspace.

func NewDetector

func NewDetector(workspace string) *Detector

NewDetector creates a new Detector for the given workspace path.

func (*Detector) Detect

func (d *Detector) Detect() *DetectResult

Detect analyzes the workspace to determine an appropriate base image. If no strong signal is detected, returns a safe default. Attempts to detect language versions from project files.

func (*Detector) DetectDebug added in v0.6.0

func (d *Detector) DetectDebug() *DebugDetectResult

DetectDebug performs detection with detailed debug information.

type SignalMatch added in v0.6.0

type SignalMatch struct {
	Name     string `json:"name"`
	Priority int    `json:"priority"`
	Path     string `json:"path"`
	Found    bool   `json:"found"`
}

SignalMatch represents a found signal with location info.

type Version

type Version struct {
	Major    int
	Minor    int
	Patch    int
	Original string
}

Version represents a parsed language version with major, minor, and patch components.

func ParseVersion

func ParseVersion(version string) (*Version, error)

ParseVersion parses a version string and returns a Version struct. Supports various version formats: - "1.22" -> {Major: 1, Minor: 22, Patch: 0} - "1.22.0" -> {Major: 1, Minor: 22, Patch: 0} - "22" -> {Major: 22, Minor: 0, Patch: 0}

func (*Version) Compare

func (v *Version) Compare(other *Version) int

Compare compares two versions. Returns: -1 if v < other, 0 if v == other, 1 if v > other

func (*Version) ImageString

func (v *Version) ImageString(useMajorOnly bool) string

ImageString returns the version formatted for Docker image tags. For most languages, this is "major.minor", but some languages use just major (Node.js).

func (*Version) IsZero

func (v *Version) IsZero() bool

IsZero returns true if the version is all zeros.

func (*Version) String

func (v *Version) String() string

String returns the version in "major.minor" format (patch is omitted for Docker images).

type VersionDebugInfo added in v0.6.0

type VersionDebugInfo struct {
	Language    string `json:"language"`
	Version     string `json:"version"`
	SourceFile  string `json:"source_file"`
	SourceField string `json:"source_field"`
	LineNumber  int    `json:"line_number"`
	RawValue    string `json:"raw_value"`
}

VersionDebugInfo contains version detection details for debugging.

Jump to

Keyboard shortcuts

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