FROM node:20-bookworm-slim AS webclient-builder
WORKDIR /webclient

COPY swingmusic-webclient/package.json swingmusic-webclient/package-lock.json ./
RUN npm ci

COPY swingmusic-webclient/ ./
RUN npm run build


FROM python:3.11-slim AS runtime
WORKDIR /app

LABEL "author"="swing music"

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    SWINGMUSIC_CLIENT_DIR=/app/client

EXPOSE 1970/tcp
VOLUME /music
VOLUME /config

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        build-essential \
        gcc \
        libev-dev \
        ffmpeg \
        libavcodec-extra \
        redis-tools \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Copy repo root files needed for installation
COPY pyproject.toml requirements.txt version.txt ./
COPY src/ ./src/

# Install the package and its dependencies
RUN pip install --no-cache-dir .

# Install Redis library for DragonflyDB support
RUN pip install --no-cache-dir redis

# Ship a deterministic web client with the backend image so startup does not
# depend on downloading release assets at runtime.
COPY --from=webclient-builder /webclient/dist /app/client

ENTRYPOINT ["python", "-m", "swingmusic", "--host", "0.0.0.0", "--config", "/config"]
