diff --git a/backend-rust/.env.mainnet b/backend-rust/.env.mainnet new file mode 100644 index 00000000..5078fc61 --- /dev/null +++ b/backend-rust/.env.mainnet @@ -0,0 +1,12 @@ +# gRPC interface of the node. +CCDSCAN_INDEXER_GRPC_ENDPOINTS=https://grpc.mainnet.concordium.software +# CCDSCAN_INDEXER_GRPC_ENDPOINTS=http://localhost:20000 + +# Database connection used by the ccdscan-indexer. +CCDSCAN_INDEXER_DATABASE_URL=postgres://postgres:secret@localhost/ccdscan_mainnet + +# Database connection used by the ccdscan-api. +CCDSCAN_API_DATABASE_URL=${CCDSCAN_INDEXER_DATABASE_URL} + +# Run database migrations at startup. +CCDSCAN_INDEXER_MIGRATE=true diff --git a/backend-rust/.env.stagenet b/backend-rust/.env.stagenet new file mode 100644 index 00000000..9d1a2d3f --- /dev/null +++ b/backend-rust/.env.stagenet @@ -0,0 +1,12 @@ +# gRPC interface of the node. +CCDSCAN_INDEXER_GRPC_ENDPOINTS=https://grpc.stagenet.concordium.com +# CCDSCAN_INDEXER_GRPC_ENDPOINTS=http://localhost:20500 + +# Database connection used by the ccdscan-indexer. +CCDSCAN_INDEXER_DATABASE_URL=postgres://postgres:secret@localhost/ccdscan_stagenet + +# Database connection used by the ccdscan-api. +CCDSCAN_API_DATABASE_URL=${CCDSCAN_INDEXER_DATABASE_URL} + +# Run database migrations at startup. +CCDSCAN_INDEXER_MIGRATE=true diff --git a/backend-rust/.env.testnet b/backend-rust/.env.testnet new file mode 100644 index 00000000..4ebde618 --- /dev/null +++ b/backend-rust/.env.testnet @@ -0,0 +1,12 @@ +# gRPC interface of the node. +CCDSCAN_INDEXER_GRPC_ENDPOINTS=https://grpc.testnet.concordium.com +# CCDSCAN_INDEXER_GRPC_ENDPOINTS=http://localhost:20001 + +# Database connection used by the ccdscan-indexer. +CCDSCAN_INDEXER_DATABASE_URL=postgres://postgres:secret@localhost/ccdscan_testnet + +# Database connection used by the ccdscan-api. +CCDSCAN_API_DATABASE_URL=${CCDSCAN_INDEXER_DATABASE_URL} + +# Run database migrations at startup. +CCDSCAN_INDEXER_MIGRATE=true diff --git a/backend-rust/src/bin/ccdscan-api.rs b/backend-rust/src/bin/ccdscan-api.rs index 28276262..81577e08 100644 --- a/backend-rust/src/bin/ccdscan-api.rs +++ b/backend-rust/src/bin/ccdscan-api.rs @@ -53,11 +53,31 @@ struct Cli { /// Non-zero exit code is returned when incompatible. #[arg(long, env = "CCDSCAN_API_CHECK_DATABASE_COMPATIBILITY_ONLY")] check_database_compatibility_only: bool, + /// Provide file to load environment variables from, instead of the default + /// `.env`. + // This is only part of this struct in order to generate help information. + // This argument is actually handled before hand using `DotenvCli`. + #[arg(long)] + dotenv: Option, +} + +/// CLI argument parser first used for parsing only the --dotenv option. +/// Allowing loading the provided file before parsing the remaining arguments +/// and producing errors +#[derive(Parser)] +#[command(ignore_errors = true, disable_help_flag = true, disable_version_flag = true)] +struct DotenvCli { + #[arg(long)] + dotenv: Option, } #[tokio::main] async fn main() -> anyhow::Result<()> { - let _ = dotenvy::dotenv(); + if let Some(dotenv) = DotenvCli::parse().dotenv { + dotenvy::from_filename(dotenv)?; + } else { + let _ = dotenvy::dotenv(); + } let cli = Cli::parse(); tracing_subscriber::fmt().with_max_level(cli.log_level).init(); let pool = PgPoolOptions::new() diff --git a/backend-rust/src/bin/ccdscan-indexer.rs b/backend-rust/src/bin/ccdscan-indexer.rs index 7b946f7f..6d5c2cc1 100644 --- a/backend-rust/src/bin/ccdscan-indexer.rs +++ b/backend-rust/src/bin/ccdscan-indexer.rs @@ -11,7 +11,7 @@ use prometheus_client::{ }; use serde_json::json; use sqlx::postgres::PgPoolOptions; -use std::net::SocketAddr; +use std::{net::SocketAddr, path::PathBuf}; use tokio::net::TcpListener; use tokio_util::sync::CancellationToken; use tracing::{error, info}; @@ -42,7 +42,7 @@ struct Cli { /// Address to listen for monitoring related requests #[arg(long, env = "CCDSCAN_INDEXER_MONITORING_ADDRESS", default_value = "127.0.0.1:8001")] monitoring_listen: SocketAddr, - #[command(flatten, next_help_heading = "Performance tuning")] + #[command(flatten)] indexer_config: IndexerServiceConfig, /// The maximum log level. Possible values are: `trace`, `debug`, `info`, /// `warn`, and `error`. @@ -56,11 +56,31 @@ struct Cli { /// migrations with elevated privileges. #[arg(long, env = "CCDSCAN_INDEXER_MIGRATE_ONLY")] migrate_only: bool, + /// Provide file to load environment variables from, instead of the default + /// `.env`. + // This is only part of this struct in order to generate help information. + // This argument is actually handled before hand using `DotenvCli`. + #[arg(long)] + dotenv: Option, +} + +/// CLI argument parser first used for parsing only the --dotenv option. +/// Allowing loading the provided file before parsing the remaining arguments +/// and producing errors +#[derive(Parser)] +#[command(ignore_errors = true, disable_help_flag = true, disable_version_flag = true)] +struct DotenvCli { + #[arg(long)] + dotenv: Option, } #[tokio::main] async fn main() -> anyhow::Result<()> { - let _ = dotenvy::dotenv(); + if let Some(dotenv) = DotenvCli::parse().dotenv { + dotenvy::from_filename(dotenv)?; + } else { + let _ = dotenvy::dotenv(); + } let cli = Cli::parse(); tracing_subscriber::fmt().with_max_level(cli.log_level).init(); let pool = PgPoolOptions::new()