pub mod auth;
pub mod autoscale_controller;
pub mod bundle;
pub mod cdi;
pub mod cgroups_stats;
pub mod container_supervisor;
pub mod cron_scheduler;
pub mod dependency;
pub mod env;
pub mod error;
pub mod gpu_detector;
pub mod gpu_metrics;
pub mod gpu_sharing;
pub mod health;
pub mod init;
pub mod job;
pub mod metrics_providers;
pub mod netlink;
pub mod overlay_manager;
pub mod proxy_manager;
pub mod runtime;
pub mod runtimes;
pub mod service;
pub mod stabilization;
pub mod storage_manager;
#[cfg(target_os = "windows")]
pub mod windows;
pub use autoscale_controller::{has_adaptive_scaling, AutoscaleController};
pub use bundle::*;
pub use container_supervisor::{
ContainerSupervisor, SupervisedContainer, SupervisedState, SupervisorConfig, SupervisorEvent,
};
pub use cron_scheduler::{CronJobInfo, CronScheduler};
pub use dependency::{
DependencyConditionChecker, DependencyError, DependencyGraph, DependencyNode, DependencyWaiter,
WaitResult,
};
pub use env::{
resolve_env_value, resolve_env_vars, resolve_env_with_secrets, EnvResolutionError, ResolvedEnv,
};
pub use error::*;
pub use gpu_detector::{detect_gpus, GpuInfo};
pub use health::*;
pub use init::{BackoffConfig, InitOrchestrator};
pub use job::{
JobExecution, JobExecutionId, JobExecutor, JobExecutorConfig, JobStatus, JobTrigger,
};
pub use metrics_providers::{RuntimeStatsProvider, ServiceManagerContainerProvider};
pub use overlay_manager::{make_interface_name, OverlayManager};
pub use proxy_manager::{ProxyManager, ProxyManagerConfig};
pub use runtime::*;
pub use runtimes::{create_runtime_for_image, detect_image_artifact_type};
#[cfg(all(target_os = "linux", feature = "youki-runtime"))]
pub use runtimes::{YoukiConfig, YoukiRuntime};
#[cfg(feature = "docker")]
pub use runtimes::DockerRuntime;
#[cfg(feature = "wasm")]
pub use runtimes::{WasmConfig, WasmRuntime};
#[cfg(target_os = "macos")]
pub use runtimes::macos_sandbox::SandboxRuntime;
#[cfg(target_os = "macos")]
pub use runtimes::macos_vm::VmRuntime;
pub use service::*;
pub use stabilization::{
wait_for_stabilization, ServiceHealthSummary, StabilizationOutcome, StabilizationResult,
};
pub use storage_manager::{StorageError, StorageManager, VolumeInfo};
#[cfg(target_os = "macos")]
use std::path::PathBuf;
use std::sync::Arc;
#[cfg(target_os = "macos")]
#[derive(Debug, Clone)]
pub struct MacSandboxConfig {
pub data_dir: PathBuf,
pub log_dir: PathBuf,
pub gpu_access: bool,
}
#[cfg(target_os = "macos")]
impl Default for MacSandboxConfig {
fn default() -> Self {
let dirs = zlayer_paths::ZLayerDirs::system_default();
Self {
data_dir: dirs.data_dir().to_path_buf(),
log_dir: dirs.logs(),
gpu_access: true,
}
}
}
#[derive(Debug, Clone, Default)]
pub enum RuntimeConfig {
#[default]
Auto,
Mock,
#[cfg(all(target_os = "linux", feature = "youki-runtime"))]
Youki(YoukiConfig),
#[cfg(feature = "docker")]
Docker,
#[cfg(feature = "wasm")]
Wasm(WasmConfig),
#[cfg(target_os = "macos")]
MacSandbox(MacSandboxConfig),
#[cfg(target_os = "macos")]
MacVm,
#[cfg(target_os = "windows")]
#[deprecated(
note = "Wsl2 is deprecated in favor of Hcs (native Windows containers via the \
Host Compute Service). This variant is preserved for one release and \
currently aliases to Hcs with a default config at dispatch time."
)]
Wsl2,
#[cfg(target_os = "windows")]
Hcs(crate::runtimes::hcs::HcsConfig),
}
#[cfg(feature = "docker")]
pub async fn is_docker_available() -> bool {
use bollard::Docker;
match Docker::connect_with_local_defaults() {
Ok(docker) => match docker.ping().await {
Ok(_) => {
tracing::debug!("Docker daemon is available");
true
}
Err(e) => {
tracing::debug!(error = %e, "Docker daemon ping failed");
false
}
},
Err(e) => {
tracing::debug!(error = %e, "Failed to connect to Docker daemon");
false
}
}
}
#[cfg(not(feature = "docker"))]
#[allow(clippy::unused_async)]
pub async fn is_docker_available() -> bool {
false
}
#[cfg(feature = "wasm")]
#[must_use]
pub fn is_wasm_available() -> bool {
true
}
#[cfg(not(feature = "wasm"))]
#[must_use]
pub fn is_wasm_available() -> bool {
false
}
pub async fn create_runtime(
config: RuntimeConfig,
auth_ctx: Option<ContainerAuthContext>,
) -> Result<Arc<dyn Runtime + Send + Sync>> {
match config {
RuntimeConfig::Auto => create_auto_runtime(auth_ctx).await,
RuntimeConfig::Mock => Ok(Arc::new(MockRuntime::new())),
#[cfg(all(target_os = "linux", feature = "youki-runtime"))]
RuntimeConfig::Youki(youki_config) => {
let runtime = YoukiRuntime::new(youki_config, auth_ctx).await?;
Ok(Arc::new(runtime))
}
#[cfg(feature = "docker")]
RuntimeConfig::Docker => {
let runtime = DockerRuntime::new(auth_ctx).await?;
Ok(Arc::new(runtime))
}
#[cfg(feature = "wasm")]
RuntimeConfig::Wasm(wasm_config) => {
let runtime = WasmRuntime::new(wasm_config, auth_ctx).await?;
Ok(Arc::new(runtime))
}
#[cfg(target_os = "macos")]
RuntimeConfig::MacSandbox(config) => {
let primary: Arc<dyn Runtime> = Arc::new(runtimes::macos_sandbox::SandboxRuntime::new(
config,
auth_ctx.clone(),
)?);
let delegate: Option<Arc<dyn Runtime>> = match runtimes::macos_vm::VmRuntime::new(
auth_ctx,
) {
Ok(rt) => {
tracing::info!(
"macOS VM (libkrun) delegate available — Linux containers will execute in a micro-VM"
);
Some(Arc::new(rt))
}
Err(e) => {
tracing::warn!(
error = %e,
"macOS VM delegate unavailable; node will only run mac-native containers"
);
None
}
};
Ok(Arc::new(runtimes::composite::CompositeRuntime::new(
primary, delegate,
)))
}
#[cfg(target_os = "macos")]
RuntimeConfig::MacVm => Ok(Arc::new(runtimes::macos_vm::VmRuntime::new(auth_ctx)?)),
#[cfg(target_os = "windows")]
#[allow(deprecated)]
RuntimeConfig::Wsl2 => {
tracing::warn!(
"RuntimeConfig::Wsl2 is deprecated; treating as RuntimeConfig::Hcs with default config"
);
Box::pin(create_runtime(
RuntimeConfig::Hcs(crate::runtimes::hcs::HcsConfig::default()),
auth_ctx,
))
.await
}
#[cfg(target_os = "windows")]
RuntimeConfig::Hcs(hcs_config) => {
let primary: Arc<dyn Runtime> =
Arc::new(crate::runtimes::hcs::HcsRuntime::new(hcs_config).await?);
#[cfg(feature = "wsl")]
let delegate: Option<Arc<dyn Runtime>> =
match runtimes::wsl2_delegate::Wsl2DelegateRuntime::try_new().await {
Ok(Some(rt)) => {
tracing::info!(
"WSL2 delegate runtime available — Linux containers will execute inside the zlayer distro"
);
Some(Arc::new(rt))
}
Ok(None) => {
tracing::info!(
"WSL2 not available; node will only run Windows-image containers"
);
None
}
Err(e) => {
tracing::warn!(
error = %e,
"WSL2 delegate setup failed; node will only run Windows-image containers"
);
None
}
};
#[cfg(not(feature = "wsl"))]
let delegate: Option<Arc<dyn Runtime>> = None;
Ok(Arc::new(runtimes::composite::CompositeRuntime::new(
primary, delegate,
)))
}
}
}
#[cfg_attr(
not(all(target_os = "linux", feature = "youki-runtime")),
allow(clippy::unused_async)
)]
#[cfg_attr(
not(any(
all(target_os = "linux", feature = "youki-runtime"),
target_os = "macos",
feature = "docker"
)),
allow(unused_variables)
)]
#[allow(clippy::too_many_lines)]
async fn create_auto_runtime(
auth_ctx: Option<ContainerAuthContext>,
) -> Result<Arc<dyn Runtime + Send + Sync>> {
tracing::info!("Auto-selecting container runtime");
#[cfg(all(target_os = "linux", feature = "youki-runtime"))]
{
match YoukiRuntime::new(YoukiConfig::default(), auth_ctx.clone()).await {
Ok(runtime) => {
tracing::info!("Using bundled libcontainer runtime (Linux-native, no daemon)");
return Ok(Arc::new(runtime));
}
Err(e) => {
tracing::warn!(error = %e, "Failed to initialize libcontainer runtime, trying Docker");
}
}
}
#[cfg(target_os = "macos")]
{
let primary: Option<Arc<dyn Runtime>> = match runtimes::macos_sandbox::SandboxRuntime::new(
MacSandboxConfig::default(),
auth_ctx.clone(),
) {
Ok(rt) => Some(Arc::new(rt)),
Err(e) => {
tracing::warn!("macOS sandbox runtime unavailable: {e}");
None
}
};
let delegate: Option<Arc<dyn Runtime>> = match runtimes::macos_vm::VmRuntime::new(
auth_ctx.clone(),
) {
Ok(rt) => {
tracing::info!(
"macOS VM (libkrun) delegate available — Linux containers will execute in a micro-VM"
);
Some(Arc::new(rt))
}
Err(e) => {
tracing::warn!("macOS VM runtime (libkrun) unavailable: {e}");
None
}
};
if let Some(p) = primary {
return Ok(Arc::new(runtimes::composite::CompositeRuntime::new(
p, delegate,
)));
}
if let Some(d) = delegate {
return Ok(d);
}
}
#[cfg(target_os = "windows")]
{
let primary: Option<Arc<dyn Runtime>> =
match crate::runtimes::hcs::HcsRuntime::new(crate::runtimes::hcs::HcsConfig::default())
.await
{
Ok(rt) => {
tracing::info!(
"Using native Windows HCS runtime (no Docker Desktop / WSL2 required)"
);
Some(Arc::new(rt))
}
Err(e) => {
tracing::warn!(error = %e, "HCS runtime unavailable, falling back to Docker");
None
}
};
#[cfg(feature = "wsl")]
let delegate: Option<Arc<dyn Runtime>> =
match runtimes::wsl2_delegate::Wsl2DelegateRuntime::try_new().await {
Ok(Some(rt)) => {
tracing::info!(
"WSL2 delegate runtime available — Linux containers will execute inside the zlayer distro"
);
Some(Arc::new(rt))
}
Ok(None) => {
tracing::info!(
"WSL2 not available; node will only run Windows-image containers"
);
None
}
Err(e) => {
tracing::warn!(
error = %e,
"WSL2 delegate setup failed; node will only run Windows-image containers"
);
None
}
};
#[cfg(not(feature = "wsl"))]
let delegate: Option<Arc<dyn Runtime>> = None;
if let Some(p) = primary {
return Ok(Arc::new(runtimes::composite::CompositeRuntime::new(
p, delegate,
)));
}
}
#[cfg(feature = "docker")]
{
if is_docker_available().await {
tracing::info!("Selected Docker runtime");
let runtime = DockerRuntime::new(auth_ctx).await?;
return Ok(Arc::new(runtime));
}
tracing::debug!("Docker daemon not available");
}
#[cfg(all(target_os = "linux", feature = "docker"))]
{
Err(AgentError::Configuration(
"Bundled libcontainer runtime failed to initialize and Docker daemon is not available."
.to_string(),
))
}
#[cfg(all(target_os = "linux", not(feature = "docker")))]
{
Err(AgentError::Configuration(
"Bundled libcontainer runtime failed to initialize. Enable the 'docker' feature for an alternative."
.to_string(),
))
}
#[cfg(all(not(target_os = "linux"), feature = "docker"))]
{
Err(AgentError::Configuration(
"No container runtime available. Start the Docker daemon.".to_string(),
))
}
#[cfg(all(not(target_os = "linux"), not(feature = "docker")))]
{
Err(AgentError::Configuration(
"No container runtime available. Enable the 'docker' feature and start the Docker daemon.".to_string(),
))
}
}