use std::path::PathBuf;
use std::sync::Arc;
use arcbox_api::{SetupState, SharedRuntime};
use arcbox_constants::container_network::ContainerNetwork;
use arcbox_constants::paths::{ArcboxProfile, HostLayout, HostMountLayout};
use tokio_util::sync::CancellationToken;
use crate::dns_service::DnsService;
use crate::startup::{ContainerNetworkLease, DaemonLock};
pub type SharedDaemonLock = Arc<std::sync::OnceLock<Arc<DaemonLock>>>;
pub type SharedContainerNetworkLease = Arc<std::sync::OnceLock<ContainerNetworkLease>>;
#[derive(Clone)]
pub struct StartupHandles {
pub shared_runtime: SharedRuntime,
pub early_runtime: SharedRuntime,
pub setup_state: Arc<SetupState>,
pub shutdown: CancellationToken,
pub daemon_lock: SharedDaemonLock,
pub container_network_lease: SharedContainerNetworkLease,
}
impl StartupHandles {
pub fn new(setup_state: Arc<SetupState>) -> Self {
Self {
shared_runtime: Arc::new(std::sync::OnceLock::new()),
early_runtime: Arc::new(std::sync::OnceLock::new()),
setup_state,
shutdown: CancellationToken::new(),
daemon_lock: Arc::new(std::sync::OnceLock::new()),
container_network_lease: Arc::new(std::sync::OnceLock::new()),
}
}
}
pub struct EarlyContext {
pub profile: ArcboxProfile,
pub layout: HostLayout,
pub shared_runtime: SharedRuntime,
pub early_runtime: SharedRuntime,
pub setup_state: Arc<SetupState>,
pub shutdown: CancellationToken,
pub daemon_lock_slot: SharedDaemonLock,
pub container_network_lease_slot: SharedContainerNetworkLease,
pub dns_domain: String,
pub dns_port: Option<u16>,
pub install_dns_resolver: bool,
pub kubernetes_port: Option<u16>,
pub kubernetes_context: String,
pub ssh_port: Option<u16>,
pub docker_integration: bool,
pub mount_nfs: bool,
pub host_mounts: HostMountLayout,
pub vm_args: VmArgs,
}
pub struct DaemonContext {
pub profile: ArcboxProfile,
pub layout: HostLayout,
pub daemon_lock: Arc<DaemonLock>,
pub shared_runtime: SharedRuntime,
pub early_runtime: SharedRuntime,
pub setup_state: Arc<SetupState>,
pub shutdown: CancellationToken,
pub container_network_lease_slot: SharedContainerNetworkLease,
pub dns_domain: String,
pub dns_port: Option<u16>,
pub install_dns_resolver: bool,
pub kubernetes_port: Option<u16>,
pub kubernetes_context: String,
pub ssh_port: Option<u16>,
pub docker_integration: bool,
pub mount_nfs: bool,
pub host_mounts: HostMountLayout,
pub vm_args: VmArgs,
}
pub struct VmArgs {
pub guest_docker_vsock_port: Option<u32>,
pub container_cidr: Option<ContainerNetwork>,
pub kernel: Option<PathBuf>,
pub no_linux_vm: bool,
}
pub struct ControlPlane {
pub grpc: tokio::task::JoinHandle<()>,
pub dns: DnsService,
}
pub struct ServiceHandles {
pub dns: tokio::task::JoinHandle<()>,
pub dns_port: u16,
pub docker: Option<tokio::task::JoinHandle<()>>,
pub grpc: tokio::task::JoinHandle<()>,
pub kubernetes_proxy: Option<tokio::task::JoinHandle<()>>,
pub ssh: Option<tokio::task::JoinHandle<()>>,
pub route_guard: Option<tokio::task::JoinHandle<()>>,
}