Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ DADK的文档托管在[DADK Docs](https://docs.dragonos.org.cn/p/dadk/)上。
## DADK有什么用?

- 管理DragonOS应用的编译与安装
- 管理DragonOS rootfs镜像(支持 ext4、Docker base 导入、base 变更自动重建)
- 对DragonOS内核进行profiling
- 管理DragonOS的镜像构建、虚拟机运行

Expand All @@ -28,6 +29,9 @@ DADK是一个Rust程序,您可以通过Cargo来安装DADK。
# 从GitHub安装最新版
cargo install --git https://github.com/DragonOS-Community/DADK.git

# 或安装指定版本(推荐与DragonOS分支匹配)
cargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v0.6.0 --locked


```

Expand Down
2 changes: 1 addition & 1 deletion dadk-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dadk-config"
version = "0.5.1"
version = "0.6.0"
edition = "2021"
authors = [
"longjin <longjin@DragonOS.org>",
Expand Down
10 changes: 10 additions & 0 deletions dadk-config/src/rootfs/fstype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use serde::{Deserialize, Deserializer};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FsType {
Fat32,
Ext4,
}

impl<'de> Deserialize<'de> for FsType {
Expand All @@ -15,6 +16,7 @@ impl<'de> Deserialize<'de> for FsType {
s.make_ascii_lowercase();
match s.as_str() {
"fat32" => Ok(FsType::Fat32),
"ext4" => Ok(FsType::Ext4),
_ => Err(serde::de::Error::custom("invalid fs type")),
}
}
Expand Down Expand Up @@ -46,6 +48,14 @@ mod tests {
assert_eq!(fs_type, FsType::Fat32);
}

#[test]
fn test_deserialize_ext4() {
let r = deserialize_fs_type("ext4");
assert_eq!(r.is_ok(), true);
let fs_type = r.unwrap();
assert_eq!(fs_type, FsType::Ext4);
}

#[test]
fn testdeserialize_random_string() {
assert!(deserialize_fs_type("abc123").is_err());
Expand Down
52 changes: 52 additions & 0 deletions dadk-config/src/rootfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct RootFSConfigFile {
pub metadata: RootFSMeta,
#[serde(default)]
pub partition: PartitionConfig,
#[serde(default)]
pub base: BaseConfig,
}

impl RootFSConfigFile {
Expand Down Expand Up @@ -43,6 +45,33 @@ pub struct RootFSMeta {
pub size: usize,
}

#[derive(Debug, Clone, Deserialize, Default, PartialEq, Eq)]
pub struct BaseConfig {
/// Docker image name, e.g. ubuntu:24.04
#[serde(default)]
pub image: String,
/// Pull policy: always | if-not-present | never
#[serde(default)]
pub pull_policy: PullPolicy,
}

impl BaseConfig {
pub fn has_base_image(&self) -> bool {
!self.image.trim().is_empty()
}
}

#[derive(Debug, Clone, Copy, Deserialize, Default, PartialEq, Eq)]
pub enum PullPolicy {
#[serde(rename = "always")]
Always,
#[default]
#[serde(rename = "if-not-present")]
IfNotPresent,
#[serde(rename = "never")]
Never,
}

#[cfg(test)]
mod tests {
use std::io::Write;
Expand All @@ -68,6 +97,7 @@ mod tests {

assert_eq!(config.metadata.fs_type, FsType::Fat32);
assert_eq!(config.metadata.size, 1024 * 1024 * 1024); // Assuming `deserialize_size` converts MB to Bytes
assert_eq!(config.base.has_base_image(), false);
}

#[test]
Expand All @@ -83,6 +113,7 @@ mod tests {

assert_eq!(config.metadata.fs_type, FsType::Fat32);
assert_eq!(config.metadata.size, 512 * 1024 * 1024); // Assuming `deserialize_size` converts MB to Bytes
assert_eq!(config.base.has_base_image(), false);
}
#[test]
fn test_load_from_invalid_fs_type() {
Expand All @@ -108,6 +139,7 @@ mod tests {

assert_eq!(config.metadata.fs_type, FsType::Fat32);
assert_eq!(config.metadata.size, 1048576); // Assuming `deserialize_size` converts MB to Bytes
assert_eq!(config.base.has_base_image(), false);
}
#[test]
fn test_load_from_valid_str_size_bytes_str() {
Expand All @@ -122,6 +154,26 @@ mod tests {

assert_eq!(config.metadata.fs_type, FsType::Fat32);
assert_eq!(config.metadata.size, 1048576); // Assuming `deserialize_size` converts MB to Bytes
assert_eq!(config.base.has_base_image(), false);
}

#[test]
fn test_load_with_base() {
let config_content = r#"
[metadata]
fs_type = "ext4"
size = "2G"

[base]
image = "ubuntu:24.04"
pull_policy = "if-not-present"
"#;
let config = RootFSConfigFile::load_from_str(config_content)
.expect("Failed to load config from str");
assert_eq!(config.metadata.fs_type, FsType::Ext4);
assert_eq!(config.base.has_base_image(), true);
assert_eq!(config.base.image, "ubuntu:24.04");
assert_eq!(config.base.pull_policy, PullPolicy::IfNotPresent);
}

#[test]
Expand Down
7 changes: 7 additions & 0 deletions dadk-config/templates/config/rootfs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ size = "1G"
#
# Note that the "none" option is incompatible with GRUB boot.
type = "none"

[base]
# Docker base image name (empty means no base image)
# image = "ubuntu:24.04"
image = ""
# Pull policy: always | if-not-present | never
pull_policy = "if-not-present"
4 changes: 2 additions & 2 deletions dadk-user/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dadk-user"
version = "0.5.1"
version = "0.6.0"
edition = "2021"
description = "DragonOS Application Development Kit - user prog build"
license = "GPL-2.0-only"
Expand All @@ -9,7 +9,7 @@ license = "GPL-2.0-only"
anyhow = { version = "1.0.100", features = ["std", "backtrace"] }
chrono = { version = "=0.4.35", features = ["serde"] }
clap = { version = "=4.5.20", features = ["derive"] }
dadk-config = { version = "0.5.1", path = "../dadk-config" }
dadk-config = { version = "0.6.0", path = "../dadk-config" }
derive_builder = "0.20.0"
lazy_static = "1.4.0"
log = "0.4.17"
Expand Down
6 changes: 3 additions & 3 deletions dadk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = [
"xuzihao <xuzihao@DragonOS.org>"
]

version = "0.5.1"
version = "0.6.0"
edition = "2021"
description = "DragonOS Application Development Kit\nDragonOS应用开发工具"
license = "GPL-2.0-only"
Expand All @@ -33,8 +33,8 @@ insiders = []
anyhow = { version = "1.0.100", features = ["std", "backtrace"] }
clap = { version = "4.5.20", features = ["derive"] }
crossbeam = "0.8.4"
dadk-config = { version = "0.5.0", path = "../dadk-config" }
dadk-user = { version = "0.5.0", path = "../dadk-user" }
dadk-config = { version = "0.6.0", path = "../dadk-config" }
dadk-user = { version = "0.6.0", path = "../dadk-user" }
derive_builder = "0.20.0"
env_logger = { workspace = true }
humantime = "2.1.0"
Expand Down
Loading
Loading