earthfile2llb

package
v0.7.14 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: MPL-2.0 Imports: 78 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgName added in v0.7.3

func ArgName(ctx context.Context, cmd spec.Command, isBase bool, explicitGlobal bool) (_ string, _ *string, isRequired bool, isGlobal bool, _ error)

ArgName returns the parsed name of an ARG command, the default value (if any), and the state of the --required and --global flags.

func ArtifactName added in v0.7.3

func ArtifactName(ctx context.Context, cmd spec.Command) (string, *string, error)

ArtifactName returns the parsed name of a SAVE ARTIFACT command and its local name (if any).

func ContextWithSourceLocation added in v0.6.26

func ContextWithSourceLocation(ctx context.Context, sl *spec.SourceLocation) context.Context

ContextWithSourceLocation returns a new context with the given source location.

func Earthfile2LLB

func Earthfile2LLB(ctx context.Context, target domain.Target, opt ConvertOpt, initialCall bool) (mts *states.MultiTarget, retErr error)

Earthfile2LLB parses a earthfile and executes the statements for a given target.

func GetTargetArgs added in v0.6.15

func GetTargetArgs(ctx context.Context, resolver *buildcontext.Resolver, gwClient gwclient.Client, target domain.Target) ([]string, error)

GetTargetArgs returns a list of build arguments for a specified target

func GetTargets added in v0.3.2

func GetTargets(ctx context.Context, resolver *buildcontext.Resolver, gwClient gwclient.Client, target domain.Target) ([]string, error)

GetTargets returns a list of targets from an Earthfile. Note that the passed in domain.Target's target name is ignored (only the reference to the Earthfile is used)

func ImageNames added in v0.7.3

func ImageNames(ctx context.Context, cmd spec.Command) ([]string, error)

ImageNames returns the parsed names of a SAVE IMAGE command.

func SourceLocationFromContext added in v0.6.26

func SourceLocationFromContext(ctx context.Context) *spec.SourceLocation

SourceLocationFromContext returns the source location from the given context.

Types

type CachedMetaResolver added in v0.6.15

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

CachedMetaResolver is an image meta resolver with a local cache.

func NewCachedMetaResolver added in v0.6.15

func NewCachedMetaResolver(metaResolver llb.ImageMetaResolver) *CachedMetaResolver

NewCachedMetaResolver creates a new cached meta resolver based on an underlying meta resolver which needs to be provided.

func (*CachedMetaResolver) ResolveImageConfig added in v0.6.15

func (cmr *CachedMetaResolver) ResolveImageConfig(ctx context.Context, ref string, opt llb.ResolveImageConfigOpt) (string, digest.Digest, []byte, error)

ResolveImageConfig implements llb.ImageMetaResolver.ResolveImageConfig.

type ConvertOpt added in v0.3.0

