pub struct Instances<E> { /* private fields */ }Expand description
Runs the store’s instances on an engine. Each instance runs one revision in its own compose project, on its own slot and under its own host label, so two revisions of one environment run side by side:
- project
<workspace>_<env>_r<revision>: trestle names can’t contain_, so a project name parses back to its parts andreconciletells instance projects from any other; - host label
<workspace>-<env>-r<revision>(demo-dev-r2.localhost); - the slot the store leases the instance, host-wide.
The rendered tree lives in <state>/instances/<id>/ (owner-only) and is a cache,
re-rendered from the revision on every start. It holds no credential: they reach Compose as
process environment only (see MaterializedOutput::into_launch_env).
Implementations§
Source§impl<E: ComposeEngine> Instances<E>
impl<E: ComposeEngine> Instances<E>
Sourcepub fn new(store: Arc<Store>, engine: E, state_dir: impl Into<PathBuf>) -> Self
pub fn new(store: Arc<Store>, engine: E, state_dir: impl Into<PathBuf>) -> Self
Run store’s instances on engine, materializing them under state_dir
(<state_dir>/instances/<id>/). Secrets resolve with the env provider only until
with_providers says otherwise.
Sourcepub fn with_providers(self, providers: SecretProviders) -> Self
pub fn with_providers(self, providers: SecretProviders) -> Self
Resolve secrets with providers (and no others).
Sourcepub fn with_source(self, source: impl Source + 'static) -> Self
pub fn with_source(self, source: impl Source + 'static) -> Self
Make source available to instances that name it.
Sourcepub fn without_port_probe(self) -> Self
pub fn without_port_probe(self) -> Self
Don’t check host ports before starting (tests on a shared host, a fake engine).
Sourcepub fn with_wait_timeout(self, timeout: Duration) -> Self
pub fn with_wait_timeout(self, timeout: Duration) -> Self
Give up waiting for health after timeout on start.
Sourcepub fn dir(&self, id: &InstanceId) -> PathBuf
pub fn dir(&self, id: &InstanceId) -> PathBuf
Where the instance’s tree is materialized.
Sourcepub fn placement(
&self,
id: &InstanceId,
) -> Result<RuntimePlacement, InstanceError>
pub fn placement( &self, id: &InstanceId, ) -> Result<RuntimePlacement, InstanceError>
Where the instance runs: its compose project, host label, mesh and slot. Leases it a slot if it has none.
Sourcepub async fn effective_env(
&self,
id: &InstanceId,
) -> Result<EffectiveEnv, InstanceError>
pub async fn effective_env( &self, id: &InstanceId, ) -> Result<EffectiveEnv, InstanceError>
The instance’s environment, every variable with its provenance (see EffectiveEnv).
Sourcepub async fn materialize(
&self,
id: &InstanceId,
) -> Result<Materialized, InstanceError>
pub async fn materialize( &self, id: &InstanceId, ) -> Result<Materialized, InstanceError>
Render the instance into its directory, from scratch, and return what it launches with. The tree holds no credential.
Sourcepub async fn start(
&self,
id: &InstanceId,
) -> Result<Materialized, InstanceError>
pub async fn start( &self, id: &InstanceId, ) -> Result<Materialized, InstanceError>
Start the instance: lease it a slot (if it has none), check its host ports, render it
afresh and up it, waiting for health. The store records it as wanted running first,
so a crash mid-start is reconciled as running.
Sourcepub async fn stop(
&self,
id: &InstanceId,
volumes: bool,
) -> Result<(), InstanceError>
pub async fn stop( &self, id: &InstanceId, volumes: bool, ) -> Result<(), InstanceError>
Stop the instance (down, with its volumes when volumes), keeping its slot.
When a source fails (a Neon outage, say), the tree rendered at the last start is taken
down without its launch env: Compose then interpolates the missing variables as empty,
which down doesn’t mind, so a source never keeps an instance from stopping.
Sourcepub async fn remove(
&self,
id: &InstanceId,
volumes: bool,
) -> Result<(), InstanceError>
pub async fn remove( &self, id: &InstanceId, volumes: bool, ) -> Result<(), InstanceError>
Stop the instance if it runs, drop its tree, and delete it from the store (releasing its slot).
Sourcepub async fn health(
&self,
id: &InstanceId,
) -> Result<BTreeMap<String, Health>, InstanceError>
pub async fn health( &self, id: &InstanceId, ) -> Result<BTreeMap<String, Health>, InstanceError>
The health of each of the instance’s services (empty when it doesn’t run).
Sourcepub async fn events(
&self,
id: &InstanceId,
) -> Result<EngineStream<InstanceEvent>, InstanceError>
pub async fn events( &self, id: &InstanceId, ) -> Result<EngineStream<InstanceEvent>, InstanceError>
The instance’s events from now on: its containers’ lifecycle and health changes.
Sourcepub async fn reconcile(
&self,
opts: ReconcileOptions,
) -> Result<Reconciled, InstanceError>
pub async fn reconcile( &self, opts: ReconcileOptions, ) -> Result<Reconciled, InstanceError>
Match what Docker runs against the store, after a restart of the runtime: a running
instance project is adopted (its instance marked running), an instance wanted running
whose project is gone is marked stopped, and an instance-shaped project the store
doesn’t know is an orphan (taken down with ReconcileOptions::remove_orphans).