From 1e535f6993ef33458c3b5d9c93bf6fb5f471ed8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Lilleb=C3=B8=20Gundersen?= Date: Sun, 23 Jun 2024 20:51:54 +0200 Subject: [PATCH] Prune dependencies and fix lints --- .github/workflows/{deploy.yaml => release.yaml} | 0 Cargo.lock | 12 ++++-------- Cargo.toml | 16 ++++++++-------- Dockerfile | 2 +- development.md | 9 ++++++++- justfile | 5 +---- src/cli/models.rs | 2 +- src/client/builder.rs | 11 ++++++----- src/client/client.rs | 8 +++----- src/main.rs | 2 +- 10 files changed, 33 insertions(+), 34 deletions(-) rename .github/workflows/{deploy.yaml => release.yaml} (100%) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/release.yaml similarity index 100% rename from .github/workflows/deploy.yaml rename to .github/workflows/release.yaml diff --git a/Cargo.lock b/Cargo.lock index 5877187..6763bf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -163,9 +163,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.99" +version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" +checksum = "c891175c3fb232128f48de6590095e59198bbeb8620c310be349bfc3afd12c7b" [[package]] name = "cfg-if" @@ -181,10 +181,8 @@ checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", - "js-sys", "num-traits", "serde", - "wasm-bindgen", "windows-targets 0.52.5", ] @@ -556,7 +554,6 @@ dependencies = [ "instant", "number_prefix", "portable-atomic", - "tokio", "unicode-width", "vt100", ] @@ -599,9 +596,9 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" @@ -1056,7 +1053,6 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bd1c54ea06cfd2f6b63219704de0b9b4f72dcc2b8fdef820be6cd799780e91e" dependencies = [ - "serde", "zeroize", ] diff --git a/Cargo.toml b/Cargo.toml index 4267fe7..ea26d71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,20 +8,20 @@ publish = false [dependencies] clap = { version = "4.5.4", features = ["derive"]} -tracing = "0.1.40" -tracing-subscriber = { version = "0.3.18", features = ["env-filter", "registry", "fmt", "ansi"], default-features = false } -indicatif = { version = "0.17.8", features = ["tokio"] } +tracing = { version = "0.1.40", default-features = false } +tracing-subscriber = { version = "0.3.18", features = ["env-filter"], default-features = false } +indicatif = { version = "0.17.8", default-features = false } tracing-indicatif = "0.3.6" -chrono = { version="0.4.37" , features=["serde"]} -secrecy = { version = "0.8.0", features = ["serde"] } +chrono = { version="0.4.37" , features=["serde", "clock"], default-features = false} +secrecy = { version = "0.8.0" } -urlencoding = "2.1.3" -regex = "1.10.4" +urlencoding = { version="2.1.3" } +regex = { version = "1.10.4", default-features = false } humantime = "2.1.0" wildmatch = { version = "2.3.3" } serde = { version = "1.0.197", features = ["derive"], default-features = false } -tokio = { version = "1.36.0", features = ["rt", "rt-multi-thread", "macros"], default-features = false } # TODO: Slim down +tokio = { version = "1.36.0", features = ["rt-multi-thread", "macros"], default-features = false } reqwest = {version = "0.12.2", features = ["json", "rustls-tls"], default-features = false } lazy_static = { version = "1.4.0" , default-features = false} diff --git a/Dockerfile b/Dockerfile index caf48b0..57fd57f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN groupadd -g 10001 -r dockergrp && useradd -r -g dockergrp -u 10001 dockeruse # Download dependencies ala cargo chef WORKDIR /app -COPY libs/cli/Cargo.lock Cargo.toml ./ +COPY Cargo.lock Cargo.toml ./ RUN mkdir src && echo "fn main() { print!(\"Dummy main\"); }" > src/main.rs RUN cargo build --release RUN rm target/$TARGET_ENV/release/deps/container_retention_policy* && rm -r src diff --git a/development.md b/development.md index 63c74cf..901d414 100644 --- a/development.md +++ b/development.md @@ -2,7 +2,7 @@ To create a release we need to: -1. Manually trigger the [deploy](.github/workflows/deploy.yaml) workflow to build new images +1. Manually trigger the [deploy](.github/workflows/release.yaml) workflow to build new images 2. Update the image tag in the [action.yaml](action.yaml) 3. Push the change and create a GitHub release post for the repo @@ -29,3 +29,10 @@ where we do the same thing. To run the binary, see the `run` command in the [justfile](./justfile). If you run this, you'll need an `.env` file containing the token you want to pass. + +# Pruning unused features + +You might notice that there's a lot of disabled features in the [Cargo.toml](./Cargo.toml). +This might be redundant, but is a measure for trying to minimize the binary size. We've +used [cargo-unused-features](https://crates.io/crates/cargo-unused-features) and the +`unused-features analyze` command to aid in identifying redundant features. diff --git a/justfile b/justfile index 18c375e..ea31cb6 100644 --- a/justfile +++ b/justfile @@ -35,7 +35,7 @@ setup: cargo binstall cargo-llvm-cov --locked --no-confirm - cargo binstall cargo-fuzz --locked --no-confirm + cargo binstall cargo-unused-features --locked --no-confirm # pre-commit is used to run checks on-commit @pip install pre-commit && pre-commit install @@ -54,6 +54,3 @@ run: --timestamp-to-use "updated_at" \ --cut-off 1d \ --dry-run true - -fuzz target time="1800": - cargo +nightly fuzz run {{ target }} -- --max-total-time=time diff --git a/src/cli/models.rs b/src/cli/models.rs index 7f23c8f..36d72fd 100644 --- a/src/cli/models.rs +++ b/src/cli/models.rs @@ -19,7 +19,7 @@ pub enum TagSelection { /// Represents the different tokens the action can use to authenticate towards the GitHub API. /// -/// See https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/ +/// See /// for a list of existing token types. #[derive(Debug, Clone)] pub enum Token { diff --git a/src/client/builder.rs b/src/client/builder.rs index bbb0409..ea04711 100644 --- a/src/client/builder.rs +++ b/src/client/builder.rs @@ -28,6 +28,7 @@ pub struct PackagesClientBuilder { } impl PackagesClientBuilder { + #[must_use] pub fn new() -> Self { Self { headers: None, @@ -40,6 +41,7 @@ impl PackagesClientBuilder { } } + /// Add default HTTP headers for the client to use in all requests. pub fn set_http_headers(mut self, token: Token) -> Result { debug!("Constructing HTTP headers"); let auth_header_value = format!( @@ -59,6 +61,7 @@ impl PackagesClientBuilder { Ok(self) } + /// Attach a urls utility struct. pub fn generate_urls(mut self, account: &Account) -> Self { debug!("Constructing base urls"); self.urls = Some(Urls::from_account(account)); @@ -69,7 +72,7 @@ impl PackagesClientBuilder { /// enforced by the GitHub API. /// /// Read more about secondary rate limits here: - /// https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#about-secondary-rate-limits + /// /// /// The first limit we handle is the max 100 concurrent requests one. Since we don't send /// requests to multiple endpoints at the same time, we don't have to maintain a global @@ -86,16 +89,14 @@ impl PackagesClientBuilder { /// We also don't (and won't) handle the "Create too much content on GitHub in a short /// amount of time" rate limit, since we don't create any content. pub fn create_rate_limited_services(mut self) -> Self { - debug!("Creating rate-limited services"); - const MAX_CONCURRENCY: usize = 100; - const MAX_POINTS_PER_ENDPOINT_PER_MINUTE: u64 = 900; const GET_REQUEST_POINTS: u64 = 1; const DELETE_REQUEST_POINTS: u64 = 5; - const ONE_MINUTE: Duration = Duration::from_secs(60); + debug!("Creating rate-limited services"); + self.fetch_package_service = Some(Arc::new(Mutex::new( ServiceBuilder::new() .concurrency_limit(MAX_CONCURRENCY) diff --git a/src/client/client.rs b/src/client/client.rs index c5da31f..32a109a 100644 --- a/src/client/client.rs +++ b/src/client/client.rs @@ -43,9 +43,7 @@ impl PackagesClient { // however, list packages, so for this token type we are limited to fetching packages // individually, by name for image_name in image_names { - if image_name.contains('!') || image_name.contains('*') { - panic!("Restrictions in the Github API prevent us from listing packages when using a $GITHUB_TOKEN token. Because of this, filtering with '!' and '*' are not supported for this token type. Image name {image_name} is therefore not valid."); - } + assert!(!(image_name.contains('!') || image_name.contains('*')), "Restrictions in the Github API prevent us from listing packages when using a $GITHUB_TOKEN token. Because of this, filtering with '!' and '*' are not supported for this token type. Image name {image_name} is therefore not valid."); } self.fetch_individual_packages(image_names, counts) .await @@ -322,8 +320,8 @@ impl PackagesClient { } /// Delete a package version. - /// https://docs.github.com/en/rest/packages/packages?apiVersion=2022-11-28#delete-package-version-for-an-organization - /// https://docs.github.com/en/rest/packages/packages?apiVersion=2022-11-28#delete-a-package-version-for-the-authenticated-user + /// Docs for organizations: + /// Docs for users: pub async fn delete_package_version( &self, package_name: String, diff --git a/src/main.rs b/src/main.rs index 10d90c7..7e51a4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,7 +103,7 @@ async fn main() -> Result<()> { .expect("Failed to fetch rate limit"); let counts = Arc::new(Counts { rate_limit_reset, - remaining_requests: RwLock::new(30), // TODO: Revert + remaining_requests: RwLock::new(remaining), package_versions: RwLock::new(0), });