states

package
v0.8.17-test2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheImports

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

CacheImports is a synchronized set of cache imports.

func NewCacheImports

func NewCacheImports(imports []string) *CacheImports

NewCacheImports creates a new cache imports structure.

func (*CacheImports) Add

func (ci *CacheImports) Add(tag string)

Add adds import to the set.

func (*CacheImports) AsSlice

func (ci *CacheImports) AsSlice() []string

AsSlice returns the cache imports contents as a slice.

func (*CacheImports) Has

func (ci *CacheImports) Has(tag string) bool

Has checks if a passed tag is added.

type CacheMount

type CacheMount struct {
	// Persisted should the cache be persisted to image.
	Persisted bool
	// RunOption Run options
	RunOption llb.RunOption
}

CacheMount holds run options needed to cache mounts, and some extra options.

type DockerTarImageSolver

type DockerTarImageSolver interface {
	SolveImage(ctx context.Context, mts *MultiTarget, dockerTag string, outFile string, printOutput bool) error
}

DockerTarImageSolver can create a Docker image and make it available as a tar file.

type ImageDef

type ImageDef struct {
	MTS       *MultiTarget
	ImageName string
	Platform  platutil.Platform
}

ImageDef includes the information required to build an image in BuildKit.

type ImageResult

type ImageResult struct {
	IntermediateImageName    string
	FinalImageName           string
	FinalImageNameWithDigest string
	ImageDigest              string
	ConfigDigest             string
	ImageDescriptor          *ocispecs.Descriptor
	Annotations              map[string]string
	NewInterImgFormat        bool
}

ImageResult contains data about an image that was built.

type ImageSolverResults

type ImageSolverResults struct {
	ResultChan  chan *ImageResult
	ErrChan     chan error
	ReleaseFunc func()
}

ImageSolverResults contains data and channels that allow one to act on images during and after they are built.

type InteractiveSession

type InteractiveSession struct {
	CommandStr  string
	State       pllb.State
	Initialized bool
	Kind        InteractiveSessionKind
}

InteractiveSession holds the relevant data for running an interactive session when it is not desired to save the resulting changes into an image.

type InteractiveSessionKind

type InteractiveSessionKind string

InteractiveSessionKind represents what kind of interactive session has been encountered.

const (
	// SessionKeep is a session where the data *persists* in the image when it exits.
	SessionKeep InteractiveSessionKind = "keep"
	// SessionEphemeral is a session where the data *does not persist* in the image when it exits.
	SessionEphemeral InteractiveSessionKind = "ephemeral"
)

type MultiImageSolver

type MultiImageSolver interface {
	SolveImages(ctx context.Context, defs []*ImageDef) (*ImageSolverResults, error)
}

MultiImageSolver can create a Docker image for the WITH DOCKER command using the embedded BuildKit registry.

type MultiTarget

type MultiTarget struct {
	// Visited represents the previously visited states, grouped by target
	// name. Duplicate targets are possible if same target is called with different
	// build args.
	Visited VisitedCollection
	// Final is the main target to be built.
	Final *SingleTarget
}

MultiTarget holds LLB states representing multiple earthly targets, in the order in which they should be built.

func (*MultiTarget) All

func (mts *MultiTarget) All() []*SingleTarget

All returns all SingleTarget contained within.

func (*MultiTarget) FinalTarget

func (mts *MultiTarget) FinalTarget() domain.Target

FinalTarget returns the final target of the states.

type RunPush

type RunPush struct {
	CommandStrs        []string
	State              pllb.State
	SaveLocals         []SaveLocal
	SaveImages         []SaveImage
	InteractiveSession InteractiveSession
	HasState           bool
}

RunPush is a series of RUN --push commands to be run after the build has been deemed as successful, along with artifacts to save and images to push

type SaveImage

type SaveImage struct {
	State        pllb.State
	Image        *image.Image
	DockerTag    string
	Push         bool
	InsecurePush bool
	// CacheHint instructs Earthly to save a separate ref for this image, even if no tag is
	// provided.
	CacheHint           bool
	HasPushDependencies bool
	// ForceSave indicates whether the image should be force-saved and (possibly pushed).
	ForceSave bool
	// CheckDuplicate indicates whether to check if the image name shows up
	// multiple times during output.
	CheckDuplicate bool
	// NoManifestList indicates that the image should not include a manifest
	// list (usually used for multi-platform setups). This means that the image
	// can only be a single-platform image.
	NoManifestList bool

	Platform    platutil.Platform
	HasPlatform bool // true when the --platform value was set (either on cli, or via FROM --platform=..., or BUILD --platform=...)

	SkipBuilder bool // for use with WAIT/END
}

SaveImage is a docker image to be saved.

type SaveLocal

type SaveLocal struct {
	// DestPath is the local dest path to copy the artifact to.
	DestPath string
	// ArtifactPath is the relative path within the artifacts image.
	ArtifactPath string
	// Index is the index number of the "save as local" command encountered. Starts as 0.
	Index int
	// IfExists allows the artifact to be optional.
	IfExists bool
}

SaveLocal is an artifact path to be saved to local disk.

type SingleTarget

