Documentation ¶
Overview ¶
Package buildengine provides a framework for building FTL modules.
Index ¶
- Constants
- Variables
- func Build(ctx context.Context, sch *schema.Schema, module Module, ...) error
- func ComputeFileHash(baseDir, srcPath string, watch []string) (hash []byte, matched bool, err error)
- func Deploy(ctx context.Context, module Module, replicas int32, waitForDeployOnline bool, ...) error
- func SetPOMProperties(ctx context.Context, baseDir string) error
- func TopologicalSort(graph map[string][]string) (groups [][]string, cycleError error)
- func WalkDir(dir string, fn func(path string, d fs.DirEntry) error) error
- type BuildStartedListenerFunc
- type DeployClient
- type Engine
- func (e *Engine) Build(ctx context.Context) error
- func (e *Engine) Close() error
- func (e *Engine) Deploy(ctx context.Context, replicas int32, waitForDeployOnline bool) error
- func (e *Engine) Dev(ctx context.Context, period time.Duration, commands projectconfig.Commands) error
- func (e *Engine) Graph(moduleNames ...string) (map[string][]string, error)
- func (e *Engine) Import(ctx context.Context, schema *schema.Module)
- type FileChangeType
- type FileHashes
- type Listener
- type ModifyFilesTransaction
- type Module
- type Option
- type WatchEvent
- type WatchEventModuleAdded
- type WatchEventModuleChanged
- type WatchEventModuleRemoved
- type Watcher
Constants ¶
const BuildLockTimeout = time.Minute
Variables ¶
var ErrSkip = errors.New("skip directory")
ErrSkip can be returned by the WalkDir callback to skip a file or directory.
Functions ¶
func Build ¶
func Build(ctx context.Context, sch *schema.Schema, module Module, filesTransaction ModifyFilesTransaction) error
Build a module in the given directory given the schema and module config.
A lock file is used to ensure that only one build is running at a time.
func ComputeFileHash ¶ added in v0.182.2
func Deploy ¶ added in v0.139.0
func Deploy(ctx context.Context, module Module, replicas int32, waitForDeployOnline bool, client DeployClient) error
Deploy a module to the FTL controller with the given number of replicas. Optionally wait for the deployment to become ready.
func SetPOMProperties ¶ added in v0.133.1
SetPOMProperties updates the ftl.version properties in the pom.xml file in the given base directory.
func TopologicalSort ¶ added in v0.134.1
TopologicalSort attempts to order the modules supplied in the graph based on their topologically sorted order. A cycle in the module dependency graph will cause this sort to be incomplete. The sorted modules are returned as a sequence of `groups` of modules that may be built in parallel. The `unsorted` modules impacted by a dependency cycle get reported as an error.
Types ¶
type BuildStartedListenerFunc ¶ added in v0.161.1
type BuildStartedListenerFunc func(module Module)
func (BuildStartedListenerFunc) OnBuildStarted ¶ added in v0.161.1
func (b BuildStartedListenerFunc) OnBuildStarted(module Module)
type DeployClient ¶ added in v0.145.4
type DeployClient interface { GetArtefactDiffs(ctx context.Context, req *connect.Request[ftlv1.GetArtefactDiffsRequest]) (*connect.Response[ftlv1.GetArtefactDiffsResponse], error) UploadArtefact(ctx context.Context, req *connect.Request[ftlv1.UploadArtefactRequest]) (*connect.Response[ftlv1.UploadArtefactResponse], error) CreateDeployment(ctx context.Context, req *connect.Request[ftlv1.CreateDeploymentRequest]) (*connect.Response[ftlv1.CreateDeploymentResponse], error) ReplaceDeploy(ctx context.Context, req *connect.Request[ftlv1.ReplaceDeployRequest]) (*connect.Response[ftlv1.ReplaceDeployResponse], error) Status(ctx context.Context, req *connect.Request[ftlv1.StatusRequest]) (*connect.Response[ftlv1.StatusResponse], error) }
type Engine ¶ added in v0.134.1
type Engine struct {
// contains filtered or unexported fields
}
Engine for building a set of modules.
func New ¶ added in v0.134.1
func New(ctx context.Context, client ftlv1connect.ControllerServiceClient, moduleDirs []string, options ...Option) (*Engine, error)
New constructs a new Engine.
Completely offline builds are possible if the full dependency graph is locally available. If the FTL controller is available, it will be used to pull in missing schemas.
"dirs" are directories to scan for local modules.
func (*Engine) Dev ¶ added in v0.142.0
func (e *Engine) Dev(ctx context.Context, period time.Duration, commands projectconfig.Commands) error
Dev builds and deploys all local modules and watches for changes, redeploying as necessary.
type FileChangeType ¶ added in v0.131.0
type FileChangeType rune
const ( FileAdded FileChangeType = '+' FileRemoved FileChangeType = '-' FileChanged FileChangeType = '*' )
func CompareFileHashes ¶
func CompareFileHashes(oldFiles, newFiles FileHashes) (FileChangeType, string, bool)
CompareFileHashes compares the hashes of the files in the oldFiles and newFiles maps.
Returns true if the hashes are equal, false otherwise.
If false, the returned string will be a file that caused the difference and the returned FileChangeType will be the type of change that occurred.
func (FileChangeType) GoString ¶ added in v0.131.0
func (f FileChangeType) GoString() string
func (FileChangeType) String ¶ added in v0.131.0
func (f FileChangeType) String() string
type FileHashes ¶ added in v0.131.0
func ComputeFileHashes ¶
func ComputeFileHashes(module Module) (FileHashes, error)
ComputeFileHashes computes the SHA256 hash of all (non-git-ignored) files in the given directory.
type ModifyFilesTransaction ¶ added in v0.182.2
type ModifyFilesTransaction interface { Begin() error ModifiedFiles(paths ...string) error End() error }
ModifyFilesTransaction allows builds to modify files in a module without triggering a watch event. This helps us avoid infinite loops with builds changing files, and those changes triggering new builds.as a no-op
type Module ¶ added in v0.131.0
type Module struct { Config moduleconfig.ModuleConfig Dependencies []string }
Module represents an FTL module in the build engine
func DiscoverModules ¶
DiscoverModules recursively loads all modules under the given directories (or if none provided, the current working directory is used).
func LoadModule ¶ added in v0.133.1
LoadModule loads a module from the given directory.
func UpdateDependencies ¶
UpdateDependencies finds the dependencies for a module and returns a Module with those dependencies populated.
func (Module) CopyWithDependencies ¶ added in v0.155.0
type Option ¶ added in v0.147.0
type Option func(o *Engine)
func Parallelism ¶ added in v0.147.0
func WithListener ¶ added in v0.160.0
WithListener sets the event listener for the Engine.
type WatchEvent ¶ added in v0.131.0
type WatchEvent interface {
// contains filtered or unexported methods
}
A WatchEvent is an event that occurs when a module is added, removed, or changed.
type WatchEventModuleAdded ¶ added in v0.131.0
type WatchEventModuleAdded struct{ Module Module }
type WatchEventModuleChanged ¶ added in v0.131.0
type WatchEventModuleChanged struct { Module Module Change FileChangeType Path string Time time.Time }
type WatchEventModuleRemoved ¶ added in v0.131.0
type WatchEventModuleRemoved struct{ Module Module }
type Watcher ¶ added in v0.182.2
type Watcher struct {
// contains filtered or unexported fields
}
func NewWatcher ¶ added in v0.182.2
func NewWatcher() *Watcher
func (*Watcher) GetTransaction ¶ added in v0.182.2
func (w *Watcher) GetTransaction(moduleDir string) ModifyFilesTransaction