-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (46 loc) · 1.76 KB
/
Dockerfile
File metadata and controls
64 lines (46 loc) · 1.76 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
# Build static assets for UI
FROM node:24 as node-builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY ./web ./web
# Outputs files in web/dist/
RUN npm run build
# Used by both builder and soundbot
FROM python:3.14 as python-base
WORKDIR /app
# https://docs.python.org/3/using/cmdline.html
ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1
# Dependencies needed by discord.py for voice and python-ffmpeg
RUN apt-get update && apt-get install -y libffi-dev libnacl-dev ffmpeg
# Creates the virtual environment and wheel for soundbot
FROM python-base as python-builder
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
COPY pyproject.toml ./
COPY ./src ./src
# Build Python wheel in /app/dist/ and virtual environment in /app/.venv/
RUN uv venv .venv && \
uv pip install --python .venv/bin/python -e ".[unix]" && \
uv build
# Final image
FROM python-base as soundbot
# Node.js runtime required by yt-dlp for YouTube extraction
COPY --from=node-builder /usr/local/bin/node /usr/local/bin/node
COPY --from=node-builder /app/web/dist ./web/dist
# Templates are used at runtime by web server
COPY --from=node-builder /app/web/template ./web/template
COPY --from=python-builder /app/.venv ./.venv
COPY --from=python-builder /app/dist ./dist
# Install uv and the wheel built previously
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
RUN uv pip install --python .venv/bin/python ./dist/*.whl
# Update yt-dlp to latest version at build time
RUN ./.venv/bin/yt-dlp --update || true
# Run as non-root so bind-mounted host dirs (sounds/, config/) get the
# expected ownership (uid 1000) instead of root.
RUN useradd -u 1000 -m -s /bin/bash soundbot && \
chown -R soundbot:soundbot /app
USER soundbot
CMD ./.venv/bin/python -m soundbot