CodeBench: esikäännä Rust-riippuvuudet Docker-imageen — 35x nopeampi

Dummy-projekti samalla Cargo.toml:llä: cargo check + cargo build --tests
imageen. Runtime kääntyy vain itse projekti (~2.5s vs ~90s).
This commit is contained in:
2026-04-14 18:16:15 +03:00
parent 742f331d93
commit 8fbb8eda2d

View File

@@ -1,4 +1,28 @@
FROM rust:1.87-slim
RUN apt-get update && apt-get install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/*
WORKDIR /work
# Esikäännä riippuvuudet dummy-projektilla — nämä cachetaan Docker-layeriin
RUN cargo init --name bench-precompile . && \
cat > Cargo.toml <<'TOML'
[package]
name = "bench-precompile"
version = "0.1.0"
edition = "2024"
[dependencies]
axum = "0.8"
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sqlx = { version = "0.8", features = ["sqlite", "runtime-tokio"] }
tower-http = { version = "0.6", features = ["cors"] }
chrono = { version = "0.4", features = ["serde"] }
[dev-dependencies]
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
tokio = { version = "1", features = ["full", "test-util"] }
TOML
RUN cargo check 2>&1 && cargo build --tests 2>&1 && rm -rf src target/debug/deps/bench_precompile* target/debug/bench-precompile*
ENTRYPOINT ["sh", "-c", "cp -r /src/* . && cargo test 2>&1"]