Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
230 lines (201 loc) · 11.1 KB
/
Copy pathDockerfile
File metadata and controls
230 lines (201 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# SoulSync WebUI Dockerfile
# Multi-architecture support for AMD64 and ARM64
FROM --platform=$BUILDPLATFORM node:24-slim AS webui-builder
WORKDIR /app/webui
COPY webui/package.json webui/package-lock.json ./
RUN npm ci
COPY webui/ ./
RUN npm run build
# Stage 1: Builder — install Python dependencies with compilation tools
FROM python:3.11-slim AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libc6-dev \
libffi-dev \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Create virtualenv and install dependencies
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# AI subtitles on an NVIDIA GPU (the :cuda tag): the cuBLAS and cuDNN 9 libraries
# for CUDA 12 that CTranslate2 needs, as pip wheels (~2 GB, so never in the
# default image). SoulSync loads them itself; no LD_LIBRARY_PATH needed.
# docker build --build-arg WHISPER_CUDA=1 -t soulsync:cuda .
# then run with --gpus all (the NVIDIA container toolkit on the host).
ARG WHISPER_CUDA=0
RUN if [ "$WHISPER_CUDA" = "1" ]; then \
pip install --no-cache-dir nvidia-cublas-cu12 "nvidia-cudnn-cu12==9.*"; \
fi
# yt-dlp must track YouTube faster than its stable channel ships — stable can
# lag months behind a breaking YouTube change while extraction is broken
# ("Requested format is not available"). Build images with the NIGHTLY channel.
# COMMIT_SHA is referenced in the RUN so CI's layer cache (cache-from: gha)
# busts on every new commit — otherwise this layer could pin a stale "nightly"
# for months, silently defeating its purpose.
ARG COMMIT_SHA=""
RUN echo "yt-dlp nightly for build ${COMMIT_SHA}" && \
pip install --no-cache-dir -U --pre "yt-dlp[default]"
# Stage 2: Runtime — only runtime dependencies, no build tools
FROM python:3.11-slim
# Install runtime-only system dependencies (no gcc/build tools).
# unzip is needed by the Deno installer below.
# flac: the Corrupt File Detector's preferred decode test (`flac -t` also
# verifies the STREAMINFO MD5 — catches damage that still decodes; #1000).
# rubberband-cli: sample studio renders saved chops with it. without it the
# pitch/tempo falls back to librosa, which smears drum hits.
# libarchive-tools: bsdtar, for the RAR/7z subtitle archives subsource still
# serves (zip is read in python; without bsdtar a RAR is just a miss).
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
gosu \
ffmpeg \
flac \
libarchive-tools \
libchromaprint-tools \
rubberband-cli \
sqlite3 \
unzip \
&& rm -rf /var/lib/apt/lists/*
# GPU video conversion for the player (free drivers from Debian main only).
# ffmpeg above already has nvenc, vaapi and qsv built in; these are the
# user-space drivers it needs to reach the card through /dev/dri:
# mesa-va-drivers AMD (and other mesa GPUs) over VA-API, amd64 + arm64
# intel-media-va-driver Intel Broadwell and newer over VA-API (amd64)
# i965-va-driver older Intel (Sandy Bridge to Coffee Lake) (amd64)
# libmfx-gen1.2 Intel Quick Sync runtime, Tiger Lake and newer (amd64)
# vainfo `docker exec soulsync-webui vainfo` shows what the card offers
# NVIDIA needs nothing here: the nvidia container runtime mounts its driver
# (see docker-compose.yml). about 60 MB on amd64, mostly mesa and the intel
# driver. the free intel driver leaves out some shader kernels, so a few
# older Intel chips decode but can't encode on it; build with
# --build-arg INTEL_NONFREE=1 for Debian's non-free driver instead.
ARG INTEL_NONFREE=0
RUN set -e; \
PKGS="mesa-va-drivers vainfo"; \
if [ "$(dpkg --print-architecture)" = "amd64" ]; then \
if [ "$INTEL_NONFREE" = "1" ]; then \
sed -i 's/^Components: main$/Components: main non-free non-free-firmware/' /etc/apt/sources.list.d/debian.sources; \
PKGS="$PKGS intel-media-va-driver-non-free"; \
else \
PKGS="$PKGS intel-media-va-driver"; \
fi; \
PKGS="$PKGS i965-va-driver libmfx-gen1.2"; \
fi; \
apt-get update && apt-get install -y --no-install-recommends $PKGS && \
rm -rf /var/lib/apt/lists/*
# Deno — JavaScript runtime for yt-dlp. YouTube gates its downloadable formats
# behind JS challenges (nsig); without a JS runtime, yt-dlp's extraction is
# deprecated and streams / music-video downloads fail with "Requested format
# is not available". Deno is yt-dlp's default-enabled runtime; the official
# installer auto-detects amd64/arm64. `deno --version` fails the build early
# if the install ever breaks.
RUN curl -fsSL https://deno.land/install.sh | DENO_INSTALL=/usr/local sh && \
deno --version
# Copy pre-built virtualenv from builder
COPY --from=builder /opt/venv /opt/venv
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Set working directory
WORKDIR /app
# Create non-root user for security
RUN useradd --create-home --shell /bin/bash --uid 1000 soulsync
# Build-time commit SHA for update detection.
# Placed here rather than at the top of this stage: the value changes on every
# commit, so every layer below it is rebuilt every build. Above the source COPY it
# costs nothing, since that COPY invalidates the rest anyway, and it leaves the
# venv copy, the apt install and the Deno install cacheable.
ARG COMMIT_SHA=""
ENV SOULSYNC_COMMIT_SHA=${COMMIT_SHA}
# Copy application code with ownership baked in.
# Using `COPY --chown` instead of `COPY` + `chown -R /app` avoids an
# extra image layer that duplicates the entire /app tree just to flip
# ownership bits — Docker layers are immutable, so chown -R rewrites
# every file into a new layer. On a clean repo that's small; if any
# bulky workspace file slips in (e.g. auto-downloaded ffmpeg binaries
# in tools/), it gets counted twice in the image. Cin caught this on
# 2026-05-08 — see the .dockerignore comment for the same incident.
COPY --chown=soulsync:soulsync . .
COPY --chown=soulsync:soulsync --from=webui-builder /app/webui/static/dist /app/webui/static/dist
# .br and .gz copies of every web UI text file (js, css, svg, json...), at max
# compression: the server sends them to browsers that take them, so the first
# load is about a fifth of the bytes. it runs by path and imports nothing from
# the app. the server ignores any copy older than its file, so a copy can't go
# stale
RUN python core/webui/precompress.py /app/webui/static
# Create runtime mount-point directories the app expects to exist.
# NOTE: /app/data is for database FILES, /app/database is the Python package
# NOTE: /app/Staging is required even though most users bind-mount it —
# the entrypoint mkdir runs early and is gated by `set -e`, so a missing
# pre-baked directory would crash the container into a restart loop on
# rootless Docker/Podman where in-container "root" can't write to /app.
# Pre-baking the dir here makes the entrypoint mkdir a guaranteed no-op.
# NOTE: /app/Stream is the transient single-file streaming cache used by
# the basic-search "Play" flow (cleared per use, never persistent). It's
# created lazily by `core/streaming/prepare.py` via `os.makedirs`, which
# fails silently on rootless Docker where the soulsync UID can't write
# to /app — playback then errors out with no obvious cause. Pre-baking
# at build time (when the layer is owned by root) avoids that path.
# NOTE: /app/storage is the PRIVATE album-bundle staging area for the
# torrent / usenet whole-release flow (download_source.album_bundle_staging_path
# defaults to 'storage/album_bundle_staging'). Like /app/Stream it's created
# lazily at runtime via mkdir(parents=True); without pre-baking it owned by
# soulsync, the album-bundle copy fails with "[Errno 13] Permission denied:
# 'storage'" because /app itself is root-owned and the soulsync UID can't
# create a top-level dir there.
# NOTE: /app/podcasts, /app/audiobooks and /app/Playlists are the default
# podcast, audiobook and playlist folders. not pre-baked, the first podcast
# download or playlist folder failed with permission denied (#2111).
RUN mkdir -p /app/config /app/data /app/logs /app/downloads /app/Transfer /app/Staging /app/Stream /app/storage /app/MusicVideos /app/scripts /app/podcasts /app/audiobooks /app/Playlists && \
chown soulsync:soulsync /app/config /app/data /app/logs /app/downloads /app/Transfer /app/Staging /app/Stream /app/storage /app/MusicVideos /app/scripts /app/podcasts /app/audiobooks /app/Playlists
# Create defaults directory and copy template files
# These will be used by entrypoint.sh to initialize empty volumes
RUN mkdir -p /defaults && \
cp /app/config/config.example.json /defaults/config.json && \
chmod 644 /defaults/config.json
# Create volume mount points
# NOTE: Changed /app/database to /app/data to avoid overwriting Python package
VOLUME ["/app/config", "/app/data", "/app/logs", "/app/downloads", "/app/Transfer", "/app/MusicVideos", "/app/scripts"]
# Copy and set up entrypoint script
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Note: Don't switch to soulsync user yet - entrypoint needs root to change UIDs
# The entrypoint script will switch to soulsync after setting up permissions
# Expose port
EXPOSE 8008
# Health check: /api/startup-status, a lightweight JSON endpoint, NOT / :
# rendering the index template on every probe was a steady idle-CPU cost
# (#1905). It is answered by wsgi's startup wrapper before any auth gate, so
# it is 200 in every auth mode, 200 while SoulSync is still starting (a big
# library's backup and upgrade can take a long while, and every other /api
# path answers 503 then, which marked the container unhealthy and got it
# restarted mid-upgrade by autoheal and friends), and 503 only when startup
# failed. Deliberate trade-off: this is a liveness probe (the process answers
# HTTP), it does not exercise template rendering.
# --max-time: Docker does not reliably kill a check that outruns --timeout, so
# a slow answer left one curl (and its connection) behind every 30s until the
# worker ran out of threads and file descriptors
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f --max-time 5 http://localhost:8008/api/startup-status || exit 1
# Set environment variables
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
ENV DATABASE_PATH=/app/data/music_library.db
# The video side's DB + its poster-asset store (assets.default_root derives from
# this path) MUST live in the persisted volume too — without it, every container
# recreate wiped video_library.db (watchlists, collections, overlays, issues,
# the YouTube ownership ledger).
ENV VIDEO_DATABASE_PATH=/app/data/video_library.db
# Same for audiobooks: without it database/audiobooks.db lived in the image
# layer and every recreate wiped the audiobook wishlist and download history.
ENV AUDIOBOOK_DATABASE_PATH=/app/data/audiobooks.db
# And the player's own db (watch progress, favorite channels, home layouts).
ENV PLAYER_DATABASE_PATH=/app/data/player.db
ENV PUID=1000
ENV PGID=1000
ENV UMASK=022
# Set entrypoint and default command
ENTRYPOINT ["/entrypoint.sh"]
CMD ["gunicorn", "-c", "gunicorn.conf.py", "wsgi:application"]