Expand description
Container runtime backends and lifecycle manager for LightShuttle.
§Crate placement in the stack
lightshuttle-spec (domain types, ContainerSpec)
lightshuttle-manifest (YAML parsing, interpolation)
|
lightshuttle-runtime <-- this crate
|
lightshuttle-control (REST/HTTP control plane)
lightshuttle-otel (OpenTelemetry instrumentation)This crate depends on lightshuttle-spec (for ContainerSpec and
related domain types) and lightshuttle-manifest (for parsed manifests
fed into LifecyclePlan::from_manifest). It is consumed by
lightshuttle-control (the control plane) and lightshuttle-otel.
§Core abstractions
§ContainerRuntime trait
The narrow abstraction that hides every daemon-specific detail.
The lifecycle manager calls only the methods declared by this trait.
DockerRuntime is the first concrete implementation, backed by the
bollard crate. Tests and downstream crates use testkit::MockRuntime
as a drop-in replacement that requires no Docker daemon.
§LifecyclePlan
Computed from a parsed manifest by LifecyclePlan::from_manifest.
Performs a topological sort (Kahn’s algorithm) over the declared
depends_on graph so the manager can start independent branches in
parallel and block each resource until its dependencies are ready.
§LifecycleManager
Orchestrates the full up and down lifecycle:
- Starts every resource in topological order, independent branches in
parallel, via
tokio::spawn. - Waits for each container to pass its healthcheck (or to reach
ContainerStatus::Runningwhen no healthcheck is declared). - Publishes
LifecycleEventon a broadcast channel so the CLI, dashboard, and REST layer can observe progress. - On
SIGINTorSIGTERM(seeLifecycleManager::run_until_signal), stops all resources in reverse topological order, sendsSIGTERMand thenSIGKILLafter the configured grace window, and tears down the per-project bridge network.
§Quick start (no Docker daemon)
use std::collections::HashMap;
use std::time::Duration;
use lightshuttle_manifest::Manifest;
use lightshuttle_runtime::{LifecyclePlan, LifecycleManager, DockerRuntime};
let yaml = r#"
project:
name: myapp
resources:
db:
postgres:
version: "16"
"#;
let manifest = Manifest::parse(yaml)?;
let plan = LifecyclePlan::from_manifest(&manifest)?;
let runtime = DockerRuntime::connect()?;
let (manager, _events) = LifecycleManager::new(plan, runtime);
// Blocks until SIGINT/SIGTERM, then tears the stack down cleanly.
manager.run_until_signal(Duration::from_secs(30)).await?;See docs/spec/manifest-v0.md in the main repository for the full
manifest specification.
Modules§
- testkit
- In-memory
ContainerRuntimeand supporting helpers for tests.
Structs§
- Container
Id - Opaque identifier for a container managed by the runtime.
- Container
Spec - Self-contained description of a container to start, derived from a manifest resource declaration.
- Docker
Runtime - Docker container runtime backed by the
bollardcrate. - EnvReport
- Report over every
${env.*}reference found in a plan’s environment values and command arguments. - EnvVar
Report - One referenced variable together with its resolution status.
- Healthcheck
Spec - Healthcheck resolved from the manifest, with duration strings
already parsed into
std::time::Durationvalues. - Lifecycle
Manager - Coordinates the startup, supervision, and shutdown of every resource
declared in a
LifecyclePlan. - Lifecycle
Plan - Topologically sorted execution plan.
- LogChunk
- One chunk of streamed log output.
- Managed
Container - One entry returned by
DockerRuntime::list_managed. - Manager
Handle - Newtype adapter turning an
Arc<LifecycleManager<R>>into aLifecycleHandle. - Plan
Node - A single resource to manage, with its resolved
ContainerSpec, its exposed outputs and its explicit dependencies. - Port
Binding - Host-to-container port binding resolved from the manifest.
- Resolved
Resource - A
ContainerSpecbundled with theResourceOutputsthe resource exposes to its dependents at runtime. - Resource
View - Dashboard-friendly view of a single managed resource.
- Volume
Binding - Volume or bind-mount mapping resolved from the manifest.
Enums§
- Container
Status - Lifecycle status reported by the runtime when inspecting a container.
- EnvSource
- Where a resolved variable’s effective value comes from.
- EnvVar
Status - Resolution status of a single referenced environment variable.
- Image
Source - How the container image is obtained.
- Lifecycle
Error - Errors raised by the lifecycle layer.
- Lifecycle
Event - Event emitted by
crate::LifecycleManagerfor consumption by a CLI, dashboard or test harness. - Lifecycle
Handle Error - Errors returned by
LifecycleHandleoperations. - LogStream
- Which stream a log chunk came from.
- Node
Status - Lifecycle status of a single managed resource.
- Resource
Status - Coarse-grained resource status, derived from
NodeStatusand flattened for UI consumption. - Runtime
Error - Errors raised by a
crate::ContainerRuntimeimplementation. - Spec
Error - Errors raised while building a
crate::ContainerSpecfrom a manifest resource declaration. - Volume
Source - Origin of the content mounted into the container.
Constants§
- LABEL_
PROJECT - Docker label key set on every container managed by LightShuttle to carry the manifest project name.
- LABEL_
RESOURCE - Docker label key set on every container to carry the manifest resource name.
Traits§
- Container
Runtime - Container runtime abstraction.
- Lifecycle
Handle - Control-plane facing view of a running stack.
Functions§
- from_
resource - Resolve a manifest resource declaration into a
ResolvedResource.
Type Aliases§
- LogChunk
Stream - Boxed, pinned stream of
LogChunkitems for a single container. - Resource
Outputs - Key/value properties that a managed resource exposes to its dependents.
- Result
- Shorthand alias for
std::result::Result<T,RuntimeError>.