feat: add Docker setup with Dockerfile and docker-compose

Co-authored-by: aider (openai/gpt-5) <aider@aider.chat>
This commit is contained in:
Chaos Rogers 2025-10-21 22:51:25 +01:00
parent 5ba0421f76
commit 4d34f11b87
3 changed files with 95 additions and 0 deletions

22
.dockerignore Normal file
View file

@ -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

44
Dockerfile Normal file
View file

@ -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"]

29
docker-compose.yml Normal file
View file

@ -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"