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:
@@ -1,4 +1,28 @@
|
|||||||
FROM rust:1.87-slim
|
FROM rust:1.87-slim
|
||||||
RUN apt-get update && apt-get install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/*
|
||||||
WORKDIR /work
|
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"]
|
ENTRYPOINT ["sh", "-c", "cp -r /src/* . && cargo test 2>&1"]
|
||||||
|
|||||||
Reference in New Issue
Block a user