diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a4c2106 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,22 @@ +# Rust build artifacts +/target + +# VCS +/.git +/.gitignore + +# Editors/OS +.DS_Store +*.swp +*.swo +*~ + +# Node/web (if present) +node_modules +dist +build + +# Firmware intermediate dirs (if any) +firmware/.pio +firmware/.pioenvs +firmware/build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..70abacd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +# 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 + +# 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 static ./static + +ENV RUST_LOG=info +EXPOSE 8080 + +# Default to running the main server +CMD ["ntp_timeturner"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e624a1d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +version: "3.8" + +services: + app: + build: + context: . + dockerfile: Dockerfile + image: ntp_timeturner:latest + container_name: ntp_timeturner + environment: + - RUST_LOG=info + ports: + - "8080:8080" + volumes: + - ./static:/app/static:ro + restart: unless-stopped + + # Optional: probe a PTP hardware clock (Linux host with /dev/ptp0) + ptp-probe: + build: + context: . + dockerfile: Dockerfile + image: ntp_timeturner:latest + profiles: + - hw + command: ["ptp_probe", "--device", "/dev/ptp0", "--interval", "1.0", "--count", "0"] + devices: + - "/dev/ptp0:/dev/ptp0" + restart: "no"