type ConvertOpt struct {
	// GwClient is the BuildKit gateway client.
	GwClient gwclient.Client
	// Resolver is the build context resolver.
	Resolver *buildcontext.Resolver
	// GlobalImports is a map of imports used to dereference import ref targets, commands, etc.
	GlobalImports map[string]domain.ImportTrackerVal
	// The resolve mode for referenced images (force pull or prefer local).
	ImageResolveMode llb.ResolveMode
	// DockerImageSolverTar is similar to the above solver but it uses a tar
	// file to transfer images. To be deprecated in favor of the local registry version.
	DockerImageSolverTar states.DockerTarImageSolver
	// MultiImageSolver can solve multiple images using a single build
	// request. Primarily used for WITH DOCKER commands.
	MultiImageSolver states.MultiImageSolver
	// CleanCollection is a collection of cleanup functions.
	CleanCollection *cleanup.Collection
	// Visited is a collection of target states which have been converted to LLB.
	// This is used for deduplication and infinite cycle detection.
	Visited *states.VisitedCollection
	// PlatformResolver is a platform resolver, which keeps track of
	// the current platform, the native platform, the user platform, and
	// the default platform.
	PlatformResolver *platutil.Resolver
	// OverridingVars is a collection of build args used for overriding args in the build.
	OverridingVars *variables.Scope
	// A cache for image solves. (maybe dockerTag +) depTargetInputHash -> context containing image.tar.
	SolveCache *states.SolveCache
	// BuildContextProvider is the provider used for local build context files.
	BuildContextProvider *provider.BuildContextProvider
	// MetaResolver is the image meta resolver to use for resolving image metadata.
	MetaResolver llb.ImageMetaResolver
	// CacheImports is a set of docker tags that can be used to import cache. Note that this
	// set is modified by the converter if InlineCache is enabled.
	CacheImports *states.CacheImports
	// UseInlineCache enables the inline caching feature (use any SAVE IMAGE --push declaration as
	// cache import).
	UseInlineCache bool
	// UseFakeDep is an internal feature flag for fake dep.
	UseFakeDep bool
	// AllowLocally is an internal feature flag for controlling if LOCALLY directives can be used.
	AllowLocally bool
	// AllowInteractive is an internal feature flag for controlling if interactive sessions can be initiated.
	AllowInteractive bool
	// EnableInteractiveDebugger is set to true when earthly is run with the --interactive cli flag
	InteractiveDebuggerEnabled bool
	// InteractiveDebuggerDebugLevelLogging controls if debug-level-logging is enabled within the interactive-debugger
	InteractiveDebuggerDebugLevelLogging bool
	// 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
	// Console is for logging
	Console conslogging.ConsoleLogger
	// AllowPrivileged is used to allow (or prevent) any "RUN --privileged" or RUNs under a LOCALLY target to be executed,
	// when set to false, it prevents other referenced remote targets from requesting elevated privileges
	AllowPrivileged bool
	// DoSaves controls when SAVE ARTIFACT AS LOCAL, and SAVE IMAGE (to the local docker instance) calls are executed
	// When a SAVE IMAGE --push is encountered, the image may still be pushed to the remote registry (as long as DoPushes=true),
	// but is not exported to the local docker instance.
	DoSaves bool
	// DoPushes controls when a SAVE IMAGE --push, and RUN --push commands are executed;
	// SAVE IMAGE --push ... will still export an image to the local docker instance (as long as DoSaves=true)
	DoPushes bool
	// IsCI determines whether it is running from a CI environment.
	IsCI bool
	// EarthlyCIRunner determines whether it is running from an Earthly CI environment.
	EarthlyCIRunner bool
	// ForceSaveImage is used to force all SAVE IMAGE commands are executed regardless of if they are
	// for a local or remote target; this is to support the legacy behaviour that was first introduced in earthly (up to 0.5)
	// When this is set to false, SAVE IMAGE commands are only executed when DoSaves is true.
	ForceSaveImage bool
	// OnlyFinalTargetImages is used to ignore SAVE IMAGE commands in indirectly referenced targets
	OnlyFinalTargetImages bool
	// Gitlookup is used to attach credentials to GIT CLONE operations
	GitLookup *buildcontext.GitLookup
	// LocalStateCache provides a cache for local pllb.States
	LocalStateCache *LocalStateCache
	// UseLocalRegistry indicates whether the BuildKit-embedded registry can be used for exports.
	UseLocalRegistry bool
	// LocalRegistryAddr is the address of the BuildKit-embedded registry.
	LocalRegistryAddr string

	// Features is the set of enabled features
	Features *features.Features

	// ParallelConversion is a feature flag enabling the parallel conversion algorithm.
	ParallelConversion bool
	// Parallelism is a semaphore controlling the maximum parallelism.
	Parallelism semutil.Semaphore
	// ErrorGroup is a serrgroup used to submit parallel conversion jobs.
	ErrorGroup *serrgroup.Group

	// FeatureFlagOverrides is used to override feature flags that are defined in specific Earthfiles
	FeatureFlagOverrides string
	// Default set of ARGs to make available in Earthfile.
	BuiltinArgs variables.DefaultArgs
	// NoCache sets llb.IgnoreCache before calling StateToRef
	NoCache bool

	// ContainerFrontend is the currently used container frontend, as detected by Earthly at app start. It provides info
	// and access to commands to manipulate the current container frontend.
	ContainerFrontend containerutil.ContainerFrontend

	// GlobalWaitBlockFtr, when true, forces all Earthfiles to add entries into the WAIT/END block
	// this is to facilitate de-duplicating code from builder.go
	GlobalWaitBlockFtr bool

	// ExportCoordinator points to the per-connection map used by the builder's onPull callback
	ExportCoordinator *gatewaycrafter.ExportCoordinator

	// LocalArtifactWhiteList points to the per-connection list of seen SAVE ARTIFACT ... AS LOCAL entries
	LocalArtifactWhiteList *gatewaycrafter.LocalArtifactWhiteList

	// InternalSecretStore is a secret store used internally by Earthly.
	// It is mainly used to pass along parameters to buildkit processes without
	// invalidating the cache.
	InternalSecretStore *secretprovider.MutableMapStore

	// TempEarthlyOutDir is a path to a temp dir where artifacts are temporarily saved
	TempEarthlyOutDir func() (string, error)

	// LLBCaps indicates that builder's capabilities
	LLBCaps *apicaps.CapSet

	// MainTargetDetailsFunc is a custom function used to handle the target details, once known.
	MainTargetDetailsFunc func(TargetDetails) error

	// Logbus is the bus used for logging and metadata reporting.
	Logbus *logbus.Bus

	// The runner used to execute the target on. This is used only for metadata reporting purposes.
	// May be one of the following:
	// * "local:<hostname>" - local builds
	// * "bk:<buildkit-address>" - remote builds via buildkit
	// * "sat:<org-name>/<sat-name>" - remote builds via satellite
	Runner string

	ProjectAdder ProjectAdder
	// contains filtered or unexported fields
}

