diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b65d147 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +.git/ +.vscode/ +screenshot/ +tests/ +*.txt +*.csv +*.xlsx +devel/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9b681bc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +# Release instructions: +# 1. Update the version tag in the Dockerfile to match the version in Cargo.toml +# 2. Update the VCS_REF tag to match the tagged version's FULL commit hash +# 3. Build image with BOTH latest and version tags +# i.e. `docker build -t sherlock/sherlocke:0.1.0 -t sherlock/sherlock:latest .` + +# Stage 1: Build the Rust application +FROM rust:1.70-slim-bullseye as build + +# Set the working directory inside the container +WORKDIR /sherlock + +# Copy the Cargo.toml and Cargo.lock files to build the dependencies first +COPY Cargo.toml Cargo.lock ./ + +# Fetch dependencies and cache them +RUN cargo fetch + +# Copy the rest of the application source code +COPY . . + +# Build the application in release mode +RUN cargo build --release + +# Stage 2: Create a minimal runtime image +FROM debian:buster-slim +WORKDIR /sherlock + +ARG VCS_REF= # CHANGE ME ON UPDATE +ARG VCS_URL="https://github.com/jonaylor89/sherlock-rs" +ARG VERSION_TAG= # CHANGE ME ON UPDATE + +LABEL org.label-schema.vcs-ref=$VCS_REF \ + org.label-schema.vcs-url=$VCS_URL \ + org.label-schema.name="Sherlock" \ + org.label-schema.version=$VERSION_TAG \ + website="https://sherlockproject.xyz" + +# Copy the compiled binary from the build stage +COPY --from=build /sherlock/target/release/myrustapp /usr/local/bin/sherlock + +# Specify the entrypoint of the container +ENTRYPOINT ["sherlock"] diff --git a/src/main.rs b/src/main.rs index afc9be8..d093a86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,7 +77,7 @@ struct Cli { local: bool, /// Include checking of NSFW sites from default list. - #[clap(long, alias = "nsfw")] + #[clap(long, alias = "nsfw", default_value_t = true)] nsfw: bool, } @@ -95,10 +95,27 @@ async fn main() -> Result<()> { println!("[!!!] error path [{}]", err.path()); })?; + let targets = match cli.nsfw { + true => initial_data.targets, + false => initial_data + .targets + .into_iter() + .filter(|(_, info)| !info.is_nsfw.unwrap_or(false)) + .collect(), + }; + + let filtered_targets = match cli.site_list.is_empty() { + true => targets, + false => targets + .into_iter() + .filter(|(site, _)| cli.site_list.contains(&site)) + .collect(), + }; + for username in cli.usernames { let results = check_username( &username, - initial_data.targets.clone(), + filtered_targets.clone(), cli.timeout, cli.proxy.as_ref(), ) diff --git a/tests/status_code_test.rs b/tests/status_code_test.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/status_code_test.rs @@ -0,0 +1 @@ +