Skip to content

Commit

Permalink
prepare first release (#51)
Browse files Browse the repository at this point in the history
* Build against musl for static build (#50)

* fix release preparation
  • Loading branch information
muhamadazmy authored Jun 3, 2022
1 parent 0b97719 commit 819a61d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
asset_content_type: application/x-pie-executable
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"] }
53 changes: 37 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -66,9 +68,9 @@ fn between<T: Ord>(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)]
Expand All @@ -78,7 +80,7 @@ struct Args {
#[clap(short, long)]
mnemonics: Option<String>,

/// seed as hex
/// seed as hex (must start with 0x)
#[clap(long, conflicts_with = "mnemonics")]
seed: Option<String>,

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -244,11 +242,34 @@ async fn processor<S: Storage>(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);
Expand Down
1 change: 1 addition & 0 deletions substrate_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 819a61d

Please sign in to comment.