FROM ubuntu:20.04 AS build

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    ca-certificates \
    cmake \
    git \
    libsqlite3-dev \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /src
COPY CMakeLists.txt ./
COPY src ./src

RUN cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF \
    && cmake --build build -j"$(nproc)"

FROM ubuntu:20.04 AS runtime

ENV DEBIAN_FRONTEND=noninteractive

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

WORKDIR /app

COPY --from=build /src/build/robot_app /app/robot_app
COPY www ./www

RUN mkdir -p data/maps data/sounds data/recordings

EXPOSE 8080

ENTRYPOINT ["/app/robot_app"]
CMD ["8080", "/app/www", "/app/data/RBS.db"]
