Skip to content

Commit 03bfd55

Browse files
committed
Refactor Dockerfile to use uv sync with upstream pyproject.toml
Replace fragile system site-packages copying with uv's native project management. The previous approach hardcoded Python paths which broke when packages installed to different locations. Changes: - Use uv sync with upstream pyproject.toml instead of uv pip install - Use venv at /app/.venv instead of copying system site-packages - Move tempio download to final stage where it's actually used
1 parent 7d0beab commit 03bfd55

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

isponsorblocktv/Dockerfile

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
# https://developers.home-assistant.io/docs/add-ons/configuration#add-on-dockerfile
22
ARG BUILD_FROM
3-
FROM $BUILD_FROM as compiler
4-
ARG TEMPIO_VERSION BUILD_ARCH
3+
FROM $BUILD_FROM AS builder
54

65
# renovate: datasource=github-releases depName=dmunozv04/iSponsorBlockTV
76
ARG ISPONSORBLOCKTV_VERSION=v2.6.1
87

9-
RUN curl -sSLf -o /usr/bin/tempio "https://github.com/home-assistant/tempio/releases/download/${TEMPIO_VERSION}/tempio_${BUILD_ARCH}"
10-
RUN apk add --no-cache uv git
11-
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy UV_PYTHON_DOWNLOADS=0
8+
RUN apk add --no-cache uv git gcc musl-dev
9+
1210
WORKDIR /app
13-
RUN git clone --branch ${ISPONSORBLOCKTV_VERSION} --depth 1 https://github.com/dmunozv04/iSponsorBlockTV /repo
14-
RUN cp -r /repo/src/* /app/ && cp /repo/requirements.txt /app/
15-
# Install build dependencies temporarily (needed for aiohttp), matching upstream approach
16-
RUN apk add --no-cache gcc musl-dev \
17-
&& uv pip install --system --index-strategy unsafe-best-match -r requirements.txt \
18-
&& apk del gcc musl-dev
19-
# TODO: we need the below as UV_COMPILE_BYTECODE=1 is not working as expected, remove once fixed
20-
RUN python3 -m compileall -b -f . && \
21-
find . -name "*.py" -type f -delete
11+
RUN git clone --branch ${ISPONSORBLOCKTV_VERSION} --depth 1 \
12+
https://github.com/dmunozv04/iSponsorBlockTV .
13+
14+
# uv sync reads pyproject.toml, creates .venv, installs all dependencies
15+
RUN uv sync --no-dev --no-editable --index-strategy unsafe-best-match
16+
17+
# Optional: compile bytecode for faster startup
18+
RUN uv run python -m compileall -b -f src \
19+
&& find src -name "*.py" -type f -delete
2220

2321
FROM $BUILD_FROM
24-
ENV iSPBTV_docker=True iSPBTV_data_dir=data TERM=xterm-256color COLORTERM=truecolor
22+
ARG TEMPIO_VERSION BUILD_ARCH
23+
24+
RUN curl -sSLf -o /usr/bin/tempio \
25+
"https://github.com/home-assistant/tempio/releases/download/${TEMPIO_VERSION}/tempio_${BUILD_ARCH}"
26+
27+
ENV iSPBTV_docker=True \
28+
iSPBTV_data_dir=data \
29+
TERM=xterm-256color \
30+
COLORTERM=truecolor \
31+
PATH="/app/.venv/bin:$PATH"
32+
2533
WORKDIR /app
26-
COPY --from=compiler /usr/bin/tempio /usr/bin/tempio
27-
COPY --from=compiler /app .
28-
COPY --from=compiler /usr/local/lib/python*/site-packages /usr/local/lib/python3.13/site-packages/
34+
COPY --from=builder /app/src ./
35+
COPY --from=builder /app/.venv ./.venv
2936
COPY rootfs/ /
3037

31-
# Healthcheck to verify the service is running
3238
HEALTHCHECK --interval=60s --timeout=10s --start-period=60s --retries=3 \
33-
CMD pgrep -f "python3.*main.pyc" > /dev/null || exit 1
39+
CMD pgrep -f "python3.*main.pyc" > /dev/null || exit 1

0 commit comments

Comments
 (0)