Skip to main content

arcbox_oci/
lib.rs

1//! # arcbox-oci
2//!
3//! OCI runtime specification support for `ArcBox`.
4//!
5//! This crate provides parsing and management of OCI (Open Container Initiative)
6//! runtime specification structures:
7//!
8//! - **Configuration**: Parse and validate `config.json` according to OCI runtime-spec
9//! - **Bundles**: Load and create OCI bundles (directory containing config + rootfs)
10//! - **State**: Container lifecycle state management
11//! - **Hooks**: Lifecycle hook definitions and validation
12//!
13//! ## Example
14//!
15//! ```no_run
16//! use arcbox_oci::{Bundle, BundleBuilder, Spec};
17//!
18//! // Load an existing bundle
19//! let bundle = Bundle::load("/path/to/bundle")?;
20//! println!("OCI version: {}", bundle.spec().oci_version);
21//!
22//! // Create a new bundle with builder
23//! let bundle = BundleBuilder::new()
24//!     .hostname("my-container")
25//!     .args(vec!["nginx".to_string(), "-g".to_string(), "daemon off;".to_string()])
26//!     .add_env("NGINX_HOST", "localhost")
27//!     .cwd("/")
28//!     .build("/path/to/new-bundle")?;
29//!
30//! // Parse config directly
31//! let spec = Spec::load("/path/to/config.json")?;
32//! # Ok::<(), arcbox_oci::OciError>(())
33//! ```
34//!
35//! ## OCI Runtime Specification
36//!
37//! This crate implements the [OCI Runtime Specification](https://github.com/opencontainers/runtime-spec)
38//! which defines:
39//!
40//! - Container configuration format (`config.json`)
41//! - Container lifecycle states (creating, created, running, stopped)
42//! - Lifecycle hooks (prestart, poststart, poststop, etc.)
43//! - Platform-specific settings (Linux namespaces, cgroups, etc.)
44//!
45//! ## Architecture
46//!
47//! ```text
48//! ┌─────────────────────────────────────────────────────────┐
49//! │                     arcbox-oci                          │
50//! │                                                         │
51//! │  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐     │
52//! │  │   config    │  │   bundle    │  │    state    │     │
53//! │  │             │  │             │  │             │     │
54//! │  │ - Spec      │  │ - Bundle    │  │ - State     │     │
55//! │  │ - Process   │  │ - Builder   │  │ - Status    │     │
56//! │  │ - Root      │  │ - utils     │  │ - Store     │     │
57//! │  │ - Mounts    │  │             │  │             │     │
58//! │  │ - Linux     │  │             │  │             │     │
59//! │  └─────────────┘  └─────────────┘  └─────────────┘     │
60//! │                                                         │
61//! │  ┌─────────────┐  ┌─────────────┐                       │
62//! │  │   hooks     │  │   error     │                       │
63//! │  │             │  │             │                       │
64//! │  │ - Hooks     │  │ - OciError  │                       │
65//! │  │ - Hook      │  │ - Result    │                       │
66//! │  │ - HookType  │  │             │                       │
67//! │  └─────────────┘  └─────────────┘                       │
68//! └─────────────────────────────────────────────────────────┘
69//! ```
70pub mod bundle;
71pub mod config;
72pub mod error;
73pub mod hooks;
74pub mod state;
75
76// Re-export main types for convenience.
77pub use bundle::{Bundle, BundleBuilder};
78pub use config::{
79    Capabilities, ConsoleSize, CpuResources, Device, IdMapping, Linux, MemoryResources, Mount,
80    Namespace, NamespaceType, OCI_VERSION, Process, Resources, Rlimit, Root, Seccomp, Spec, User,
81};
82pub use error::{OciError, Result};
83pub use hooks::{Hook, HookContext, HookResult, HookType, Hooks};
84pub use state::{ContainerState, State, StateStore, Status};