Documentation
¶
Index ¶
- type BinaryInfo
- type BuildInfo
- type Detector
- func (d *Detector) ConvertBinaryInfoToBuildInfo(bi *BinaryInfo) *BuildInfo
- func (d *Detector) ConvertBinaryInfoToBuildInfoWithLabels(bi *BinaryInfo, imageLabels map[string]string) *BuildInfo
- func (d *Detector) DetectGoBinaries(ctx context.Context, gwClient client.Client, targetState *llb.State, ...) ([]*BinaryInfo, error)
- type RebuildContext
- type RebuildResult
- type RebuildStrategy
- type Rebuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BinaryInfo ¶
type BinaryInfo struct {
// Path is the filesystem path to the binary in the target image.
Path string
// GoVersion is the Go version used to build the binary (e.g., "go1.21.5").
GoVersion string
// ModulePath is the main module path (e.g., "github.com/example/app").
ModulePath string
// Main is the main module info (path and version).
Main string
// Dependencies maps module names to versions.
Dependencies map[string]string
// BuildSettings contains build settings (CGO_ENABLED, GOOS, GOARCH, ldflags, etc.).
BuildSettings map[string]string
// VCS contains version control info (vcs, vcs.revision, vcs.time, vcs.modified).
VCS map[string]string
// FileMode is the octal file permission mode of the original binary (e.g., "0755").
FileMode string
// FileOwner is the uid:gid of the original binary (e.g., "0:0").
FileOwner string
}
BinaryInfo contains information extracted from a Go binary using `go version -m`.
type BuildInfo ¶
type BuildInfo struct {
// BuildArgs contains the build arguments used.
BuildArgs map[string]string
// GoVersion is the Go version used for building.
GoVersion string
// BaseImage is the base image reference used.
BaseImage string
// CGOEnabled indicates if CGO was enabled during the build.
CGOEnabled bool
// BuildFlags are additional flags passed to go build.
BuildFlags []string
// Workdir is the working directory used during build.
Workdir string
// MainPackage is the main package path (e.g., "cmd/app").
MainPackage string
// ModulePath is the Go module path (e.g., "github.com/org/repo").
ModulePath string
// Dependencies maps module names to versions (from binary detection).
Dependencies map[string]string
}
BuildInfo contains information extracted about how a Go binary was built.
type Detector ¶
type Detector struct{}
Detector detects Go binaries in container images using `go version -m`.
func (*Detector) ConvertBinaryInfoToBuildInfo ¶
func (d *Detector) ConvertBinaryInfoToBuildInfo(bi *BinaryInfo) *BuildInfo
ConvertBinaryInfoToBuildInfo converts detected binary info to BuildInfo for rebuilding.
func (*Detector) ConvertBinaryInfoToBuildInfoWithLabels ¶
func (d *Detector) ConvertBinaryInfoToBuildInfoWithLabels(bi *BinaryInfo, imageLabels map[string]string) *BuildInfo
ConvertBinaryInfoToBuildInfoWithLabels converts detected binary info to BuildInfo, using OCI image labels as fallback when VCS info is missing (e.g. binaries built with -trimpath).
func (*Detector) DetectGoBinaries ¶
func (d *Detector) DetectGoBinaries( ctx context.Context, gwClient client.Client, targetState *llb.State, platform *specs.Platform, ) ([]*BinaryInfo, error)
DetectGoBinaries detects all Go binaries in an image using a single BuildKit operation. It mounts the target image and runs `go version -m` on all executable files.
type RebuildContext ¶
type RebuildContext struct {
// Strategy is the rebuild strategy to use.
Strategy RebuildStrategy
// BuildInfo is information extracted from binary detection.
BuildInfo *BuildInfo
// BinaryInfo contains information from detected Go binaries.
BinaryInfo []*BinaryInfo
// ImageLabels contains OCI image labels for version metadata fallback.
ImageLabels map[string]string
ImageRef string
GoVCSURL string
ImageSourceLabel string // org.opencontainers.image.source OCI label
}
RebuildContext contains all information needed for a binary rebuild attempt.
type RebuildResult ¶
type RebuildResult struct {
// Success indicates if the rebuild LLB graph was constructed successfully.
// The actual build is executed later during BuildKit Solve.
Success bool
// Strategy is the strategy that was used.
Strategy string
// Error is the error if rebuild failed.
Error error
// Warnings are non-fatal issues encountered.
Warnings []string
// BinariesRebuilt is the number of binaries successfully rebuilt.
BinariesRebuilt int
// RebuiltBinaries maps original binary paths to their rebuild status.
RebuiltBinaries map[string]bool
}
RebuildResult contains the outcome of a rebuild attempt.
type RebuildStrategy ¶
type RebuildStrategy int
RebuildStrategy defines how Copa should attempt to rebuild Go binaries.
const ( // RebuildStrategyAuto automatically chooses the best strategy based on available information. RebuildStrategyAuto RebuildStrategy = iota // RebuildStrategyHeuristic uses detected binary information for rebuild. RebuildStrategyHeuristic // RebuildStrategyNone indicates no rebuild is possible. RebuildStrategyNone )
func (RebuildStrategy) String ¶
func (s RebuildStrategy) String() string
String returns string representation of RebuildStrategy.
type Rebuilder ¶
type Rebuilder struct{}
Rebuilder orchestrates the Go binary rebuild process using heuristic detection.
func (*Rebuilder) RebuildBinary ¶
func (r *Rebuilder) RebuildBinary( rebuildCtx *RebuildContext, updates map[string]string, platform *specs.Platform, targetState *llb.State, binaryPath string, ) (llb.State, *RebuildResult, error)
RebuildBinary rebuilds a Go binary with updated dependencies and merges it back into the target image.