From 821f71100e7a05f446bd364e0cef7c2509e45ee5 Mon Sep 17 00:00:00 2001 From: eXhumer Date: Fri, 4 Oct 2024 18:27:54 -0600 Subject: [PATCH 1/5] feat: add support for custom compression options Signed-off-by: eXhumer --- .github/workflows/rust.yml | 8 ++++---- Cargo.lock | 28 +++++++++++++++++++++++++++- Cargo.toml | 2 +- src/cli/mod.rs | 18 ++++++++++++++++++ src/cli/plugin/build.rs | 30 +++++++++++++++++++++++++----- src/cli/plugin/deploy.rs | 5 +++++ src/cli/plugin/mod.rs | 10 +++++++++- 7 files changed, 89 insertions(+), 12 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b3d9bff..c773711 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -40,7 +40,7 @@ jobs: outputs: version: ${{ steps.version.outputs.version }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Rust cache for ${{ matrix.platform.release_for }} uses: Swatinem/rust-cache@v2 @@ -58,7 +58,7 @@ jobs: strip: true - name: Upload binary - uses: actions/upload-artifact@v3.1.2 + uses: actions/upload-artifact@v4 with: name: ${{ matrix.platform.name }} path: target/${{ matrix.platform.target }}/release/decky @@ -70,7 +70,7 @@ jobs: contents: write if: github.event_name != 'pull_request' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Grab version id: version @@ -79,7 +79,7 @@ jobs: echo "Version code is $version" echo "version=$version" >> $GITHUB_OUTPUT - - uses: actions/download-artifact@v4.1.7 + - uses: actions/download-artifact@v4 with: path: artifacts diff --git a/Cargo.lock b/Cargo.lock index bf46d3e..172daf3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + [[package]] name = "aho-corasick" version = "1.0.4" @@ -123,7 +129,7 @@ dependencies = [ "cc", "cfg-if", "libc", - "miniz_oxide", + "miniz_oxide 0.7.1", "object", "rustc-demangle", ] @@ -399,6 +405,16 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +[[package]] +name = "flate2" +version = "1.0.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" +dependencies = [ + "crc32fast", + "miniz_oxide 0.8.0", +] + [[package]] name = "flexi_logger" version = "0.24.2" @@ -833,6 +849,15 @@ dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + [[package]] name = "mio" version = "0.8.11" @@ -1846,4 +1871,5 @@ dependencies = [ "byteorder", "crc32fast", "crossbeam-utils", + "flate2", ] diff --git a/Cargo.toml b/Cargo.toml index 589ae2e..a000ad9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,6 @@ sha2 = "0.10.7" tokio = { version = "1.24.2", features = ["full"] } users = "0.11.0" walkdir = "2.3.2" -zip = { version = "0.6.3", default-features = false } +zip = { version = "0.6.3", default-features = false, features = ["deflate"] } which = "4.4.0" dirs = "5" diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 7b5f3a0..8eed8e4 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -27,6 +27,12 @@ impl ContainerEngine { } +#[derive(clap::ValueEnum, Clone)] +pub enum CompressMethod { + Deflate, + Store, +} + #[derive(Subcommand)] pub enum Command { Plugin(PluginCLI), @@ -70,6 +76,12 @@ pub enum PluginCommand { #[arg(short = 'e', long = "engine", default_value = "docker")] container_engine: ContainerEngine, + + #[arg(short = 'm', long, default_value = "deflate")] + compression_method: CompressMethod, + + #[arg(short = 'l', long)] + compression_level: Option, }, New, Deploy { @@ -94,6 +106,12 @@ pub enum PluginCommand { #[arg(short = 'e', long = "engine", default_value = "docker")] container_engine: ContainerEngine, + #[arg(short = 'm', long, default_value = "deflate")] + compression_method: CompressMethod, + + #[arg(short = 'l', long)] + compression_level: Option, + #[arg(short = 'S', long, default_value = "true")] follow_symlinks: bool, diff --git a/src/cli/plugin/build.rs b/src/cli/plugin/build.rs index 313ef4a..9f4272e 100644 --- a/src/cli/plugin/build.rs +++ b/src/cli/plugin/build.rs @@ -14,10 +14,10 @@ use std::{ path::{Path, PathBuf}, }; use walkdir::WalkDir; -use zip::{write::FileOptions, ZipWriter}; +use zip::{write::FileOptions, CompressionMethod, ZipWriter}; use crate::{ - cli::{FilenameSource, ContainerEngine}, + cli::{CompressMethod, ContainerEngine, FilenameSource}, container_engine, plugin::{CustomBackend, Plugin}, }; @@ -35,6 +35,8 @@ pub struct Builder { pub follow_symlinks: bool, pub output_filename_source: FilenameSource, pub container_engine: ContainerEngine, + pub compression_method: CompressMethod, + pub compression_level: Option, } impl Builder { @@ -216,7 +218,7 @@ impl Builder { filename: &str, path: PathBuf, zip: &mut ZipWriter, - perms: FileOptions, + opts: FileOptions, ) -> Result<()> { let name = path .strip_prefix(&self.tmp_build_root) @@ -233,11 +235,25 @@ impl Builder { if path.is_file() { let bytes = std::fs::read(&path).unwrap(); - zip.start_file(name.to_str().unwrap(), perms)?; + let method = match self.compression_method { + CompressMethod::Deflate => CompressionMethod::Deflated, + CompressMethod::Store => CompressionMethod::Stored, + }; + + let mut opts = opts.compression_method(method); + + if method == CompressionMethod::Deflated { + opts = match self.compression_level { + Some(level) => opts.compression_level(Some(level)), + None => opts.compression_level(Some(9)) + } + } + + zip.start_file(name.to_str().unwrap(), opts)?; zip.write_all(&bytes)?; } else if !name.as_os_str().is_empty() { - zip.add_directory(name.to_str().unwrap(), perms)?; + zip.add_directory(name.to_str().unwrap(), opts)?; } Ok(()) @@ -395,6 +411,8 @@ impl Builder { follow_symlinks: bool, output_filename_source: FilenameSource, container_engine: ContainerEngine, + compression_method: CompressMethod, + compression_level: Option, ) -> Result { if !output_root.exists() { std::fs::create_dir(&output_root)?; @@ -421,6 +439,8 @@ impl Builder { follow_symlinks, output_filename_source, container_engine, + compression_method, + compression_level, }) } } diff --git a/src/cli/plugin/deploy.rs b/src/cli/plugin/deploy.rs index 7da43fc..5b12154 100644 --- a/src/cli/plugin/deploy.rs +++ b/src/cli/plugin/deploy.rs @@ -7,6 +7,7 @@ use log::info; use rand::distributions::{Alphanumeric, DistString}; use crate::cli::plugin::build::Builder; +use crate::cli::CompressMethod; use crate::plugin::DeckFile; use crate::{cli::FilenameSource, cli::ContainerEngine, plugin::Plugin}; @@ -231,6 +232,8 @@ impl Deployer { follow_symlinks: bool, output_filename_source: FilenameSource, container_engine: ContainerEngine, + compression_method: CompressMethod, + compression_level: Option, deck_ip: Option, deck_port: Option, deck_pass: Option, @@ -248,6 +251,8 @@ impl Deployer { follow_symlinks, output_filename_source, container_engine, + compression_method, + compression_level, ) .expect("Could not create builder"); diff --git a/src/cli/plugin/mod.rs b/src/cli/plugin/mod.rs index 287929c..2de7ea5 100644 --- a/src/cli/plugin/mod.rs +++ b/src/cli/plugin/mod.rs @@ -14,7 +14,9 @@ pub async fn parse(args: &PluginCLI) -> Result<()> { build_with_dev, follow_symlinks, output_filename_source, - container_engine + container_engine, + compression_method, + compression_level, } => { build::Builder::new( plugin_path.into(), @@ -25,6 +27,8 @@ pub async fn parse(args: &PluginCLI) -> Result<()> { follow_symlinks.clone(), output_filename_source.clone(), container_engine.clone(), + compression_method.clone(), + compression_level.clone(), )? .run() .await @@ -44,6 +48,8 @@ pub async fn parse(args: &PluginCLI) -> Result<()> { deck_pass, deck_key, deck_dir, + compression_method, + compression_level, } => { deploy::Deployer::new( plugin_path.into(), @@ -54,6 +60,8 @@ pub async fn parse(args: &PluginCLI) -> Result<()> { follow_symlinks.clone(), output_filename_source.clone(), container_engine.clone(), + compression_method.clone(), + compression_level.clone(), deck_ip.clone(), deck_port.clone(), deck_pass.clone(), From cc83f05de3addb44706d6dfe9e0253906304648d Mon Sep 17 00:00:00 2001 From: eXhumer Date: Fri, 4 Oct 2024 20:39:12 -0600 Subject: [PATCH 2/5] replace `users` crate with `uzers` Signed-off-by: eXhumer --- Cargo.lock | 20 ++++++++++---------- Cargo.toml | 2 +- src/container_engine.rs | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 172daf3..219be9e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -331,7 +331,7 @@ dependencies = [ "serde_json", "sha2", "tokio", - "users", + "uzers", "walkdir", "which", "zip", @@ -1534,21 +1534,21 @@ dependencies = [ ] [[package]] -name = "users" -version = "0.11.0" +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "uzers" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032" +checksum = "4df81ff504e7d82ad53e95ed1ad5b72103c11253f39238bcc0235b90768a97dd" dependencies = [ "libc", "log", ] -[[package]] -name = "utf8parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" - [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index a000ad9..c6f196b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ serde = { version = "1.0.152", features = ["derive"] } serde_json = "1.0.91" sha2 = "0.10.7" tokio = { version = "1.24.2", features = ["full"] } -users = "0.11.0" +uzers = "0.12.1" walkdir = "2.3.2" zip = { version = "0.6.3", default-features = false, features = ["deflate"] } which = "4.4.0" diff --git a/src/container_engine.rs b/src/container_engine.rs index db0e2ac..99820b4 100644 --- a/src/container_engine.rs +++ b/src/container_engine.rs @@ -6,7 +6,7 @@ use tokio::{ io::{AsyncBufReadExt, BufReader}, process::Command, }; -use users::{get_effective_gid, get_effective_uid}; +use uzers::{get_effective_gid, get_effective_uid}; use which::which; async fn run_command(cmd: &mut Command) -> Result<()> { From 7c279e02786dd311cacd9d60cec02a68bbcc5cd6 Mon Sep 17 00:00:00 2001 From: eXhumer Date: Fri, 4 Oct 2024 20:45:41 -0600 Subject: [PATCH 3/5] upgrade `flexi_logger` * see https://rustsec.org/advisories/RUSTSEC-2021-0145 Signed-off-by: eXhumer --- Cargo.lock | 43 +++++++------------------------------------ Cargo.toml | 2 +- 2 files changed, 8 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 219be9e..c6abc46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,17 +102,6 @@ version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -417,14 +406,12 @@ dependencies = [ [[package]] name = "flexi_logger" -version = "0.24.2" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade8e86c48285f138a4d6ca15a2912e39bd6c74d62db42da4f1985f651a0b057" +checksum = "4aecae2cdf1c33e1c83896a37cc155e207a6358c915795932c338126e8eb3392" dependencies = [ - "atty", "chrono", "glob", - "lazy_static", "log", "nu-ansi-term", "regex", @@ -614,15 +601,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.2" @@ -755,7 +733,7 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi", "rustix", "windows-sys 0.48.0", ] @@ -889,12 +867,11 @@ dependencies = [ [[package]] name = "nu-ansi-term" -version = "0.46.0" +version = "0.50.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +checksum = "d4a28e057d01f97e61255210fcff094d74ed0466038633e95017f5beb68e4399" dependencies = [ - "overload", - "winapi", + "windows-sys 0.52.0", ] [[package]] @@ -912,7 +889,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.2", + "hermit-abi", "libc", ] @@ -981,12 +958,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - [[package]] name = "parking_lot" version = "0.12.1" diff --git a/Cargo.toml b/Cargo.toml index c6f196b..aaddee1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" anyhow = "1.0.68" boolinator = "2.4.0" clap = { version = "4.1.4", features = ["derive"] } -flexi_logger = "0.24" +flexi_logger = "0.29" futures = "0.3.25" glob = "0.3.1" itertools = "0.10.5" From 453c61073e5f29ae6be7cb1c08089a731f536ee6 Mon Sep 17 00:00:00 2001 From: eXhumer Date: Sat, 5 Oct 2024 10:27:20 -0600 Subject: [PATCH 4/5] refactor: only use deck file while deploying Signed-off-by: eXhumer --- src/cli/plugin/deploy.rs | 47 +++++++++++++++++++++++++++++++++++++--- src/plugin.rs | 40 ---------------------------------- 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/src/cli/plugin/deploy.rs b/src/cli/plugin/deploy.rs index 5b12154..2c96575 100644 --- a/src/cli/plugin/deploy.rs +++ b/src/cli/plugin/deploy.rs @@ -2,15 +2,26 @@ use dirs::home_dir; use std::path::PathBuf; use std::process::{Command, Stdio}; -use anyhow::Result; +use anyhow::{anyhow, Result}; +use boolinator::Boolinator; +use serde::{Deserialize, Serialize}; + use log::info; use rand::distributions::{Alphanumeric, DistString}; use crate::cli::plugin::build::Builder; use crate::cli::CompressMethod; -use crate::plugin::DeckFile; use crate::{cli::FilenameSource, cli::ContainerEngine, plugin::Plugin}; +#[derive(Serialize, Deserialize, Clone)] +pub struct DeckFile { + pub deckip: String, + pub deckport: String, + pub deckpass: String, + pub deckkey: String, + pub deckdir: String, +} + #[derive(Clone)] pub struct Deployer { builder: Builder, @@ -164,7 +175,7 @@ impl Deployer { deckdir: self.deck_dir.clone().unwrap(), }; } else { - deck = self.plugin.deck.clone(); + deck = self.find_deckfile()?; if self.deck_ip.is_some() { deck.deckip = self.deck_ip.clone().unwrap(); } @@ -223,6 +234,36 @@ impl Deployer { Ok(()) } + fn find_deckfile(&mut self) -> Result { + info!("Looking for deck.json..."); + let deckfile_location = self.plugin_root.join("deck.json"); + + self.plugin_root + .join("deck.json") + .exists() + .as_result( + deckfile_location.clone(), + anyhow!("Could not find deck.json"), + ) + .and_then(|deckfile| std::fs::read_to_string(deckfile).map_err(Into::into)) + .and_then(|str| serde_json::from_str::(&str).map_err(Into::into)) + .or_else(|_| { + let deck = DeckFile { + deckip: "0.0.0.0".to_string(), + deckport: "22".to_string(), + deckpass: "ssap".to_string(), + deckkey: "-i $HOME/.ssh/id_rsa".to_string(), + deckdir: "/home/deck".to_string(), + }; + std::fs::write( + deckfile_location, + serde_json::to_string_pretty(&deck).unwrap(), + ) + .unwrap(); + Ok(deck) + }) + } + pub fn new( plugin_root: PathBuf, output_root: PathBuf, diff --git a/src/plugin.rs b/src/plugin.rs index 6c358fb..19472f3 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -13,7 +13,6 @@ pub enum CustomBackend { #[derive(Clone)] pub struct Plugin { pub meta: PluginFile, - pub deck: DeckFile, #[allow(dead_code)] pub root: PathBuf, pub custom_backend: CustomBackend, @@ -28,14 +27,6 @@ pub struct PluginFile { pub flags: Vec, } -#[derive(Serialize, Deserialize, Clone)] -pub struct DeckFile { - pub deckip: String, - pub deckport: String, - pub deckpass: String, - pub deckkey: String, - pub deckdir: String, -} impl Plugin { fn find_custom_backend(plugin_root: &Path) -> Result { @@ -61,36 +52,6 @@ impl Plugin { .as_result((), anyhow!("Could not find package.json")) } - fn find_deckfile(plugin_root: &Path) -> Result { - info!("Looking for deck.json..."); - let deckfile_location = plugin_root.join("deck.json"); - - plugin_root - .join("deck.json") - .exists() - .as_result( - deckfile_location.clone(), - anyhow!("Could not find deck.json"), - ) - .and_then(|deckfile| std::fs::read_to_string(deckfile).map_err(Into::into)) - .and_then(|str| serde_json::from_str::(&str).map_err(Into::into)) - .or_else(|_| { - let deck = DeckFile { - deckip: "0.0.0.0".to_string(), - deckport: "22".to_string(), - deckpass: "ssap".to_string(), - deckkey: "-i $HOME/.ssh/id_rsa".to_string(), - deckdir: "/home/deck".to_string(), - }; - std::fs::write( - deckfile_location, - serde_json::to_string_pretty(&deck).unwrap(), - ) - .unwrap(); - Ok(deck) - }) - } - fn find_pluginfile(plugin_root: &Path) -> Result { info!("Looking for plugin.json..."); let pluginfile_location = plugin_root.join("plugin.json"); @@ -108,7 +69,6 @@ impl Plugin { Ok(Self { meta: Plugin::find_pluginfile(&plugin_root)?, - deck: Plugin::find_deckfile(&plugin_root)?, custom_backend: Plugin::find_custom_backend(&plugin_root)?, root: plugin_root.clone(), }) From 38c7d154ce2f29ea637546054af31f8ee362d85a Mon Sep 17 00:00:00 2001 From: eXhumer Date: Sat, 5 Oct 2024 10:30:20 -0600 Subject: [PATCH 5/5] chore: bump version Signed-off-by: eXhumer --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6abc46..49daafc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -303,7 +303,7 @@ dependencies = [ [[package]] name = "decky" -version = "0.0.3" +version = "0.0.5" dependencies = [ "anyhow", "boolinator", diff --git a/Cargo.toml b/Cargo.toml index aaddee1..a5b748a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "decky" -version = "0.0.3" +version = "0.0.5" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html