From cdd2afe154bfbe6afc6d4a190d16e0a170fe64bc Mon Sep 17 00:00:00 2001 From: holly sparkles Date: Mon, 19 Feb 2024 22:38:55 +0100 Subject: [PATCH] Add support for configuration via environment variables - Enable the clap env feature - Update docker to remove unnecessary scripts --- Cargo.toml | 2 +- docker-compose.yml | 5 +++++ scripts/docker/entrypoint.sh | 22 +++++++++++++++++----- src/main.rs | 4 ++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8545710..aaf3834 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ bat = { version = "0.24.0", default-features = false, features = ["build-assets" bytes = "1.5" bincode = "1.3" comrak = "0.21.0" -clap = { version = "4.4.10", features = ["cargo", "derive"] } +clap = { version = "4.4.10", features = ["cargo", "derive", "env"] } futures = "0.3" git2 = "0.18.0" hex = "0.4" diff --git a/docker-compose.yml b/docker-compose.yml index dbb0670..bd6fe29 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,11 @@ services: image: ghcr.io/w4/rgit:main volumes: - /path/to/my-repos:/git + environment: + - RGIT_DB_STORE=/tmp/rgit-cache.db + - RGIT_BIND_ADDRESS=0.0.0.0:8000 + - RGIT_SCAN_PATH=/git + - RGIT_REFRESH_INTERVAL=5m ports: - 3333:8000 restart: unless-stopped diff --git a/scripts/docker/entrypoint.sh b/scripts/docker/entrypoint.sh index dc4eac4..bca81fe 100755 --- a/scripts/docker/entrypoint.sh +++ b/scripts/docker/entrypoint.sh @@ -1,8 +1,20 @@ #!/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; +# Set defaults +if [ -z "${RGIT_DB_STORE+x}" ]; then + export RGIT_DB_STORE="/tmp/rgit-cache.db" fi + +if [ -z "${RGIT_BIND_ADDRESS+x}" ]; then + export RGIT_BIND_ADDRESS="[::]:8000" +fi + +if [ -z "${RGIT_SCAN_PATH+x}" ]; then + export RGIT_SCAN_PATH="/git" +fi + +if [ -z "${RGIT_SCAN_PATH+x}" ]; then + export RGIT_SCAN_PATH="5m" +fi + +./rgit \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index b5c2d65..e76d7fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,13 +68,17 @@ pub struct Args { /// /// The RocksDB database is very quick to generate, so this can be pointed to temporary storage #[clap(short, long, value_parser)] + #[clap(env = "RGIT_DB_STORE")] db_store: PathBuf, /// The socket address to bind to (eg. 0.0.0.0:3333) + #[clap(env = "RGIT_BIND_ADDRESS")] bind_address: SocketAddr, /// The path in which your bare Git repositories reside (will be scanned recursively) + #[clap(env = "RGIT_SCAN_PATH")] scan_path: PathBuf, /// Configures the metadata refresh interval (eg. "never" or "60s") #[clap(long, default_value_t = RefreshInterval::Duration(Duration::from_secs(300)))] + #[clap(env = "RGIT_REFRESH_INTERVAL")] refresh_interval: RefreshInterval, } -- libgit2 1.7.2