# Build stage
FROM rust:1.85-slim AS builder

WORKDIR /app
COPY Cargo.toml Cargo.lock ./
COPY src/ src/

RUN cargo build --release --locked

# Runtime stage
FROM debian:bookworm-slim

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

COPY --from=builder /app/target/release/telepi /usr/local/bin/telepi

# Create non-root user
RUN useradd -m -s /bin/bash telepi
USER telepi
WORKDIR /home/telepi

# Config directory
RUN mkdir -p /home/telepi/.pi/telepi

ENTRYPOINT ["telepi"]
CMD ["start"]
