diff --git a/Cargo.toml b/Cargo.toml index c6bfa73..edf461b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ "crates/krata", + "crates/krataoci", "crates/krataguest", "crates/kratart", "crates/kratad", @@ -21,6 +22,7 @@ version = "0.0.1" [workspace.dependencies] anyhow = "1.0" arrayvec = "0.7.4" +async-compression = "0.4.6" async-stream = "0.3.5" async-trait = "0.1.77" backhand = "0.14.2" @@ -29,10 +31,8 @@ bytes = "1.5.0" cli-tables = "0.2.1" crossterm = "0.27.0" ctrlc = "3.4.4" -directories = "5.0.1" elf = "0.7.4" env_logger = "0.11.0" -errno = "0.3.0" etherparse = "0.14.2" flate2 = "1.0" futures = "0.3.30" @@ -40,7 +40,6 @@ ipnetwork = "0.20.0" libc = "0.2" log = "0.4.20" memchr = "2" -netlink-packet-route = "0.19.0" nix = "0.28.0" oci-spec = "0.6.4" once_cell = "1.19.0" @@ -53,28 +52,20 @@ rand = "0.8.5" redb = "1.5.0" rtnetlink = "0.14.1" serde_json = "1.0.113" -sha256 = "1.5.0" serde_yaml = "0.9" +sha256 = "1.5.0" signal-hook = "0.3.17" slice-copy = "0.3.0" smoltcp = "0.11.0" -termion = "3.0.0" thiserror = "1.0" -tokio-listener = "0.3.1" -tokio-native-tls = "0.3.1" tokio-tar = { git = "https://github.com/edera-dev/tokio-tar.git", branch = "edera" } tokio-tun = "0.11.2" tonic-build = "0.11.0" tower = "0.4.13" -trait-variant = "0.1.1" udp-stream = "0.0.11" url = "2.5.0" walkdir = "2" xz2 = "0.1" -zstd = "0.13.0" - -[workspace.dependencies.async-compression] -version = "0.4.6" [workspace.dependencies.clap] version = "4.4.18" @@ -89,14 +80,14 @@ version = "0.12.0" default-features = false features = ["rustls-tls"] -[workspace.dependencies.sys-mount] -version = "3.0.0" -default-features = false - [workspace.dependencies.serde] version = "1.0.196" features = ["derive"] +[workspace.dependencies.sys-mount] +version = "3.0.0" +default-features = false + [workspace.dependencies.tokio] version = "1.35.1" features = ["macros", "rt", "rt-multi-thread", "io-util"] diff --git a/crates/krata/Cargo.toml b/crates/krata/Cargo.toml index 5edf950..a9225ae 100644 --- a/crates/krata/Cargo.toml +++ b/crates/krata/Cargo.toml @@ -7,12 +7,10 @@ resolver = "2" [dependencies] anyhow = { workspace = true } libc = { workspace = true } -log = { workspace = true } once_cell = { workspace = true } prost = { workspace = true } prost-reflect = { workspace = true } serde = { workspace = true } -tokio = { workspace = true } tonic = { workspace = true } url = { workspace = true } diff --git a/crates/kratactl/Cargo.toml b/crates/kratactl/Cargo.toml index c426401..9ccca3d 100644 --- a/crates/kratactl/Cargo.toml +++ b/crates/kratactl/Cargo.toml @@ -15,15 +15,12 @@ env_logger = { workspace = true } krata = { path = "../krata" } log = { workspace = true } prost-reflect = { workspace = true, features = ["serde"] } -serde = { workspace = true } serde_json = { workspace = true } serde_yaml = { workspace = true } -signal-hook = { workspace = true } tokio = { workspace = true } tokio-stream = { workspace = true } tonic = { workspace = true } tower = { workspace = true } -url = { workspace = true } [lib] name = "kratactl" diff --git a/crates/kratad/Cargo.toml b/crates/kratad/Cargo.toml index fa778ee..681cd5e 100644 --- a/crates/kratad/Cargo.toml +++ b/crates/kratad/Cargo.toml @@ -16,8 +16,6 @@ kratart = { path = "../kratart" } log = { workspace = true } prost = { workspace = true } redb = { workspace = true } -serde = { workspace = true } -serde_yaml = { workspace = true } signal-hook = { workspace = true } tokio = { workspace = true } tokio-stream = { workspace = true } diff --git a/crates/krataguest/Cargo.toml b/crates/krataguest/Cargo.toml index 6604d9d..af8e1ab 100644 --- a/crates/krataguest/Cargo.toml +++ b/crates/krataguest/Cargo.toml @@ -20,7 +20,6 @@ serde = { workspace = true } serde_json = { workspace = true } sys-mount = { workspace = true } tokio = { workspace = true } -tokio-stream = { workspace = true } walkdir = { workspace = true } xenstore = { path = "../xen/xenstore" } diff --git a/crates/kratanet/Cargo.toml b/crates/kratanet/Cargo.toml index e21146e..e1f37f3 100644 --- a/crates/kratanet/Cargo.toml +++ b/crates/kratanet/Cargo.toml @@ -15,7 +15,6 @@ etherparse = { workspace = true } futures = { workspace = true } libc = { workspace = true } log = { workspace = true } -netlink-packet-route = { workspace = true } rtnetlink = { workspace = true } smoltcp = { workspace = true } tokio = { workspace = true } diff --git a/crates/krataoci/Cargo.toml b/crates/krataoci/Cargo.toml new file mode 100644 index 0000000..aa8d82b --- /dev/null +++ b/crates/krataoci/Cargo.toml @@ -0,0 +1,35 @@ +[package] +name = "krataoci" +version.workspace = true +edition = "2021" +resolver = "2" + +[dependencies] +anyhow = { workspace = true } +async-compression = { workspace = true, features = ["tokio", "gzip", "zstd"] } +async-trait = { workspace = true } +backhand = { workspace = true } +bytes = { workspace = true } +log = { workspace = true } +oci-spec = { workspace = true } +path-clean = { workspace = true } +reqwest = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +sha256 = { workspace = true } +tokio = { workspace = true } +tokio-stream = { workspace = true } +tokio-tar = { workspace = true } +url = { workspace = true } +uuid = { workspace = true } +walkdir = { workspace = true } + +[lib] +name = "krataoci" + +[dev-dependencies] +env_logger = { workspace = true } + +[[example]] +name = "krataoci-squashify" +path = "examples/squashify.rs" diff --git a/crates/krataoci/examples/squashify.rs b/crates/krataoci/examples/squashify.rs new file mode 100644 index 0000000..d735874 --- /dev/null +++ b/crates/krataoci/examples/squashify.rs @@ -0,0 +1,29 @@ +use std::{env::args, path::PathBuf}; + +use anyhow::Result; +use env_logger::Env; +use krataoci::{cache::ImageCache, compiler::ImageCompiler, name::ImageName}; +use tokio::fs; + +#[tokio::main] +async fn main() -> Result<()> { + env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); + + let image = ImageName::parse(&args().nth(1).unwrap())?; + let seed = args().nth(2).map(PathBuf::from); + + let cache_dir = PathBuf::from("krata-cache"); + if !cache_dir.exists() { + fs::create_dir(&cache_dir).await?; + } + + let cache = ImageCache::new(&cache_dir)?; + let compiler = ImageCompiler::new(&cache, seed)?; + let info = compiler.compile(&image).await?; + println!( + "generated squashfs of {} to {}", + image, + info.image_squashfs.to_string_lossy() + ); + Ok(()) +} diff --git a/crates/kratart/src/image/cache.rs b/crates/krataoci/src/cache.rs similarity index 100% rename from crates/kratart/src/image/cache.rs rename to crates/krataoci/src/cache.rs diff --git a/crates/kratart/src/image/compiler.rs b/crates/krataoci/src/compiler.rs similarity index 98% rename from crates/kratart/src/image/compiler.rs rename to crates/krataoci/src/compiler.rs index 05fb28f..efd0495 100644 --- a/crates/kratart/src/image/compiler.rs +++ b/crates/krataoci/src/compiler.rs @@ -1,6 +1,7 @@ -use crate::image::cache::ImageCache; -use crate::image::name::ImageName; -use crate::image::registry::OciRegistryPlatform; +use crate::cache::ImageCache; +use crate::fetch::{OciImageDownloader, OciImageLayer}; +use crate::name::ImageName; +use crate::registry::OciRegistryPlatform; use anyhow::{anyhow, Result}; use backhand::compression::Compressor; use backhand::{FilesystemCompressor, FilesystemWriter, NodeHeader}; @@ -18,8 +19,6 @@ use tokio_tar::{Archive, Entry}; use uuid::Uuid; use walkdir::WalkDir; -use crate::image::fetch::{OciImageDownloader, OciImageLayer}; - pub const IMAGE_SQUASHFS_VERSION: u64 = 2; pub struct ImageInfo { diff --git a/crates/kratart/src/image/fetch.rs b/crates/krataoci/src/fetch.rs similarity index 100% rename from crates/kratart/src/image/fetch.rs rename to crates/krataoci/src/fetch.rs index b91181d..ea93a1a 100644 --- a/crates/kratart/src/image/fetch.rs +++ b/crates/krataoci/src/fetch.rs @@ -1,3 +1,8 @@ +use super::{ + name::ImageName, + registry::{OciRegistryClient, OciRegistryPlatform}, +}; + use std::{ path::{Path, PathBuf}, pin::Pin, @@ -17,11 +22,6 @@ use tokio::{ use tokio_stream::StreamExt; use tokio_tar::Archive; -use super::{ - name::ImageName, - registry::{OciRegistryClient, OciRegistryPlatform}, -}; - pub struct OciImageDownloader { seed: Option, storage: PathBuf, diff --git a/crates/kratart/src/image/mod.rs b/crates/krataoci/src/lib.rs similarity index 100% rename from crates/kratart/src/image/mod.rs rename to crates/krataoci/src/lib.rs diff --git a/crates/kratart/src/image/name.rs b/crates/krataoci/src/name.rs similarity index 100% rename from crates/kratart/src/image/name.rs rename to crates/krataoci/src/name.rs diff --git a/crates/kratart/src/image/registry.rs b/crates/krataoci/src/registry.rs similarity index 100% rename from crates/kratart/src/image/registry.rs rename to crates/krataoci/src/registry.rs diff --git a/crates/kratart/Cargo.toml b/crates/kratart/Cargo.toml index f87e9ed..59750a3 100644 --- a/crates/kratart/Cargo.toml +++ b/crates/kratart/Cargo.toml @@ -7,29 +7,15 @@ resolver = "2" [dependencies] advmac = { path = "../vendor/advmac" } anyhow = { workspace = true } -async-compression = { workspace = true, features = ["tokio", "gzip", "zstd"] } -async-stream = { workspace = true } -async-trait = { workspace = true } backhand = { workspace = true } -bytes = { workspace = true } ipnetwork = { workspace = true } krata = { path = "../krata" } +krataoci = { path = "../krataoci" } log = { workspace = true } loopdev = { path = "../vendor/loopdev" } -nix = { workspace = true, features = ["process"] } -oci-spec = { workspace = true } -path-clean = { workspace = true } -reqwest = { workspace = true } -serde = { workspace = true } serde_json = { workspace = true } -sha256 = { workspace = true } tokio = { workspace = true } -tokio-stream = { workspace = true } -tokio-tar = { workspace = true } -tonic = { workspace = true, features = ["tls"] } -url = { workspace = true } uuid = { workspace = true } -walkdir = { workspace = true } xenclient = { path = "../xen/xenclient" } xenstore = { path = "../xen/xenstore" } diff --git a/crates/kratart/examples/squashify.rs b/crates/kratart/examples/squashify.rs index 6ff62f2..d735874 100644 --- a/crates/kratart/examples/squashify.rs +++ b/crates/kratart/examples/squashify.rs @@ -2,7 +2,7 @@ use std::{env::args, path::PathBuf}; use anyhow::Result; use env_logger::Env; -use kratart::image::{cache::ImageCache, compiler::ImageCompiler, name::ImageName}; +use krataoci::{cache::ImageCache, compiler::ImageCompiler, name::ImageName}; use tokio::fs; #[tokio::main] diff --git a/crates/kratart/src/cfgblk.rs b/crates/kratart/src/cfgblk.rs index 571f83c..044a16d 100644 --- a/crates/kratart/src/cfgblk.rs +++ b/crates/kratart/src/cfgblk.rs @@ -1,7 +1,7 @@ -use crate::image::compiler::ImageInfo; use anyhow::Result; use backhand::{FilesystemWriter, NodeHeader}; use krata::launchcfg::LaunchInfo; +use krataoci::compiler::ImageInfo; use log::trace; use std::fs; use std::fs::File; diff --git a/crates/kratart/src/launch/mod.rs b/crates/kratart/src/launch/mod.rs index d1dcc53..4be2640 100644 --- a/crates/kratart/src/launch/mod.rs +++ b/crates/kratart/src/launch/mod.rs @@ -13,12 +13,12 @@ use xenclient::{DomainConfig, DomainDisk, DomainNetworkInterface}; use xenstore::XsdInterface; use crate::cfgblk::ConfigBlock; -use crate::image::{ +use crate::RuntimeContext; +use krataoci::{ cache::ImageCache, compiler::{ImageCompiler, ImageInfo}, name::ImageName, }; -use crate::RuntimeContext; use super::{GuestInfo, GuestState}; diff --git a/crates/kratart/src/lib.rs b/crates/kratart/src/lib.rs index 9c1aab8..ba64aaf 100644 --- a/crates/kratart/src/lib.rs +++ b/crates/kratart/src/lib.rs @@ -20,14 +20,13 @@ use xenstore::{XsdClient, XsdInterface, XsdWatchHandle}; use self::{ autoloop::AutoLoop, console::XenConsole, - image::cache::ImageCache, launch::{GuestLaunchRequest, GuestLauncher}, }; +use krataoci::cache::ImageCache; pub mod autoloop; pub mod cfgblk; pub mod console; -pub mod image; pub mod launch; pub struct ContainerLoopInfo {