Skip to content

recmo/rust-service-template

Repository files navigation

Rust project template

lines of code dependency status codecov Build, Test & Deploy

Features

Continuous Integration

  • Build, test and deploy
    • Run rustfmt, clippy and doc build

Main features. Comes with the kitchen sink. Remove what you don't need.

  • Command line argument parsing using StructOpt.
  • Version info including commit hash.
  • Error handling using anyhow and thiserror.
  • Logging using tracing with log and futures compatibility, -v, -vv, etc. command line arguments.
  • Preloaded with serde, rand, rayon, itertools.
  • Tests using proptest, pretty_assertions and float_eq. I recommend the closure style proptests.
  • Benchmarks using criterion (run cargo criterion).
  • Dependencies build optimized, also in dev build.
  • From scratch Docker build statically linked to musl.

Deployment

Using GitHub actions for each PR it will push a Docker container image to the Github container registry. A Helm chart is included for easy deployment to Kubernetes clusters. The ingress rule assumes a Traefik frontend.

Todo: Tutorial using: https://github.com/redkubes/otomi-core

Hints

Lint, build, test, run

cargo fmt && cargo clippy --all-targets --all-features && cargo build --all-targets --all-features && cargo test && cargo run --

Run benchmarks

cargo bench --bench criterion --features="bench proptest"

How to use the template

Update Cargo.toml and regenerate deploy/Chart.yaml from it using the included script:

./deploy/generate.py > ./deploy/Chart.yaml

Change the name of the crate from rust_service_template to the new name in ./criterion.rs and ./src/cli/main.rs.

Implement your service in src/lib.rs.

If your service makes outbound connections, add egress rules to deploy/templates/network-policy.yaml.

Deploy using Helm on a Kubernetes cluster using Traefik for ingress management.

To do

Copy from Tokio:

  • Add license, contributing, and other changelogs

  • Rustdocs with Katex.

  • Long running / fuzz mode for proptests.

  • loom support for concurrency testing, maybe simulation.

  • Add crates.io publishing

Build images locally

for arch in x86_64 aarch64; do
  docker run --rm \
    -v "$(pwd)":/src \
    -v $HOME/.cargo:/usr/local/cargo:Z \
    -v /usr/local/cargo/bin \
    ghcr.io/recmo/rust-static-build:1.58-$arch \
    cargo build --locked --release --features mimalloc
done
for arch in amd64 arm64; do
  docker build --platform linux/$arch --tag rust-service-template:latest-$arch .
done
docker manifest rm ghcr.io/recmo/rust-service-template:latest
docker manifest create \
    rust-service-template:latest \
    rust-service-template:latest-amd64 \
    rust-service-template:latest-arm64
docker manifest inspect rust-service-template:latest

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages