Files
music-mirror/Dockerfile
T
Emma ThorpeandClaude Opus 5 c63115f246
Build and publish container / build (pull_request) Successful in 7m41s
feat: level the mirror's volume with ReplayGain tags
Rockbox applies the offset a ReplayGain tag carries but has no loudness
analysis of its own, so an untagged mirror plays every album at whatever
level it was mastered to.

Albums are measured with rsgain once their tracks are in place, album gain
and track gain both, leaving the device to choose between them. An album is
re-measured as a whole whenever it gains, loses or replaces a track, because
album gain is a property of all of its tracks and one new track makes the
value stored on every sibling wrong.

rsgain runs with --preserve-mtimes. Staleness here is an mtime comparison
and tagging rewrites the file, so without it every levelled track would look
newer than its source and the next pass would re-encode the whole library.

Whether a file has already been levelled is decided by walking its ID3v2
frame headers and seeking over the bodies. Cover art is embedded in every
mirror file, so reading the tag whole would turn an idle pass into a full
read of the library.

A missing rsgain is reported and then left alone rather than failing the
pass: the mirror is still correct audio in the right place.

Two existing tests move with the change. ffprobe's csv writer renders the
ReplayGain side data as a trailing empty field, and a copied MP3 now differs
from its source in the container while carrying identical audio.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-28 16:49:37 +01:00

39 lines
1.5 KiB
Docker

# Alpine rather than Debian slim purely because of ffmpeg's dependencies.
# Debian's ffmpeg depends on libavdevice, which can render to X11, Wayland and
# OpenGL, so it drags in Mesa and with it LLVM (127 MB) and Z3 (27 MB) to
# encode an MP3 on a headless NAS. Alpine's build brings none of that: 576 MB
# down to 189 MB.
FROM python:3.13-alpine AS runtime
ENV PYTHONUNBUFFERED=1
# ffmpeg does the encoding and rsgain the volume levelling; the application
# itself has no Python dependencies. rsgain lives in the community repository,
# which the official Python images already have enabled.
RUN apk add --no-cache ffmpeg rsgain
WORKDIR /app
COPY pyproject.toml README.md ./
COPY music_mirror.py ./
RUN pip install --no-cache-dir . \
&& rm -rf build music_mirror.egg-info
# Runs as root by default so a bind-mounted dataset of any ownership is
# writable. Override with `user:` in compose to run as the dataset's owner.
ENTRYPOINT ["music-mirror"]
# Test stage: the suite runs against this image's own ffmpeg, which is the one
# that ships. Build it with `--target test`; a failing test fails the build.
# The published image is the `runtime` stage above and carries none of this.
FROM runtime AS test
RUN pip install --no-cache-dir pytest
# sync-to-ipod.sh and its tests need these; the runtime image deliberately does
# not carry them, and neither does the base.
RUN apk add --no-cache bash rsync findmnt
COPY pytest.ini ./
# Host-side tools; not in the runtime image, but the suite covers them.
COPY tools ./tools
COPY tests ./tests
RUN python -m pytest