FROM rust:1.88-bookworm AS builder

WORKDIR /build

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        pkg-config \
        libudev-dev \
    && rm -rf /var/lib/apt/lists/*

COPY . /build

RUN cargo build --release -p aster-webui

FROM debian:bookworm-slim

ENV CONFIG_DIR=/config \
    PORT=8080 \
    ASTER_DEVICE=/dev/ttyACM0 \
    ASTER_USB= \
    ASTER_SIMULATE=0 \
    ASTER_WRITE_ONLY=0 \
    ASTER_DISABLE_DISPLAY=0

WORKDIR /app

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

COPY --from=builder /build/target/release/aster-webui /usr/local/bin/aster-webui
COPY container/entrypoint.sh /usr/local/bin/entrypoint.sh

RUN chmod 0755 /usr/local/bin/aster-webui /usr/local/bin/entrypoint.sh

EXPOSE 8080
VOLUME ["/config"]

CMD ["/usr/local/bin/entrypoint.sh"]
