Skip to content

Commit

Permalink
Prune dependencies and fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
sondrelg committed Jun 23, 2024
1 parent a777400 commit 1e535f6
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 34 deletions.
File renamed without changes.
12 changes: 4 additions & 8 deletions Cargo.lock

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

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
5 changes: 1 addition & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/cli/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/>
/// for a list of existing token types.
#[derive(Debug, Clone)]
pub enum Token {
Expand Down
11 changes: 6 additions & 5 deletions src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct PackagesClientBuilder {
}

impl PackagesClientBuilder {
#[must_use]
pub fn new() -> Self {
Self {
headers: None,
Expand All @@ -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<Self> {
debug!("Constructing HTTP headers");
let auth_header_value = format!(
Expand All @@ -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));
Expand All @@ -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
/// <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
Expand All @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: <https://docs.github.com/en/rest/packages/packages?apiVersion=2022-11-28#delete-package-version-for-an-organization>
/// Docs for users: <https://docs.github.com/en/rest/packages/packages?apiVersion=2022-11-28#delete-a-package-version-for-the-authenticated-user>
pub async fn delete_package_version(
&self,
package_name: String,
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});

Expand Down

0 comments on commit 1e535f6

Please sign in to comment.