-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (54 loc) · 2.12 KB
/
Copy pathDockerfile
File metadata and controls
68 lines (54 loc) · 2.12 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
ARG PYTHON_BASE_IMAGE=gcr.io/based-hardware-dev/python:3.11-slim-forky
ARG UV_VERSION=0.11.13
FROM ${PYTHON_BASE_IMAGE} AS builder
ARG UV_VERSION
RUN python -m venv /opt/venv
RUN python3 -m pip install --no-cache-dir "uv==${UV_VERSION}"
ENV PATH="/opt/venv/bin:$PATH"
# Install build dependencies for liblc3
RUN apt-get update && apt-get install -y \
git \
gcc \
g++ \
meson \
ninja-build \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
# Build liblc3 and create wheel
WORKDIR /tmp
RUN git clone https://github.com/google/liblc3.git && \
cd liblc3 && \
meson setup build && \
cd build && \
meson install && \
ldconfig && \
# Stage shared libs to a fixed path (meson install path varies by arch)
mkdir -p /opt/liblc3 && \
cp /usr/local/lib/*/liblc3.so* /opt/liblc3/ 2>/dev/null || \
cp /usr/local/lib/liblc3.so* /opt/liblc3/ && \
cd /tmp/liblc3 && \
python3 -m pip wheel --no-cache-dir --wheel-dir /tmp/wheels .
# Install Python requirements from the checked-in runtime lock.
WORKDIR /opt/venv
COPY backend/pylock.runtime.toml /tmp/pylock.runtime.toml
RUN uv pip sync /tmp/pylock.runtime.toml --python /opt/venv/bin/python --compile-bytecode
FROM ${PYTHON_BASE_IMAGE}
WORKDIR /app
ENV PATH="/opt/venv/bin:$PATH"
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
RUN apt-get update && apt-get -y install ffmpeg curl libjemalloc2 && rm -rf /var/lib/apt/lists/*
# jemalloc eliminates glibc malloc fragmentation that causes RSS to grow linearly
# under high-churn bytearray allocations from WebSocket audio streams (#6938)
# Use soname-only form so ld.so resolves via standard search paths (arch-portable)
ENV LD_PRELOAD=libjemalloc.so.2
# Copy compiled liblc3 library from builder staging dir
COPY --from=builder /opt/liblc3/ /usr/local/lib/
COPY --from=builder /tmp/wheels /tmp/wheels
# Install liblc3 Python package and set library path
RUN ldconfig && \
pip install --no-cache-dir /tmp/wheels/*.whl && \
rm -rf /tmp/wheels
COPY --from=builder /opt/venv /opt/venv
COPY backend/ .
EXPOSE 8080
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080", "--loop", "uvloop"]