Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
199 lines (185 loc) · 8.02 KB
/
Copy pathDockerfile
File metadata and controls
199 lines (185 loc) · 8.02 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
# Use Ubuntu base (required for Camoufox/Playwright dependencies)
FROM lscr.io/linuxserver/baseimage-ubuntu:jammy
ENV PUID=99 \
PGID=100 \
UMASK=002
# Layer 1: System dependencies (rarely changes)
# Single layer to avoid file duplication across layers
RUN apt-get update && apt-get install -y --no-install-recommends \
# Python build tools
python3 \
python3-pip \
python3-dev \
gcc \
g++ \
make \
git \
# Playwright/Browser dependencies
wget \
curl \
ca-certificates \
fonts-liberation \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libatspi2.0-0 \
libcups2 \
libdbus-1-3 \
libdrm2 \
libgbm1 \
libgtk-3-0 \
libnspr4 \
libnss3 \
libwayland-client0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxkbcommon0 \
libxrandr2 \
xvfb \
# RYM metadata dependencies
libxml2-dev \
libxslt-dev \
zlib1g-dev \
# Audio validation tools
flac \
ffmpeg \
# Permission handling
gosu \
# Cron for scheduling
cron \
&& rm -rf /var/lib/apt/lists/*
# Layer 2: Python dependencies only (rebuilds when pyproject.toml/uv.lock changes)
# Copy only dependency declarations, not the entire codebase
COPY pyproject.toml uv.lock /app/
RUN ln -s /usr/bin/python3 /usr/bin/python && \
pip3 install --no-cache-dir uv && \
cd /app && \
uv export --locked --no-dev --no-emit-project --no-hashes -o requirements.txt && \
uv pip install --system --no-cache -r requirements.txt
# Layer 3: Install Camoufox packages and download browserforge data (browser/GeoIP downloaded at runtime)
RUN pip3 install --no-cache-dir "camoufox[geoip]==0.4.11" "playwright==1.59.0" && \
python3 -m browserforge update && \
chmod -R a+rwX /usr/local/lib/python3.*/dist-packages/browserforge 2>/dev/null || true && \
chmod -R a+rwX /usr/local/lib/python3.*/dist-packages/camoufox 2>/dev/null || true && \
pip3 cache purge && \
find /usr/local/lib/python3.*/dist-packages -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true && \
find /usr/local/lib/python3.*/dist-packages -type f -name "*.pyc" -delete 2>/dev/null || true
# Layer 4: Streamrip code (changes frequently, rebuilds quickly)
COPY . /app/
RUN cd /app && \
uv pip install --system --no-cache --no-deps . && \
# Ensure browserforge/camoufox files are readable+writable after streamrip install (for GeoIP download)
chmod -R a+rwX /usr/local/lib/python3.*/dist-packages/browserforge 2>/dev/null || true && \
chmod -R a+rwX /usr/local/lib/python3.*/dist-packages/camoufox 2>/dev/null || true && \
# Cleanup build dependencies to reduce image size
apt-get purge -y gcc g++ python3-dev libxml2-dev libxslt-dev && \
apt-get autoremove -y && \
rm -rf /tmp/* /root/.cache /var/lib/apt/lists/*
# Layer 5: Runtime configuration
# Save the real rip binary and create wrapper for permission handling
RUN mv /usr/local/bin/rip /usr/local/bin/rip.bin && \
printf '%s\n' \
'#!/bin/bash' \
'set -e' \
'export HOME=/config' \
'cd /downloads' \
'exec gosu ${PUID:-99}:${PGID:-100} env HOME=/config /usr/local/bin/rip.bin "$@"' \
> /usr/local/bin/rip && \
chmod +x /usr/local/bin/rip
# Create rym-tag wrapper that reads proxy config from streamrip config
RUN mv /usr/local/bin/rym-tag /usr/local/bin/rym-tag.bin && \
printf '%s\n' \
'#!/bin/bash' \
'set -e' \
'export HOME=/config' \
'' \
'# Helper function to extract config value from [rym.config] section' \
'get_config_value() {' \
' local key="$1"' \
' # Extract entire [rym.config] section (from [rym.config] to next [ or end of file)' \
' local value=$(sed -n '"'"'/^\[rym\.config\]/,/^\[/p'"'"' "$CONFIG_FILE" | grep "^$key" | awk -F"\"" '"'"'{print $2}'"'"')' \
' # If no quoted value, try unquoted (for booleans and numbers)' \
' if [ -z "$value" ]; then' \
' value=$(sed -n '"'"'/^\[rym\.config\]/,/^\[/p'"'"' "$CONFIG_FILE" | grep "^$key" | sed '"'"'s/^[^=]*=[[:space:]]*\([^#]*\)/\1/'"'"' | sed '"'"'s/[[:space:]]*$//'"'"')' \
' fi' \
' echo "$value"' \
'}' \
'' \
'# Read proxy config from streamrip config.toml if it exists' \
'CONFIG_FILE="/config/.config/streamrip/config.toml"' \
'if [ -f "$CONFIG_FILE" ]; then' \
' PROXY_ENABLED=$(get_config_value "proxy_enabled")' \
' if [ "$PROXY_ENABLED" = "true" ]; then' \
' export PROXY_HOST=$(get_config_value "proxy_host")' \
' export PROXY_PORT=$(get_config_value "proxy_port")' \
' export PROXY_USERNAME=$(get_config_value "proxy_username")' \
' export PROXY_PASSWORD=$(get_config_value "proxy_password")' \
' fi' \
' # Read Groq API key for LLM matching fallback' \
' GROQ_KEY=$(get_config_value "groq_api_key")' \
' if [ -n "$GROQ_KEY" ]; then' \
' export GROQ_API_KEY="$GROQ_KEY"' \
' fi' \
'fi' \
'' \
'cd /downloads' \
'exec gosu ${PUID:-99}:${PGID:-100} env HOME=/config PROXY_HOST="$PROXY_HOST" PROXY_PORT="$PROXY_PORT" PROXY_USERNAME="$PROXY_USERNAME" PROXY_PASSWORD="$PROXY_PASSWORD" GROQ_API_KEY="$GROQ_API_KEY" /usr/local/bin/rym-tag.bin "$@"' \
> /usr/local/bin/rym-tag && \
chmod +x /usr/local/bin/rym-tag
# Camoufox setup script - runs on container start before rip
RUN mkdir -p /etc/cont-init.d && \
printf '%s\n' \
'#!/usr/bin/with-contenv bash' \
'set -e' \
'' \
'if [ ! -d "/config/.cache/camoufox" ] || [ -z "$(ls -A /config/.cache/camoufox 2>/dev/null)" ]; then' \
' echo "================================================"' \
' echo "[Camoufox Setup] First run detected!"' \
' echo "[Camoufox Setup] Downloading browser binaries and GeoIP data (~2.8GB)"' \
' echo "[Camoufox Setup] This will take 2-5 minutes depending on your connection..."' \
' echo "================================================"' \
' ' \
' export HOME=/config' \
' python3 -m camoufox fetch' \
' ' \
' chown -R ${PUID}:${PGID} /config/.cache 2>/dev/null || true' \
' ' \
' echo "================================================"' \
' echo "[Camoufox Setup] Download complete!"' \
' echo "[Camoufox Setup] Browser cache stored in /config/.cache/camoufox"' \
' echo "================================================"' \
'else' \
' echo "[Camoufox Setup] Browser cache found at /config/.cache/camoufox, skipping download"' \
'fi' \
> /etc/cont-init.d/10-setup-camoufox && \
chmod +x /etc/cont-init.d/10-setup-camoufox
# single job script used both at startup and daily; imports env via s6
RUN mkdir -p /etc/periodic/daily && \
printf '%s\n' \
'#!/usr/bin/with-contenv bash' \
'set -e' \
'export HOME=/config' \
'/usr/local/bin/rip url https://tidal.com/my-collection/albums https://tidal.com/my-collection/artists https://tidal.com/my-collection/tracks https://play.qobuz.com/user/library/favorites/albums https://play.qobuz.com/user/library/favorites/artists https://play.qobuz.com/user/library/favorites/tracks' \
'date' \
> /etc/periodic/daily/rip-tidal && \
chmod +x /etc/periodic/daily/rip-tidal
# run once on container start (after camoufox setup)
RUN ln -s /etc/periodic/daily/rip-tidal /etc/cont-init.d/99-run-rip-once
# cron setup (4 AM EDT daily) - Ubuntu uses /etc/cron.d/
RUN printf '%s\n' \
'0 4 * * * root /etc/periodic/daily/rip-tidal' \
> /etc/cron.d/rip-tidal && \
chmod 0644 /etc/cron.d/rip-tidal
# s6 service keeps cron in foreground (container stays alive)
RUN mkdir -p /etc/services.d/crond && \
printf '%s\n' \
'#!/usr/bin/with-contenv bash' \
'exec cron -f' \
> /etc/services.d/crond/run && \
chmod +x /etc/services.d/crond/run
# Set runtime HOME to /config for user access to cached browser
ENV HOME=/config
VOLUME /config /downloads /library
WORKDIR /downloads
# no CMD (LSIO uses /init)