diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..1a6433a --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,40 @@ +name: CI + +on: + push: + branches: [master] + pull_request: + +jobs: + build: + runs-on: amd64 + steps: + - name: Install node + run: | + if command -v apk >/dev/null 2>&1; then + apk add --no-cache nodejs npm + elif command -v apt-get >/dev/null 2>&1; then + apt-get update && apt-get install -y nodejs npm + else + echo "No package manager found, assuming node present" + fi + - uses: actions/checkout@v4 + - name: Install Rust + run: | + if command -v rustc >/dev/null 2>&1 && command -v cargo >/dev/null 2>&1; then + echo "Rust already present" + elif command -v apk >/dev/null 2>&1; then + apk add --no-cache rust rustfmt rust-clippy + elif command -v apt-get >/dev/null 2>&1; then + apt-get update && apt-get install -y rustc cargo rustfmt rust-clippy + else + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable --component rustfmt,clippy + fi + - name: cargo check + run: cargo check + - name: cargo clippy + run: cargo clippy -- -D warnings + - name: cargo test + run: cargo test + - name: cargo fmt --check + run: cargo fmt -- --check diff --git a/Cargo.toml b/Cargo.toml index 92da267..9acdfe4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,15 @@ [package] name = "slim" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] -anyhow = "1" -clap = { version = "4", features = ["derive"] } -flate2 = "1" -walkdir = "2" -cpio = "0.2" -xdg = "2" +anyhow = "1.0.104" +clap = { version = "4.6.6", features = ["derive"] } +flate2 = "1.1.9" +walkdir = "2.5.0" +cpio = "0.4.1" +xdg = "3.0.0" [dev-dependencies] -tempfile = "3" +tempfile = "3.27.0" diff --git a/src/main.rs b/src/main.rs index eaac44e..20e09b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,9 +43,9 @@ fn main() -> Result<()> { } fn registry_dir(image: &str) -> PathBuf { - let base = xdg::BaseDirectories::with_prefix("slim-rs").unwrap(); - base.place_data_file(format!("registry/{}/vmlinuz", image)).unwrap(); - base.place_data_file(format!("registry/{}/initrd", image)).unwrap().parent().unwrap().to_path_buf() + let base = xdg::BaseDirectories::with_prefix("slim-rs"); + let initrd_path = base.place_data_file(format!("registry/{}/initrd", image)); + initrd_path.unwrap().parent().unwrap().to_path_buf() } fn build(image: &str) -> Result<()> { @@ -64,7 +64,9 @@ fn build(image: &str) -> Result<()> { // Step 2: find vmlinuz let vmlinuz_src = mount_path.join("vmlinuz"); if !vmlinuz_src.exists() { - anyhow::bail!("Image missing required /vmlinuz. Place kernel at /vmlinuz in Containerfile."); + anyhow::bail!( + "Image missing required /vmlinuz. Place kernel at /vmlinuz in Containerfile." + ); } // Step 3: prepare registry dir @@ -106,8 +108,12 @@ fn build(image: &str) -> Result<()> { // Gzip initrd let initrd_file = fs::File::open(&initrd_raw)?; - let mut initrd_writer = flate2::write::GzEncoder::new(File::create(&initrd_path)?, flate2::Compression::default()); - std::io::copy(&mut std::io::BufReader::new(initrd_file), &mut initrd_writer)?; + let mut initrd_writer = + flate2::write::GzEncoder::new(File::create(&initrd_path)?, flate2::Compression::default()); + std::io::copy( + &mut std::io::BufReader::new(initrd_file), + &mut initrd_writer, + )?; initrd_writer.finish()?; fs::remove_file(&initrd_raw)?; println!("Created initrd -> {}", initrd_path.display()); @@ -139,18 +145,27 @@ fn run(name: &str) -> Result<()> { ); // Launch with a 5-second timeout for quick smoke verification let status = Command::new("timeout") - .args(["5", "qemu-system-x86_64", - "-m", "256", - "-nographic", - "-kernel", vmlinuz_path.to_str().unwrap(), - "-initrd", initrd_path.to_str().unwrap(), - "-append", "console=ttyS0"]) + .args([ + "5", + "qemu-system-x86_64", + "-m", + "256", + "-nographic", + "-kernel", + vmlinuz_path.to_str().unwrap(), + "-initrd", + initrd_path.to_str().unwrap(), + "-append", + "console=ttyS0", + ]) .status() .context("Failed to launch qemu-system-x86_64")?; if status.success() { println!("QEMU exited cleanly (timeout or normal exit)."); } else { - println!("QEMU exited with non-zero status (timeout/expected for initrd boot without init)."); + println!( + "QEMU exited with non-zero status (timeout/expected for initrd boot without init)." + ); } Ok(()) }