# WiFi-DensePose Rust Sensing Server
# Includes RuVector signal intelligence crates
# Multi-stage build for minimal final image

# Stage 1: Build
FROM rust:1.85-bookworm AS builder

WORKDIR /build

# Copy workspace files
COPY rust-port/wifi-densepose-rs/Cargo.toml rust-port/wifi-densepose-rs/Cargo.lock ./
COPY rust-port/wifi-densepose-rs/crates/ ./crates/

# Copy vendored RuVector crates
COPY vendor/ruvector/ /build/vendor/ruvector/

# Build release binary
RUN cargo build --release -p wifi-densepose-sensing-server 2>&1 \
    && strip target/release/sensing-server

# Stage 2: Runtime
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy binary
COPY --from=builder /build/target/release/sensing-server /app/sensing-server

# Copy UI assets
COPY ui/ /app/ui/

# HTTP API
EXPOSE 3000
# WebSocket
EXPOSE 3001
# ESP32 UDP
EXPOSE 5005/udp

ENV RUST_LOG=info

# CSI_SOURCE controls which data source the sensing server uses at startup.
# auto      — probe UDP port 5005 for an ESP32 first; fall back to simulation (default)
# esp32     — receive real CSI frames from an ESP32 device over UDP port 5005
# wifi      — use host Wi-Fi RSSI/scan data (Windows netsh; not available in containers)
# simulated — generate synthetic CSI frames (no hardware required)
# Override at runtime:  docker run -e CSI_SOURCE=esp32 ...
ENV CSI_SOURCE=auto

ENTRYPOINT ["/bin/sh", "-c"]
# Shell-form CMD allows $CSI_SOURCE to be substituted at container start.
# The ENV default above (CSI_SOURCE=auto) applies when the variable is unset.
CMD ["/app/sensing-server --source ${CSI_SOURCE} --tick-ms 100 --ui-path /app/ui --http-port 3000 --ws-port 3001"]
