From c6a15c4da399f9e07166c21b93b154ddd698fe3b Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Fri, 26 Jan 2024 13:46:16 +0100 Subject: [PATCH] Basic bin --- .dockerignore | 2 +- Cargo.lock | 2 +- Cargo.toml | 8 +++---- Dockerfile | 40 ++++++++++++++++++++++++++++++++- README.md | 2 +- bin/{service.rs => mpc_node.rs} | 4 +++- rust-toolchain.toml | 2 ++ rustfmt.toml | 3 +++ 8 files changed, 54 insertions(+), 9 deletions(-) rename bin/{service.rs => mpc_node.rs} (83%) create mode 100644 rust-toolchain.toml create mode 100644 rustfmt.toml diff --git a/.dockerignore b/.dockerignore index 73a56d4..bda08b5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,3 @@ target/ .git -README.md \ No newline at end of file +README.md diff --git a/Cargo.lock b/Cargo.lock index 2db37ac..2b6e16f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2441,7 +2441,7 @@ dependencies = [ [[package]] name = "telemetry-batteries" version = "0.1.0" -source = "git+https://github.com/worldcoin/telemetry-batteries.git#c6816624415ae194da5203a5161621a9e10ad3b0" +source = "git+https://github.com/worldcoin/telemetry-batteries.git?rev=c6816624415ae194da5203a5161621a9e10ad3b0#c6816624415ae194da5203a5161621a9e10ad3b0" dependencies = [ "chrono", "dirs", diff --git a/Cargo.toml b/Cargo.toml index 8c418bf..2ce2612 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -clap = { verison = "4.4.18", features = ["derive"] } +clap = { version = "4.4.18", features = ["derive"] } config = "0.13.4" criterion = "0.5.1" eyre = "0.6.11" @@ -14,13 +14,13 @@ sqlx = { version = "0.7.3", features = [ "postgres", "chrono", ] } -telemetry-batteries = { git = "https://github.com/worldcoin/telemetry-batteries.git", commit = "c6816624415ae194da5203a5161621a9e10ad3b0" } +telemetry-batteries = { git = "https://github.com/worldcoin/telemetry-batteries.git", rev = "c6816624415ae194da5203a5161621a9e10ad3b0" } tokio = { version = "1.35.1", features = ["macros"] } tracing = "0.1.40" [[bin]] -name = "service" -path = "bin/service.rs" +name = "mpc-node" +path = "bin/mpc_node.rs" [[bench]] name = "example" diff --git a/Dockerfile b/Dockerfile index 49c30b8..f5af92d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1 +1,39 @@ -FROM rust:1.75.0 AS chef-builder \ No newline at end of file +FROM debian:12 as build-env + +WORKDIR /src + +# Install dependencies +RUN apt-get update && \ + apt-get install -y \ + curl build-essential \ + libssl-dev texinfo \ + libcap2-bin pkg-config + +# TODO: Use a specific version of rustup +# Install rustup +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y + +COPY . . + +# Set environment variables +ENV PATH="/root/.cargo/bin:${PATH}" +ENV RUSTUP_HOME="/root/.rustup" +ENV CARGO_HOME="/root/.cargo" + +# Install the toolchain +RUN rustup component add cargo + +# Build the binary +RUN cargo fetch +RUN cargo build --release --no-default-features + +# Make sure it runs +RUN /src/target/release/mpc-node --version + +# cc variant because we need libgcc and others +FROM gcr.io/distroless/cc-debian12:nonroot + +# Copy the mpc-node binary +COPY --from=build-env --chown=0:10001 --chmod=010 /src/target/release/mpc-node /bin/mpc-node + +ENTRYPOINT [ "/bin/mpc-node" ] diff --git a/README.md b/README.md index 749b960..68df485 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# service-template-rs +# MPC Service diff --git a/bin/service.rs b/bin/mpc_node.rs similarity index 83% rename from bin/service.rs rename to bin/mpc_node.rs index 9b2f03f..1056ab5 100644 --- a/bin/service.rs +++ b/bin/mpc_node.rs @@ -1,5 +1,6 @@ use clap::Parser; -use telemetry_batteries::{metrics::batteries::StatsdBattery, tracing::batteries::DatadogBattery}; +use telemetry_batteries::metrics::batteries::StatsdBattery; +use telemetry_batteries::tracing::batteries::DatadogBattery; pub const SERVICE_NAME: &str = "service"; @@ -10,6 +11,7 @@ pub const METRICS_BUFFER_SIZE: usize = 1024; pub const METRICS_PREFIX: &str = "service"; #[derive(Parser)] +#[clap(version)] pub struct Args {} #[tokio::main] diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..cce326e --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2024-01-26" diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..cc19b4d --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,3 @@ +group_imports = "StdExternalCrate" +imports_granularity = "Module" +max_width = 80 \ No newline at end of file