ConvertOpt holds conversion parameters.

type ConvertRunOpts added in v0.6.15

type ConvertRunOpts struct {
	CommandName          string
	Args                 []string
	Locally              bool
	Mounts               []string
	Secrets              []string
	WithEntrypoint       bool
	WithShell            bool
	Privileged           bool
	NoNetwork            bool
	Push                 bool
	Transient            bool
	WithSSH              bool
	NoCache              bool
	Interactive          bool
	InteractiveKeep      bool
	InteractiveSaveFiles []debuggercommon.SaveFilesSettings
	// contains filtered or unexported fields
}

ConvertRunOpts represents a set of options needed for the RUN command.

type Converter

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

Converter turns earthly commands to buildkit LLB representation.

func NewConverter

func NewConverter(ctx context.Context, target domain.Target, bc *buildcontext.Data, sts *states.SingleTarget, opt ConvertOpt) (*Converter, error)

NewConverter constructs a new converter for a given earthly target.

func (*Converter) Arg

func (c *Converter) Arg(ctx context.Context, argKey string, defaultArgValue string, opts commandflag.ArgOpts) error

Arg applies the ARG command.

func (*Converter) Build

func (c *Converter) Build(ctx context.Context, fullTargetName string, platform platutil.Platform, allowPrivileged bool, buildArgs []string) error

Build applies the earthly BUILD command.

func (*Converter) BuildAsync added in v0.6.15

func (c *Converter) BuildAsync(ctx context.Context, fullTargetName string, platform platutil.Platform, allowPrivileged bool, buildArgs []string, cmdT cmdType, apf afterParallelFunc, sem semutil.Semaphore) error

BuildAsync applies the earthly BUILD command asynchronously.

func (*Converter) Cache added in v0.6.15

func (c *Converter) Cache(ctx context.Context, mountTarget string, sharing string) error

Cache handles a `CACHE` command in a Target. It appends run options to the Converter which will mount a cache volume in each successive `RUN` command, and configures the `Converter` to persist the cache in the image at the end of the target.

func (*Converter) Cmd

func (c *Converter) Cmd(ctx context.Context, cmdArgs []string, isWithShell bool) error

Cmd applies the CMD command.

func (*Converter) CopyArtifact

func (c *Converter) CopyArtifact(ctx context.Context, artifactName string, dest string, platform platutil.Platform, allowPrivileged bool, buildArgs []string, isDir bool, keepTs bool, keepOwn bool, chown string, chmod *fs.FileMode, ifExists, symlinkNoFollow bool) error

