buildengine

package
v0.465.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: Apache-2.0 Imports: 56 Imported by: 0

Documentation

Overview

Package buildengine provides a framework for building FTL modules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanStubs

func CleanStubs(ctx context.Context, projectRoot string) error

CleanStubs removes all generated stubs.

func GenerateStubs

func GenerateStubs(ctx context.Context, projectRoot string, modules []*schema.Module, metas map[string]moduleMeta) error

GenerateStubs generates stubs for the given modules.

Currently, only Go stubs are supported. Kotlin and other language stubs can be added in the future.

func SyncStubReferences

func SyncStubReferences(ctx context.Context, projectRoot string, moduleNames []string, metas map[string]moduleMeta, view *schema.Schema) error

SyncStubReferences syncs the references in the generated stubs.

For Go, this means updating all the go.work files to include all known modules in the shared stubbed modules directory.

func TopologicalSort

func TopologicalSort(graph map[string][]string) (groups [][]string, cycleError error)

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 Config added in v0.434.0

type Config struct {
	EventCacheRetention *time.Duration `help:"Delete cached events after this time period. 0 to disable" env:"FTL_EVENT_CACHE_RETENTION" default:"24h"`
}

type DependencyCycleError added in v0.460.0

type DependencyCycleError struct {
	Modules []string
}

func (DependencyCycleError) Error added in v0.460.0

func (e DependencyCycleError) Error() string

type DependencyGrapher added in v0.462.0

type DependencyGrapher interface {
	Graph(moduleNames ...string) (map[string][]string, error)
}

type DependencyMode

type DependencyMode string

DependencyMode is an enum for dependency modes

const (
	Raw                  DependencyMode = "Raw"
	AlwaysIncludeBuiltin DependencyMode = "AlwaysIncludingBuiltin"
)

type DeployCoordinator added in v0.462.0

type DeployCoordinator struct {
	SchemaUpdates chan SchemaUpdatedEvent
	// contains filtered or unexported fields
}

DeployCoordinator manages the deployment of modules through changesets. It ensures that changesets are deployed in the correct order and that changesets are not deployed if they are superseded by a newer changeset.

The DeployCoordinator also maintains a schema based on active changesets and queued modules. This allows the build engine to build modules against where the schema is moving to. For example if module A is dependant on module B and module B builds with a breaking schema change deploy coordinator will put deployment of A into a pending state, but publish it as part of the its schema. This allows the build engine to react and build module A against the new schema for module B. The DeployCoordinator will then create a changeset of A and B together.

func NewDeployCoordinator added in v0.462.0

func NewDeployCoordinator(
	ctx context.Context,
	adminClient AdminClient,
	schemaSource *schemaeventsource.EventSource,
	dependencyGrapher DependencyGrapher,
	engineUpdates chan *buildenginepb.EngineEvent,
	logChanges bool,
) *DeployCoordinator

type Engine

type Engine struct {

	// topic to subscribe to engine events
	EngineUpdates *pubsub.Topic[*buildenginepb.EngineEvent]
	// contains filtered or unexported fields
}

Engine for building a set of modules.

func New

func New(
	ctx context.Context,
	adminClient AdminClient,
	schemaSource *schemaeventsource.EventSource,
	projectConfig projectconfig.Config,
	moduleDirs []string,
	updatesEndpoint *url.URL,
	logChanges bool,
	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) Build

func (e *Engine) Build(ctx context.Context) error

Build attempts to build all local modules.

func (*Engine) BuildAndDeploy

func (e *Engine) BuildAndDeploy(ctx context.Context, replicas optional.Option[int32], waitForDeployOnline bool, singleChangeset bool, moduleNames ...string) (err error)

BuildAndDeploy attempts to build and deploy all local modules.

func (*Engine) Close

func (e *Engine) Close() error

Close stops the Engine's schema sync.

func (*Engine) Dev

func (e *Engine) Dev(ctx context.Context, period time.Duration) error

Dev builds and deploys all local modules and watches for changes, redeploying as necessary.

func (*Engine) Each

func (e *Engine) Each(fn func(Module) error) (err error)

Each iterates over all local modules.

func (*Engine) GetModuleSchema added in v0.462.0

func (e *Engine) GetModuleSchema(moduleName string) (*schema.Module, bool)

func (*Engine) Graph

func (e *Engine) Graph(moduleNames ...string) (map[string][]string, error)

Graph returns the dependency graph for the given modules.

If no modules are provided, the entire graph is returned. An error is returned if any dependencies are missing.

func (*Engine) Import

func (e *Engine) Import(ctx context.Context, moduleSch *schema.Module)

Import manually imports a schema for a module as if it were retrieved from the FTL controller.

func (*Engine) Modules

func (e *Engine) Modules() []string

Modules returns the names of all modules.

type Module

type Module struct {
	Config moduleconfig.ModuleConfig
	// paths to deploy, relative to ModuleConfig.DeployDir
	Deploy []string
	// contains filtered or unexported fields
}

Module represents an FTL module in the build engine

func (Module) CopyWithDependencies

func (m Module) CopyWithDependencies(dependencies []string) Module

func (Module) CopyWithDeploy

func (m Module) CopyWithDeploy(files []string) Module

func (Module) Dependencies

func (m Module) Dependencies(mode DependencyMode) []string

Dependencies returns the dependencies of the module Mode allows us to control how dependencies are returned.

When calling language plugins, use Raw mode to ensure plugins receive the same dependencies that were declared.

type Option

type Option func(o *Engine)

func BuildEnv

func BuildEnv(env []string) Option

func Parallelism

func Parallelism(n int) Option

func WithDevMode

func WithDevMode(updates chan dev.LocalEndpoint) Option

WithDevMode sets the engine to dev mode.

func WithStartTime

func WithStartTime(startTime time.Time) Option

WithStartTime sets the start time to report total startup time

type SchemaUpdatedEvent added in v0.462.0

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