# Afterglow, headless, for a NAS or any always-on Linux machine. See NAS.md.

# whisper.cpp, built natively: it makes subtitles from dialogue and hears lyrics.
FROM debian:bookworm-slim AS whisper
RUN apt-get update && apt-get install -y --no-install-recommends build-essential cmake git ca-certificates \
 && git clone --depth 1 --branch v1.7.5 https://github.com/ggml-org/whisper.cpp /src \
 && cmake -S /src -B /src/build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DWHISPER_BUILD_TESTS=OFF -DGGML_NATIVE=OFF \
 && cmake --build /src/build -j"$(nproc)" --target whisper-cli

FROM python:3.12-slim
COPY --from=whisper /src/build/bin/whisper-cli /usr/local/bin/whisper-cli

# ffmpeg plays and converts media; fpcalc (libchromaprint-tools) identifies music by how it sounds.
RUN apt-get update \
 && apt-get install -y --no-install-recommends ffmpeg libchromaprint-tools \
 && rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY setup.py /tmp/setup.py
RUN python /tmp/setup.py --destination /app
RUN rm -rf /app/server/tests

# /config keeps everything Afterglow learns and saves; /media is the library (mount your folders inside it).
ENV AFTERGLOW_HEADLESS=1 \
    AFTERGLOW_DATA_DIR=/config \
    AFTERGLOW_TOOLS_DIR=/config/tools \
    AFTERGLOW_LIBRARY=/media \
    PYTHONUNBUFFERED=1
VOLUME ["/config"]
EXPOSE 8765

CMD ["python", "/app/server/afterglow_server.py"]
