# Multi-stage build for Rust Linux container FROM rust:1.82-bookworm AS builder # Build dependencies (libudev for serialport on Linux) RUN apt-get update && apt-get install -y --no-install-recommends \ pkg-config \ libudev-dev \ build-essential \ ca-certificates \ tzdata \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Leverage docker layer caching for dependencies COPY Cargo.toml Cargo.lock ./ RUN mkdir -p src && echo 'fn main() { println!("cargo:rerun-if-changed=build.rs"); }' > src/main.rs RUN cargo build --release || true RUN rm -rf src # Copy full source and build real binaries COPY . . RUN cargo build --release --bin ntp_timeturner --bin ptp_probe # Build and install the Statime PTP daemon (from crates.io) # This installs the 'statime' binary into /usr/local/cargo/bin/statime in the builder image. RUN cargo install --locked statime-linux --version 0.4.0 # Runtime image FROM debian:bookworm-slim AS runtime RUN apt-get update && apt-get install -y --no-install-recommends \ libudev1 \ ca-certificates \ tzdata \ && rm -rf /var/lib/apt/lists/* WORKDIR /app COPY --from=builder /app/target/release/ntp_timeturner /usr/local/bin/ntp_timeturner COPY --from=builder /app/target/release/ptp_probe /usr/local/bin/ptp_probe COPY --from=builder /usr/local/cargo/bin/statime /usr/local/bin/statime COPY static ./static ENV RUST_LOG=info EXPOSE 8080 # Default to running the main server CMD ["ntp_timeturner"]