diff --git a/Cargo.lock b/Cargo.lock index f07d9284..825cc0ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -570,9 +570,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.16.0" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" [[package]] name = "byteorder" @@ -597,9 +597,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.21" +version = "1.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" dependencies = [ "jobserver", "libc", @@ -926,21 +926,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.0.1" @@ -1319,31 +1304,32 @@ dependencies = [ ] [[package]] -name = "hyper-timeout" -version = "0.4.1" +name = "hyper-rustls" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +checksum = "a0bea761b46ae2b24eb4aef630d8d1c398157b6fc29e6350ecf090a0b70c952c" dependencies = [ - "hyper 0.14.30", - "pin-project-lite", + "futures-util", + "http 1.1.0", + "hyper 1.4.1", + "hyper-util", + "rustls 0.22.4", + "rustls-pki-types", "tokio", - "tokio-io-timeout", + "tokio-rustls 0.25.0", + "tower-service", ] [[package]] -name = "hyper-tls" -version = "0.6.0" +name = "hyper-timeout" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" dependencies = [ - "bytes", - "http-body-util", - "hyper 1.4.1", - "hyper-util", - "native-tls", + "hyper 0.14.30", + "pin-project-lite", "tokio", - "tokio-native-tls", - "tower-service", + "tokio-io-timeout", ] [[package]] @@ -1669,23 +1655,6 @@ version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d02c0b00610773bb7fc61d85e13d86c7858cbdf00e1a120bfc41bc055dbaa0e" -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "nittei" version = "0.1.0" @@ -1705,6 +1674,7 @@ dependencies = [ "opentelemetry-otlp", "opentelemetry_sdk", "test-log", + "tikv-jemallocator", "tokio", "tracing", "tracing-opentelemetry", @@ -1909,50 +1879,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags 2.6.0", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.68", -] - [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "opentelemetry" version = "0.23.0" @@ -2081,9 +2013,9 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "parking" -version = "2.2.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" +checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" [[package]] name = "parking_lot" @@ -2447,7 +2379,7 @@ dependencies = [ "http 0.2.12", "http-body 0.4.6", "hyper 0.14.30", - "hyper-rustls", + "hyper-rustls 0.24.2", "ipnet", "js-sys", "log", @@ -2481,7 +2413,6 @@ checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" dependencies = [ "base64 0.22.1", "bytes", - "encoding_rs", "futures-core", "futures-util", "h2 0.4.5", @@ -2489,29 +2420,30 @@ dependencies = [ "http-body 1.0.0", "http-body-util", "hyper 1.4.1", - "hyper-tls", + "hyper-rustls 0.26.0", "hyper-util", "ipnet", "js-sys", "log", "mime", - "native-tls", "once_cell", "percent-encoding", "pin-project-lite", + "rustls 0.22.4", "rustls-pemfile 2.1.2", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", - "system-configuration", "tokio", - "tokio-native-tls", + "tokio-rustls 0.25.0", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", + "webpki-roots", "winreg 0.52.0", ] @@ -2639,7 +2571,21 @@ dependencies = [ "log", "ring 0.17.8", "rustls-pki-types", - "rustls-webpki 0.102.5", + "rustls-webpki 0.102.7", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls" +version = "0.23.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" +dependencies = [ + "once_cell", + "ring 0.17.8", + "rustls-pki-types", + "rustls-webpki 0.102.7", "subtle", "zeroize", ] @@ -2693,9 +2639,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.102.5" +version = "0.102.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a6fccd794a42c2c105b513a2f62bc3fd8f3ba57a4593677ceb0bd035164d78" +checksum = "84678086bd54edf2b415183ed7a94d0efb049f1b646a33e22a36f3794be6ae56" dependencies = [ "ring 0.17.8", "rustls-pki-types", @@ -3019,6 +2965,8 @@ dependencies = [ "once_cell", "paste", "percent-encoding", + "rustls 0.23.12", + "rustls-pemfile 2.1.2", "serde", "serde_json", "sha2", @@ -3030,6 +2978,7 @@ dependencies = [ "tracing", "url", "uuid", + "webpki-roots", ] [[package]] @@ -3318,6 +3267,26 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tikv-jemalloc-sys" +version = "0.5.4+5.3.0-patched" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9402443cb8fd499b6f327e40565234ff34dbda27460c5b47db0db77443dd85d1" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "tikv-jemallocator" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "965fe0c26be5c56c94e38ba547249074803efd52adfb66de62107d95aab3eaca" +dependencies = [ + "libc", + "tikv-jemalloc-sys", +] + [[package]] name = "time" version = "0.3.36" @@ -3403,16 +3372,6 @@ dependencies = [ "syn 2.0.68", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.24.1" @@ -3873,6 +3832,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd7c23921eeb1713a4e851530e9b9756e4fb0e89978582942612524cf09f01cd" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "whoami" version = "1.5.1" diff --git a/bins/nittei/Cargo.toml b/bins/nittei/Cargo.toml index 2b527da7..b34439ef 100644 --- a/bins/nittei/Cargo.toml +++ b/bins/nittei/Cargo.toml @@ -43,6 +43,15 @@ openssl-probe = "0.1.2" chrono = "0.4.19" chrono-tz = "0.8.1" +# Use Jemalloc only for musl-64 bits platforms +# The default MUSL allocator is known to be slower than Jemalloc +# E.g. https://github.com/BurntSushi/ripgrep/commit/03bf37ff4a29361c47843369f7d3dc5689b8fdac +[target.'cfg(all(target_env = "musl", target_pointer_width = "64"))'.dependencies.tikv-jemallocator] +version = "0.5" + + +################## +# Dev dependencies [dev-dependencies] nittei_sdk = { workspace = true } futures = "0.3" diff --git a/bins/nittei/src/main.rs b/bins/nittei/src/main.rs index bb3ff7b4..0d81fcda 100644 --- a/bins/nittei/src/main.rs +++ b/bins/nittei/src/main.rs @@ -3,6 +3,15 @@ mod telemetry; use nittei_api::Application; use nittei_infra::setup_context; use telemetry::init_subscriber; +#[cfg(all(target_env = "musl", target_pointer_width = "64"))] +use tikv_jemallocator::Jemalloc; + +// Use Jemalloc only for musl-64 bits platforms +// The default MUSL allocator is known to be slower than Jemalloc +// E.g. https://github.com/BurntSushi/ripgrep/commit/03bf37ff4a29361c47843369f7d3dc5689b8fdac +#[cfg(all(target_env = "musl", target_pointer_width = "64"))] +#[global_allocator] +static GLOBAL: Jemalloc = Jemalloc; #[tokio::main] async fn main() -> anyhow::Result<()> { diff --git a/clients/rust/Cargo.toml b/clients/rust/Cargo.toml index 76c74722..ac643713 100644 --- a/clients/rust/Cargo.toml +++ b/clients/rust/Cargo.toml @@ -14,7 +14,11 @@ workspace = true [dependencies] nittei_api_structs = { path = "../../crates/api_structs", version = "0.3.1" } nittei_domain = { path = "../../crates/domain", version = "0.2.1" } -reqwest = { version = "0.12", features = ["json"] } +reqwest = { version = "0.12", default-features = false, features = [ + "http2", + "json", + "rustls-tls", +] } serde = "1" chrono = { version = "0.4.19", features = ["serde"] } chrono-tz = { version = "0.8.1", features = ["serde"] } diff --git a/crates/infra/Cargo.toml b/crates/infra/Cargo.toml index af95a6f5..0dbbc057 100644 --- a/crates/infra/Cargo.toml +++ b/crates/infra/Cargo.toml @@ -20,11 +20,16 @@ chrono-tz = { version = "0.8.1", features = ["serde"] } anyhow = "1.0" tokio = { version = "1", features = ["macros"] } tracing = "0.1.25" -reqwest = { version = "0.12", features = ["json"] } +reqwest = { version = "0.12", default-features = false, features = [ + "http2", + "json", + "rustls-tls", +] } uuid = { version = "1.1.2", features = ["serde"] } futures = "0.3" sqlx = { version = "0.8.2", features = [ "runtime-tokio", + "tls-rustls-ring", "postgres", "uuid", "json", diff --git a/musl.Dockerfile b/musl.Dockerfile index 39ce9c7e..34ba302f 100644 --- a/musl.Dockerfile +++ b/musl.Dockerfile @@ -1,24 +1,26 @@ -FROM ekidd/rust-musl-builder as builder +# Usage: +# docker buildx build -f musl.Dockerfile -t image:tag --build-arg='ARCH=x86_64' --platform linux/amd64 . +# docker buildx build -f musl.Dockerfile -t image:tag --build-arg='ARCH=aarch64' --platform linux/arm64 . -WORKDIR /home/rust/ +ARG ARCH=x86_64 +FROM messense/rust-musl-cross:${ARCH}-musl AS builder -COPY . . +ARG ARCH=x86_64 +ARG APP_NAME=nittei -USER root -RUN chown -R rust:rust . -USER rust +# Copy source code from previous stage +COPY . . -ENV DATABASE_URL "postgresql://postgres:postgres@172.17.0.1:5432/nittei" +# Build application +RUN cargo build --release --target ${ARCH}-unknown-linux-musl && \ + cp ./target/${ARCH}-unknown-linux-musl/release/${APP_NAME} /${APP_NAME} -# RUN cargo test -RUN cargo build --release +#Create a new stage with a minimal image +FROM busybox:musl -# Size optimization -RUN strip target/x86_64-unknown-linux-musl/release/nittei +ARG APP_NAME=nittei +ENV APP_NAME=${APP_NAME} -# Start building the final image -FROM scratch -WORKDIR /home/rust/ -COPY --from=builder /home/rust/target/x86_64-unknown-linux-musl/release/nittei . +COPY --from=builder /${APP_NAME} /${APP_NAME} -ENTRYPOINT ["./nittei"] +CMD /${APP_NAME}