CopyArtifact applies the earthly COPY artifact command.

func (*Converter) CopyArtifactLocal added in v0.6.15

func (c *Converter) CopyArtifactLocal(ctx context.Context, artifactName string, dest string, platform platutil.Platform, allowPrivileged bool, buildArgs []string, isDir bool) error

CopyArtifactLocal applies the earthly COPY artifact command which are invoked under a LOCALLY target.

func (*Converter) CopyClassical

func (c *Converter) CopyClassical(ctx context.Context, srcs []string, dest string, isDir bool, keepTs bool, keepOwn bool, chown string, chmod *fs.FileMode, ifExists bool) error

CopyClassical applies the earthly COPY command, with classical args.

func (*Converter) EnterScopeDo added in v0.6.15

func (c *Converter) EnterScopeDo(ctx context.Context, command domain.Command, baseTarget domain.Target, allowPrivileged bool, scopeName string, buildArgs []string) error

EnterScopeDo introduces a new variable scope. Globals and imports are fetched from baseTarget.

func (*Converter) Entrypoint

func (c *Converter) Entrypoint(ctx context.Context, entrypointArgs []string, isWithShell bool) error

Entrypoint applies the ENTRYPOINT command.

func (*Converter) Env

func (c *Converter) Env(ctx context.Context, envKey string, envValue string) error

Env applies the ENV command.

func (*Converter) ExitScope added in v0.6.15

func (c *Converter) ExitScope(ctx context.Context) error

ExitScope exits the most recent variable scope.

func (*Converter) ExpandArgs added in v0.3.3

func (c *Converter) ExpandArgs(ctx context.Context, runOpts ConvertRunOpts, word string, allowShellOut bool) (string, error)

ExpandArgs expands args in the provided word.

func (*Converter) Expose

func (c *Converter) Expose(ctx context.Context, ports []string) error

Expose applies the EXPOSE command.

func (*Converter) FinalizeStates

func (c *Converter) FinalizeStates(ctx context.Context) (*states.MultiTarget, error)

FinalizeStates returns the LLB states.

func (*Converter) From

func (c *Converter) From(ctx context.Context, imageName string, platform platutil.Platform, allowPrivileged bool, buildArgs []string) error

From applies the earthly FROM command.

func (*Converter) FromDockerfile added in v0.3.0

func (c *Converter) FromDockerfile(ctx context.Context, contextPath string, dfPath string, dfTarget string, platform platutil.Platform, buildArgs []string) error

FromDockerfile applies the earthly FROM DOCKERFILE command.

func (*Converter) GitClone

func (c *Converter) GitClone(ctx context.Context, gitURL string, branch string, dest string, keepTs bool) error

GitClone applies the GIT CLONE command.

func (*Converter) Healthcheck added in v0.2.0

func (c *Converter) Healthcheck(ctx context.Context, isNone bool, cmdArgs []string, interval time.Duration, timeout time.Duration, startPeriod time.Duration, retries int) error

Healthcheck applies the HEALTHCHECK command.

func (*Converter) Host added in v0.6.15

func (c *Converter) Host(ctx context.Context, hostname string, ip net.IP) error

Host handles a `HOST` command in a Target.

func (*Converter) Import added in v0.6.15

func (c *Converter) Import(ctx context.Context, importStr, as string, isGlobal, currentlyPrivileged, allowPrivilegedFlag bool) error

Import applies the IMPORT command.

func (*Converter) Label

func (c *Converter) Label(ctx context.Context, labels map[string]string) error

Label applies the LABEL command.

func (*Converter) Let added in v0.7.3

func (c *Converter) Let(ctx context.Context, key string, value string) error

Let applies the LET command.

func (*Converter) Locally added in v0.4.6

func (c *Converter) Locally(ctx context.Context) error

Locally applies the earthly Locally command.

func (*Converter) Pipeline added in v0.6.24

func (c *Converter) Pipeline(ctx context.Context) error

Pipeline handles a "PIPELINE" command.

func (*Converter) PopWaitBlock added in v0.6.15

func (c *Converter) PopWaitBlock(ctx context.Context) error

PopWaitBlock should be called when an END is encountered, it will block until all commands within the block complete

func (*Converter) Project added in v0.6.20

func (c *Converter) Project(ctx context.Context, org, project string) error

Project handles a "PROJECT" command in base target.

func (*Converter) PushWaitBlock added in v0.6.15

func (c *Converter) PushWaitBlock(ctx context.Context) error

PushWaitBlock should be called when a WAIT block starts, all commands will be added to this new block

func (*Converter) RecordTargetFailure added in v0.7.0

func (c *Converter) RecordTargetFailure(ctx context.Context, err error)

RecordTargetFailure records a failure in a target.

func (*Converter) ResolveReference added in v0.6.15

func (c *Converter) ResolveReference(ctx context.Context, ref domain.Reference) (bc *buildcontext.Data, allowPrivileged, allowPrivilegedSet bool, err error)

ResolveReference resolves a reference's build context given the current state: relativity to the Earthfile, imports etc.

func (*Converter) Run

func (c *Converter) Run(ctx context.Context, opts ConvertRunOpts) error

Run applies the earthly RUN command.

func (*Converter) RunCommand added in v0.6.15

func (c *Converter) RunCommand(ctx context.Context, commandName string, opts ConvertRunOpts) (string, error)

RunCommand runs a command and returns its output. The run is transient - any state created is not used in subsequent commands.

func (*Converter) RunExitCode added in v0.6.15

func (c *Converter) RunExitCode(ctx context.Context, opts ConvertRunOpts) (int, error)

RunExitCode executes a run for the purpose of determining the exit code of the command. This can be used in conditionals.

func (*Converter) RunExpression added in v0.6.15

func (c *Converter) RunExpression(ctx context.Context, expressionName string, opts ConvertRunOpts) (string, error)

RunExpression runs an expression and returns its output. The run is transient - any state created is not used in subsequent commands.

func (*Converter) SaveArtifact

func (c *Converter) SaveArtifact(ctx context.Context, saveFrom string, saveTo string, saveAsLocalTo string, keepTs bool, keepOwn bool, ifExists, symlinkNoFollow, force bool, isPush bool) error

SaveArtifact applies the earthly SAVE ARTIFACT command.

func (*Converter) SaveArtifactFromLocal added in v0.6.15

func (c *Converter) SaveArtifactFromLocal(ctx context.Context, saveFrom, saveTo string, keepTs, keepOwn bool, chown string) error

SaveArtifactFromLocal saves a local file into the ArtifactsState

func (*Converter) SaveImage

func (c *Converter) SaveImage(ctx context.Context, imageNames []string, hasPushFlag bool, insecurePush bool, cacheHint bool, cacheFrom []string, noManifestList bool) error

SaveImage applies the earthly SAVE IMAGE command.

func (*Converter) SetArg added in v0.6.15

func (c *Converter) SetArg(ctx context.Context, argKey string, argValue string) error

SetArg sets an arg to a specific value.

func (*Converter) StackString added in v0.6.15

func (c *Converter) StackString() string

StackString string returns the current command stack string.

func (*Converter) UnsetArg added in v0.6.15

func (c *Converter) UnsetArg(ctx context.Context, argKey string) error

UnsetArg unsets a previously declared arg. If the arg does not exist this operation is a no-op.

func (*Converter) UpdateArg added in v0.7.3

func (c *Converter) UpdateArg(ctx context.Context, argKey string, argValue string, isBase bool) error

UpdateArg updates an existing arg to a new value. It errors if the arg could not be found.

func (*Converter) User

func (c *Converter) User(ctx context.Context, user string) error

User applies the USER command.

func (*Converter) Volume

func (c *Converter) Volume(ctx context.Context, volumes []string) error

Volume applies the VOLUME command.

func (*Converter) WithDockerRun added in v0.3.2

func (c *Converter) WithDockerRun(ctx context.Context, args []string, opt WithDockerOpt, allowParallel bool) error

WithDockerRun applies an entire WITH DOCKER ... RUN ... END clause.

func (*Converter) WithDockerRunLocal added in v0.6.15