type SingleTarget struct {
	// ID is a random unique string.
	ID                     string
	Target                 domain.Target
	PlatformResolver       *platutil.Resolver
	MainImage              *image.Image
	MainState              pllb.State
	ArtifactsState         pllb.State
	SeparateArtifactsState []pllb.State
	SaveLocals             []SaveLocal
	SaveImages             []SaveImage
	VarCollection          *variables.Collection
	RunPush                RunPush
	InteractiveSession     InteractiveSession
	GlobalImports          map[string]domain.ImportTrackerVal
	// HasDangling represents whether the target has dangling instructions -
	// ie if there are any non-SAVE commands after the first SAVE command,
	// or if the target is invoked via BUILD command (not COPY nor FROM).
	HasDangling bool
	// RanFromLike represents whether we have encountered a FROM-like command
	// (eg FROM, FROM DOCKERFILE, LOCALLY).
	RanFromLike bool
	// RanInteractive represents whether we have encountered an --interactive command.
	RanInteractive bool

	// WaitBlocks contains the caller's waitblock plus any additional waitblocks defined in the target
	WaitBlocks []waitutil.WaitBlock

	// WaitItems contains all wait items which are created by the target
	// it exists for tracking items in the target vs a caller's wait block that is shared between multiple targets
	WaitItems []waitutil.WaitItem
	// contains filtered or unexported fields
}

SingleTarget holds LLB states representing an earthly target.

func (*SingleTarget) AddBuildArgInput

func (sts *SingleTarget) AddBuildArgInput(bai dedup.BuildArgInput)

AddBuildArgInput adds a bai to the sts's target input.

func (*SingleTarget) AddDependentIDs

func (sts *SingleTarget) AddDependentIDs(dependentIDs map[string]bool)

AddDependentIDs adds additional IDs that depend on this sts.

func (*SingleTarget) AddWaitBlock

func (sts *SingleTarget) AddWaitBlock(waitBlock waitutil.WaitBlock)

AddWaitBlock adds a wait block to the state

func (*SingleTarget) AttachTopLevelWaitItems

func (sts *SingleTarget) AttachTopLevelWaitItems(ctx context.Context, waitBlock waitutil.WaitBlock)

AttachTopLevelWaitItems adds pre-created wait items to a new waitblock

func (*SingleTarget) Done

func (sts *SingleTarget) Done() chan struct{}

Done returns a channel that is closed when the sts is complete.

func (*SingleTarget) GetDoPushes

func (sts *SingleTarget) GetDoPushes() bool

GetDoPushes returns whether the SAVE IMAGE --push or RUN --push commands should be executed

func (*SingleTarget) GetDoSaves

func (sts *SingleTarget) GetDoSaves() bool

GetDoSaves returns whether the SaveImages and the SaveLocals should be actually saved.

func (*SingleTarget) LastSaveImage

func (sts *SingleTarget) LastSaveImage() SaveImage

LastSaveImage returns the last save image available (if any).

func (*SingleTarget) MonitorDependencySubscription

func (sts *SingleTarget) MonitorDependencySubscription(ctx context.Context, inCh chan string)

MonitorDependencySubscription monitors for new dependencies.

func (*SingleTarget) NewDependencySubscription

func (sts *SingleTarget) NewDependencySubscription() chan string

NewDependencySubscription adds additional IDs that depend on this sts.

func (*SingleTarget) SetDoPushes

func (sts *SingleTarget) SetDoPushes()

SetDoPushes sets the doPushes flag.

func (*SingleTarget) SetDoSaves

func (sts *SingleTarget) SetDoSaves()

SetDoSaves sets the DoSaves flag.

func (*SingleTarget) TargetInput

func (sts *SingleTarget) TargetInput() dedup.TargetInput

TargetInput returns the target input in a concurrent-safe way.

func (*SingleTarget) Wait

func (sts *SingleTarget) Wait(ctx context.Context) error

Wait performs a Wait on all wait blocks

type SolveCache

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

SolveCache is a formal version of the cache we keep mapping targets to their LLB state.

func NewSolveCache

func NewSolveCache() *SolveCache

NewSolveCache gives a new SolveCachemap instance

func (*SolveCache) Do

func (sc *SolveCache) Do(ctx context.Context, sk StateKey, constructor SolveCacheConstructor) (pllb.State, error)

Do sets an LLB state in the given solve cache. If the state has been previously constructed, it is returned immediately without calling the constructor again.

type SolveCacheConstructor

type SolveCacheConstructor func(context.Context, StateKey) (pllb.State, error)

SolveCacheConstructor is func taking a StateKey and returning a state.

type StateKey

type StateKey string

StateKey is a type for a key in SolveCache. These keys seem to be highly convention based, and used elsewhere too (LocalFolders?). so this is a step at formalizing that convention, since we sometimes need one key, and sometimes another. It may give us some toeholds to help with some refactoring later.

func KeyFromHashAndTag

func KeyFromHashAndTag(target *SingleTarget, dockerTag string) (StateKey, error)

KeyFromHashAndTag builds a state key from a given target state and a docker tag. This is useful when you want to reference the same image but with a different name.

func KeyFromState

func KeyFromState(target *SingleTarget) (StateKey, error)

KeyFromState is a simple wrapper to get a key from a given state using the hash of its target.

type VisitedCollection

type VisitedCollection interface {
	// All returns all visited items.
	All() []*SingleTarget
	// Add adds a target to the collection, if it hasn't yet been visited. The returned sts is
	// either the previously visited one or a brand new one.
	Add(ctx context.Context, target domain.Target, platr *platutil.Resolver, allowPrivileged bool, overridingVars *variables.Scope, parentDepSub chan string) (*SingleTarget, bool, error)
}

VisitedCollection represents a collection of visited targets.

func NewLegacyVisitedCollection

func NewLegacyVisitedCollection() VisitedCollection

NewLegacyVisitedCollection returns a collection of visited targets.

func NewVisitedUpfrontHashCollection

func NewVisitedUpfrontHashCollection() VisitedCollection

NewVisitedUpfrontHashCollection returns a collection of visited targets.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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