Skip to content

Commit

Permalink
refactor: refactor cli args (#1222)
Browse files Browse the repository at this point in the history
* Remove settings.rs and refactor configuration handling

Deleted settings.rs and moved configuration logic into config.rs, introducing ForesterConfig::new_for_start and ForesterConfig::new_for_status. Updated Docker commands and enhanced Dockerfile to reflect these changes. Adjusted WS URL handling and metrics push logic for better functional separation.

* Standardize CLI argument environment variable names

Updated environment variable names in CLI arguments to use the 'FORESTER_' prefix for consistency. This change ensures better readability and maintainability by following a uniform naming convention.

* Rename `length` to `processing_length` in queue handlers.

This change clarifies the purpose of the length parameters, specifying that they pertain to the processing length of queues rather than their total length. Updates have been made across `queue_helpers.rs`, `config.rs`, and `cli.rs` for consistency.

* Add GitHub Actions workflow for Docker build and push.

* Refactor Dockerfile to add custom startup script

* Enhance logging for start script in Dockerfile

* Simplify Dockerfile entrypoint

* Make `payer` and `rpc_url` optional in CLI args

Convert `rpc_url` and `payer` to `Option` types to handle scenarios where they might be missing and ensure appropriate error handling. Updated configuration initializations to account for these optional fields, thereby improving robustness and flexibility.

* Update forester CI workflow configuration

Switched the branch trigger to 'main' and pull request paths to 'forester/**'. Upgraded Docker GitHub Actions to newer versions for better compatibility and performance.

* Refactor config and CLI for better readability

* Fix tests

* Update pushgateway URL in test utils configuration

This change sets the `pushgateway_url` to `None` in the test configuration. This will prevent attempts to push metrics to Pushgateway during test runs, ensuring tests do not interact with external services.
  • Loading branch information
sergeytimoshin authored Sep 17, 2024
1 parent 24b2337 commit 09d605a
Show file tree
Hide file tree
Showing 14 changed files with 410 additions and 329 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/forester-build-and-push-to-docr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Docker Build and Push to DOCR

on:
push:
branches:
- main
pull_request:
branches:
- "**"
paths:
- "forester/**"

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DigitalOcean Container Registry
uses: docker/login-action@v3
with:
registry: registry.digitalocean.com
username: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
password: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./forester/Dockerfile
platforms: linux/amd64
push: true
tags: registry.digitalocean.com/v3-relayer/forester:latest

- name: Inspect image
run: |
docker buildx imagetools inspect registry.digitalocean.com/v3-relayer/forester:latest
2 changes: 1 addition & 1 deletion forester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
[dependencies]
config = "0.14.0"
anchor-lang = { workspace = true }
clap = {version = "4.5.9", features = ["derive"]}
clap = {version = "4.5.9", features = ["derive", "env"]}
solana-sdk = { workspace = true }
solana-client = { workspace = true }
solana-transaction-status = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions forester/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ RUN apt-get update && apt-get install -y ca-certificates libssl-dev && rm -rf /v
RUN mkdir -p /app/config
COPY --from=builder /app/target/release/forester /usr/local/bin/forester
WORKDIR /app
ENTRYPOINT ["forester"]
CMD ["start"]

ENTRYPOINT ["/usr/local/bin/forester"]
CMD []
126 changes: 119 additions & 7 deletions forester/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,129 @@
use clap::{Parser, Subcommand};

#[derive(Parser)]
#[clap(author, version, about, long_about=None)]
#[clap(author, version, about, long_about = None)]
pub struct Cli {
#[arg(long, default_value_t = false, global = true)]
pub enable_metrics: bool,

#[command(subcommand)]
pub command: Option<Commands>,
pub command: Commands,
}

#[allow(clippy::large_enum_variant)]
#[derive(Subcommand)]
pub enum Commands {
Start,
Status,
Start(StartArgs),
Status(StatusArgs),
}

#[derive(Parser, Clone, Debug)]
pub struct StartArgs {
#[arg(long, env = "FORESTER_RPC_URL")]
pub rpc_url: Option<String>,

#[arg(long, env = "FORESTER_PUSH_GATEWAY_URL")]
pub push_gateway_url: Option<String>,

#[arg(long, env = "FORESTER_WS_RPC_URL")]
pub ws_rpc_url: Option<String>,

#[arg(long, env = "FORESTER_INDEXER_URL")]
pub indexer_url: Option<String>,

#[arg(long, env = "FORESTER_PROVER_URL")]
pub prover_url: Option<String>,

#[arg(long, env = "FORESTER_PAYER")]
pub payer: Option<String>,

#[arg(long, env = "FORESTER_PHOTON_API_KEY")]
pub photon_api_key: Option<String>,

#[arg(long, env = "FORESTER_INDEXER_BATCH_SIZE", default_value = "50")]
pub indexer_batch_size: usize,

#[arg(
long,
env = "FORESTER_INDEXER_MAX_CONCURRENT_BATCHES",
default_value = "10"
)]
pub indexer_max_concurrent_batches: usize,

#[arg(long, env = "FORESTER_TRANSACTION_BATCH_SIZE", default_value = "1")]
pub transaction_batch_size: usize,

#[arg(
long,
env = "FORESTER_TRANSACTION_MAX_CONCURRENT_BATCHES",
default_value = "20"
)]
pub transaction_max_concurrent_batches: usize,

#[arg(long, env = "FORESTER_CU_LIMIT", default_value = "1000000")]
pub cu_limit: u32,

#[arg(long, env = "FORESTER_RPC_POOL_SIZE", default_value = "20")]
pub rpc_pool_size: usize,

#[arg(
long,
env = "FORESTER_SLOT_UPDATE_INTERVAL_SECONDS",
default_value = "10"
)]
pub slot_update_interval_seconds: u64,

#[arg(
long,
env = "FORESTER_TREE_DISCOVERY_INTERVAL_SECONDS",
default_value = "5"
)]
pub tree_discovery_interval_seconds: u64,

#[arg(long, env = "FORESTER_MAX_RETRIES", default_value = "3")]
pub max_retries: u32,

#[arg(long, env = "FORESTER_RETRY_DELAY", default_value = "1000")]
pub retry_delay: u64,

#[arg(long, env = "FORESTER_RETRY_TIMEOUT", default_value = "30000")]
pub retry_timeout: u64,

#[arg(long, env = "FORESTER_STATE_QUEUE_START_INDEX", default_value = "0")]
pub state_queue_start_index: u16,

#[arg(
long,
env = "FORESTER_STATE_PROCESSING_LENGTH",
default_value = "28807"
)]
pub state_queue_processing_length: u16,

#[arg(long, env = "FORESTER_ADDRESS_QUEUE_START_INDEX", default_value = "0")]
pub address_queue_start_index: u16,

#[arg(
long,
env = "FORESTER_ADDRESS_PROCESSING_LENGTH",
default_value = "28807"
)]
pub address_queue_processing_length: u16,
}

#[derive(Parser, Clone, Debug)]
pub struct StatusArgs {
#[arg(long, env = "FORESTER_RPC_URL")]
pub rpc_url: Option<String>,

#[arg(long, env = "FORESTER_PUSH_GATEWAY_URL")]
pub push_gateway_url: Option<String>,
}

impl StartArgs {
pub fn enable_metrics(&self) -> bool {
self.push_gateway_url.is_some()
}
}

impl StatusArgs {
pub fn enable_metrics(&self) -> bool {
self.push_gateway_url.is_some()
}
}
Loading

0 comments on commit 09d605a

Please sign in to comment.