func (c *Converter) WithDockerRunLocal(ctx context.Context, args []string, opt WithDockerOpt, allowParallel bool) error

WithDockerRunLocal applies an entire WITH DOCKER ... RUN ... END clause.

func (*Converter) Workdir

func (c *Converter) Workdir(ctx context.Context, workdirPath string) error

Workdir applies the WORKDIR command.

type DockerLoadOpt added in v0.3.2

type DockerLoadOpt struct {
	Target          string
	ImageName       string
	Platform        platutil.Platform
	BuildArgs       []string
	AllowPrivileged bool
}

DockerLoadOpt holds parameters for WITH DOCKER --load parameter.

type DockerPullOpt added in v0.4.2

type DockerPullOpt struct {
	ImageName string
	Platform  platutil.Platform
}

DockerPullOpt holds parameters for the WITH DOCKER --pull parameter.

type Interpreter added in v0.6.15

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

Interpreter interprets Earthly AST's into calls to the converter.

func (*Interpreter) Run added in v0.6.15

func (i *Interpreter) Run(ctx context.Context, ef spec.Earthfile) (err error)

Run interprets the commands in the given Earthfile AST, for a specific target.

type InterpreterError added in v0.6.15

type InterpreterError struct {
	SourceLocation *spec.SourceLocation
	TargetID       string
	// contains filtered or unexported fields
}

InterpreterError is an error of the interpreter, which contains optional references to the original source code location.

func Errorf added in v0.6.15

func Errorf(sl *spec.SourceLocation, targetID, stack string, format string, args ...interface{}) *InterpreterError

Errorf creates a new interpreter error.

func GetInterpreterError added in v0.6.15

func GetInterpreterError(err error) (*InterpreterError, bool)

GetInterpreterError finds the first InterpreterError in the wrap chain and returns it.

func WrapError added in v0.6.15

func WrapError(cause error, sl *spec.SourceLocation, targetID, stack string, format string, args ...interface{}) *InterpreterError

WrapError wraps another error into a new interpreter error.

func (InterpreterError) Cause added in v0.7.0

func (ie InterpreterError) Cause() error

Cause returns the cause of the error (if any).

func (InterpreterError) Error added in v0.6.15

func (ie InterpreterError) Error() string

func (InterpreterError) Stack added in v0.6.15

func (ie InterpreterError) Stack() string

Stack returns the Earthly stack within the error.

func (InterpreterError) Unwrap added in v0.6.15

func (ie InterpreterError) Unwrap() error

Unwrap unwraps the error.

type LocalStateCache added in v0.6.15

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

LocalStateCache provides caching of local States

func NewSharedLocalStateCache added in v0.6.15

func NewSharedLocalStateCache() *LocalStateCache

NewSharedLocalStateCache creates a new local state cache

type ProjectAdder added in v0.7.10

type ProjectAdder interface {
	AddProject(org, proj string)
}

type StringSliceFlag

type StringSliceFlag struct {
	Args []string
}

StringSliceFlag is a flag backed by a string slice.

func (*StringSliceFlag) Set

func (ssf *StringSliceFlag) Set(arg string) error

Set adds a flag value to the string slice.

func (*StringSliceFlag) String

func (ssf *StringSliceFlag) String() string

String returns a string representation of the flag.

type TargetDetails added in v0.7.0

type TargetDetails struct {
	// EarthlyOrgName is the name of the Earthly org.
	EarthlyOrgName string
	// EarthlyProjectName is the name of the Earthly project.
	EarthlyProjectName string
}

TargetDetails contains details about the target being built.

type WithDockerOpt added in v0.3.2

type WithDockerOpt struct {
	Mounts         []string
	Secrets        []string
	WithShell      bool
	WithEntrypoint bool
	WithSSH        bool
	NoCache        bool
	Interactive    bool

	Pulls                 []DockerPullOpt
	Loads                 []DockerLoadOpt
	ComposeFiles          []string
	ComposeServices       []string
	TryCatchSaveArtifacts []debuggercommon.SaveFilesSettings
	// contains filtered or unexported fields
}

WithDockerOpt holds parameters for WITH DOCKER run.

Jump to

Keyboard shortcuts

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