mvm_core/build_env.rs
1use anyhow::Result;
2
3use crate::instance::InstanceNet;
4use crate::pool::{BuildRevision, PoolSpec};
5use crate::tenant::{TenantConfig, TenantNet};
6
7/// Minimal shell execution abstraction used by dev-mode builds.
8///
9/// This trait provides just shell execution and logging — enough for
10/// `dev_build()` which runs `nix build` directly in the Lima VM.
11pub trait ShellEnvironment: Send + Sync {
12 /// Execute a shell script in the VM.
13 fn shell_exec(&self, script: &str) -> Result<()>;
14
15 /// Execute a shell script in the VM and capture stdout.
16 fn shell_exec_stdout(&self, script: &str) -> Result<String>;
17
18 /// Execute a shell script with visible output.
19 fn shell_exec_visible(&self, script: &str) -> Result<()>;
20
21 /// Log an informational message.
22 fn log_info(&self, msg: &str);
23
24 /// Log a success message.
25 fn log_success(&self, msg: &str);
26
27 /// Log a warning (optional; default no-op for test fakes).
28 fn log_warn(&self, _msg: &str) {
29 // default implementation: no-op
30 }
31}
32
33/// Full build environment for orchestrated pool builds.
34///
35/// Extends [`ShellEnvironment`] with tenant/pool/network operations needed
36/// by the pool build pipeline (ephemeral FC builder VMs, artifact recording).
37/// mvm-build depends on mvm-core only. At runtime, the orchestrator provides
38/// a concrete implementation that delegates to the runtime modules.
39pub trait BuildEnvironment: ShellEnvironment {
40 /// Load a pool spec from the filesystem.
41 fn load_pool_spec(&self, tenant_id: &str, pool_id: &str) -> Result<PoolSpec>;
42
43 /// Load a tenant config from the filesystem.
44 fn load_tenant_config(&self, tenant_id: &str) -> Result<TenantConfig>;
45
46 /// Ensure the tenant network bridge is up.
47 fn ensure_bridge(&self, net: &TenantNet) -> Result<()>;
48
49 /// Create and attach a TAP device for a VM.
50 fn setup_tap(&self, net: &InstanceNet, bridge_name: &str) -> Result<()>;
51
52 /// Remove a TAP device.
53 fn teardown_tap(&self, tap_dev: &str) -> Result<()>;
54
55 /// Record a build revision and update the current symlink.
56 fn record_revision(
57 &self,
58 tenant_id: &str,
59 pool_id: &str,
60 revision: &BuildRevision,
61 ) -> Result<()>;
62}