diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 50b46f9..5dfa72f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -8,10 +8,14 @@ name: Create Release jobs: build: - name: Releasing zinit + name: Releasing rmb # we use 18.04 to be compatible with libc version on zos runs-on: ubuntu-20.04 steps: + - name: Prepare + run: | + sudo apt-get update + sudo apt-get install musl-dev musl-tools - name: Checkout code uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 @@ -43,4 +47,4 @@ jobs: upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: target/x86_64-unknown-linux-musl/release/rmb asset_name: rmb - asset_content_type: application/x-pie-executable \ No newline at end of file + asset_content_type: application/x-pie-executable diff --git a/Cargo.toml b/Cargo.toml index 71548b8..f1f5956 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,12 +3,9 @@ edition = "2021" name = "rmb-rs" version = "0.1.0" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -# [workspace] -# members = [ -# "rmb_client" -# ] +[[bin]] +name = "rmb" +path = "src/main.rs" [dependencies] anyhow = "1.0.56" @@ -35,3 +32,6 @@ md5 = "0.7.0" clap = {version = "3.1", features = ["derive"]} base64 = "0.13.0" nix = "0.24.1" +git-version = "0.3.5" +# for static build +openssl = { version = "0.10", features = ["vendored"] } diff --git a/src/main.rs b/src/main.rs index 54a455f..114591c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,6 +27,8 @@ use twin::{SubstrateTwinDB, TwinDB}; const MIN_RETRIES: usize = 1; const MAX_RETRIES: usize = 5; +const GIT_VERSION: &str = + git_version::git_version!(args = ["--tags", "--always", "--dirty=-modified"]); #[derive(Debug)] enum KeyType { @@ -66,9 +68,9 @@ fn between(v: T, min: T, max: T) -> T { v } -/// the grid message bus +/// the reliable message bus #[derive(Parser, Debug)] -#[clap(author, version, about, long_about = None)] +#[clap(name ="rmb", author, version = GIT_VERSION, about, long_about = None)] struct Args { /// key type #[clap(short, long, default_value_t = KeyType::Sr25519)] @@ -78,7 +80,7 @@ struct Args { #[clap(short, long)] mnemonics: Option, - /// seed as hex + /// seed as hex (must start with 0x) #[clap(long, conflicts_with = "mnemonics")] seed: Option, @@ -118,18 +120,14 @@ async fn app(args: &Args) -> Result<()> { .with_module_level("substrate_api_client", log::LevelFilter::Off) .init()?; - // this will get either a prefixed "0x" seed or mnemonics - let secret = if let Some(seed) = &args.seed { - if !seed.to_lowercase().starts_with("0x") { - format!("0x{}", seed) - } else { - seed.clone() - } - } else { - match &args.mnemonics { - Some(mnemonics) => mnemonics.clone(), - None => bail!("either mnemonics or seed must be provided"), - } + let secret = match args.mnemonics { + Some(ref m) => m, + None => match args.seed { + Some(ref s) => s, + None => { + bail!("either mnemonics or seed must be provided"); + } + }, }; let identity = match args.key_type { @@ -244,11 +242,34 @@ async fn processor(id: u32, storage: S) { } } +/// set_ca populate the SSL_CERT_DIR environment variable +/// only if built against musl and none of the SSL variables +/// are passed by the user. +fn set_ca() { + if std::cfg!(target_env = "musl") { + use std::env; + let file = env::var_os("SSL_CERT_FILE"); + let dir = env::var_os("SSL_CERT_DIR"); + if file.is_some() || dir.is_some() { + // user already setting up environment file + // for certificate + return; + } + + // nothing is set, override + env::set_var("SSL_CERT_DIR", "/etc/ssl/certs") + } +} + #[tokio::main] async fn main() { - nix::sys::resource::setrlimit(nix::sys::resource::Resource::RLIMIT_NOFILE, 10240, 10240) + // we set the soft, hard limit of max number of open file to a big value so we can handle as much connections + // as possible. + nix::sys::resource::setrlimit(nix::sys::resource::Resource::RLIMIT_NOFILE, 16384, 16384) .unwrap(); + set_ca(); + let args = Args::parse(); if let Err(e) = app(&args).await { eprintln!("{}", e); diff --git a/substrate_client/Cargo.toml b/substrate_client/Cargo.toml index 03afc35..db5f469 100644 --- a/substrate_client/Cargo.toml +++ b/substrate_client/Cargo.toml @@ -14,6 +14,7 @@ sp-keyring = "3.0.0" # frame-support = "3.0.0" # frame-system = "3" parity-scale-codec = "3.1.2" +openssl = { version = "0.10", features = ["vendored"] } [dev-dependencies] env_logger = "0.9.0"