# --- Etap 1: budowa panelu ---------------------------------------------------
FROM node:22-alpine AS frontend-build

WORKDIR /frontend

COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci

COPY frontend/ ./
RUN npm run build

# --- Etap 2: aplikacja -------------------------------------------------------
FROM python:3.13-slim

# Zależności systemowe: opus dla głosu, ffmpeg do dekodowania audio
RUN apt-get update && apt-get install -y \
    libopus0 \
    libopus-dev \
    ffmpeg \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Zależności przed źródłami, aby korzystać z cache warstw.
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .
COPY --from=frontend-build /frontend/dist /app/static

EXPOSE 8000

# Python serwuje API oraz zbudowany panel webowy.
CMD ["python", "-u", "main.py"]
