Files
Scrobbler/docker/api.Dockerfile
T
mattandClaude Sonnet 5 83b27d7ba1
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 13s
CI / federation-interop (push) Successful in 1m39s
CI / test (push) Successful in 3m38s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / trigger-deploy (push) Skipped
CI / notify (push) Successful in 5s
Stop album art from blocking page loads
Root cause: gunicorn runs only 2 sync workers, and GET /api/v1/art/album
did its MusicBrainz + Cover Art Archive work synchronously inside the
request (2-12+ seconds per call, measured). A page with several
uncached albums could tie up the entire application - every endpoint,
every user - for as long as that took. Separately, even an
already-resolved album re-streamed its image bytes live from Cover
Art Archive on every single page view, by the original v1 design.

The endpoint is now cache-only: it reads the album_art table and, if
resolved, a local file, and never touches the network. A cache miss
records a "pending" row and returns 404 immediately - the frontend
already treats 404 as "show the placeholder," so no frontend changes
are needed. A new background worker task (the same claim-with-
FOR-UPDATE-SKIP-LOCKED pattern already used by imports and federation
deliveries) does the actual resolving and downloads the image bytes
to a shared volume, completely decoupled from any request. No
migration needed: AlbumArt.status just gains a new "pending" value.

Verified against the real docker compose stack (not just the test
suite): cold lookups for 5 real albums all returned 404 in well under
0.2s (previously 2-12+s each), the worker resolved all 5 within ~10s
in the background, and resolved art then served in single-digit
milliseconds from the volume, including after a full container
restart (no re-download).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011Hn2QwS1HRT8tFAzo8ew63
2026-10-06 21:27:50 +01:00

34 lines
1.4 KiB
Docker

# Scrobbler API: gunicorn serving the Flask app, metrics on :9100.
FROM ghcr.io/astral-sh/uv:0.7.21 AS uv
FROM python:3.13-slim AS build
COPY --from=uv /uv /usr/local/bin/uv
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy UV_PYTHON_DOWNLOADS=never
WORKDIR /app
COPY pyproject.toml uv.lock README.md ./
RUN uv sync --locked --no-dev --no-install-project
COPY src ./src
RUN uv sync --locked --no-dev --no-editable
FROM python:3.13-slim
LABEL org.opencontainers.image.licenses="BSD-3-Clause"
RUN useradd --system --uid 10001 --no-create-home scrobbler
# Downloaded album art lives here, on a volume shared with the worker (which writes it).
RUN mkdir -p /data/album-art && chown scrobbler:scrobbler /data/album-art
WORKDIR /app
COPY --from=build /app/.venv /app/.venv
COPY gunicorn.conf.py docker/api-entrypoint.sh ./
# PROMETHEUS_MULTIPROC_DIR is set by gunicorn.conf.py for the API only: prometheus_client
# enters multiprocess mode whenever it's set, which other commands (the worker) don't want.
ENV PATH=/app/.venv/bin:$PATH \
PYTHONUNBUFFERED=1 \
BIND=0.0.0.0:8000 \
METRICS_PORT=9100 \
OPENAPI_DOCS_ENABLED=1
USER scrobbler
EXPOSE 8000 9100
HEALTHCHECK --interval=15s --timeout=3s --start-period=20s \
CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/healthz', timeout=2)"
ENTRYPOINT ["./api-entrypoint.sh"]
CMD ["gunicorn", "-c", "gunicorn.conf.py"]