From 53684796e5bf8c05942a39b6f1f8498ac3936be1 Mon Sep 17 00:00:00 2001 From: Alexander von Gluck Date: Fri, 21 Nov 2025 15:29:19 -0600 Subject: [PATCH] cli: Fix command line arguments. Allow using ENV vars --- Cargo.toml | 3 ++- docker-compose.yml | 6 ++---- src/main.rs | 21 ++++++++++++++++----- scripts/docker/entrypoint.sh | 8 +------- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 08a9f62..4977fcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ "std", "cargo", "derive", + "env", "help", "usage", ] } @@ -60,7 +61,7 @@ "bytecheck", "alloc", ], default-features = false } -rocksdb = { version = "0.23", default-features = false, features = ["snappy"] } +rocksdb = { version = "0.24", default-features = false, features = ["snappy"] } serde = { version = "1.0", features = ["derive", "rc"] } simdutf8 = "0.1.5" tar = { version = "0.4", default-features = false } diff --git a/docker-compose.yml b/docker-compose.yml index 42c93ed..81b086a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,15 +1,13 @@ version: '3' services: rgit: image: ghcr.io/w4/rgit:main - command: - - "[::]:8000" - - /git - - -d /tmp/rgit-cache.db volumes: - /volume/git:/git ports: - 8000:8000 environment: - REFRESH_INTERVAL=5m + - DB_STORE=/tmp/rgit.db + - SCAN_PATH=/git restart: unless-stopped diff --git a/src/main.rs b/src/main.rs index f679199..aeb2266 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,10 @@ #![deny(clippy::pedantic)] use std::{ borrow::Cow, fmt::{Display, Formatter}, future::IntoFuture, - net::SocketAddr, + net::{IpAddr, Ipv6Addr, SocketAddr}, path::PathBuf, str::FromStr, sync::{Arc, OnceLock}, @@ -72,24 +72,25 @@ #[derive(Parser, Debug)] #[clap(author, version, about)] pub struct Args { + /// The path in which your bare Git repositories reside (will be scanned recursively) + #[clap(short, long, env="SCAN_PATH", value_parser)] + scan_path: PathBuf, + /// The socket address to bind to (eg. 0.0.0.0:3333) + #[clap(short, long, env="BIND_ADDRESS", default_value_t = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 8080), value_parser)] + bind_address: SocketAddr, /// Path to a directory in which the `RocksDB` database should be stored, will be created if it doesn't already exist - /// /// The `RocksDB` database is very quick to generate, so this can be pointed to temporary storage - #[clap(short, long, value_parser)] + #[clap(short, long, env="DB_STORE", value_parser)] db_store: PathBuf, - /// The socket address to bind to (eg. 0.0.0.0:3333) - bind_address: SocketAddr, - /// The path in which your bare Git repositories reside (will be scanned recursively) - scan_path: PathBuf, /// Optional path (relative to cwd) to a plain text file containing a list of repositories relative to the `scan_path` /// that are whitelisted to be exposed by rgit. - #[clap(long)] + #[clap(long, env="REPOSITORY_LIST")] repository_list: Option, /// Configures the metadata refresh interval (eg. "never" or "60s") - #[clap(long, default_value_t = RefreshInterval::Duration(Duration::from_secs(300)))] + #[clap(long, env="REFRESH_INTERVAL", default_value_t = RefreshInterval::Duration(Duration::from_secs(300)))] refresh_interval: RefreshInterval, /// Configures the request timeout. - #[clap(long, default_value_t = Duration::from_secs(10).into())] + #[clap(long, env="REQUEST_TIMEOUT", default_value_t = Duration::from_secs(10).into())] request_timeout: humantime::Duration, } diff --git a/scripts/docker/entrypoint.sh b/scripts/docker/entrypoint.sh index 19c8208..ea506c8 100755 --- a/scripts/docker/entrypoint.sh +++ b/scripts/docker/entrypoint.sh @@ -1,8 +1,2 @@ #!/usr/bin/env bash - -if [ -z ${REFRESH_INTERVAL+x} ]; -then - ./rgit "[::]:8000" /git -d /tmp/rgit-cache.db; -else - ./rgit "[::]:8000" /git -d /tmp/rgit-cache.db --refresh-interval "$REFRESH_INTERVAL"; -fi +./rgit "[::]:8000" /git -d /tmp/rgit-cache.db; -- gitore 0.2.3