Stage 1: Builder FROM python:3.13-slim AS builder ...
# ask-ai
r
# Stage 1: Builder FROM python:3.13-slim AS builder # Env variables ENV BINARY_INSTALL_PATH=/usr/local/bin # Install build dependencies RUN rm -rf /var/lib/apt/lists/* && \ apt-get update && \ apt-get install -y --no-install-recommends wget && \ apt-get install -y git # Create application user RUN groupadd --gid 3000 app && \ useradd --uid 10001 --gid 3000 --create-home app # Set environment variables ENV HOME=/home/app ENV PYTHONPATH=“/home/app/packages/chat/src/home/app/packages/fastapi app/src/home/app/packages/livekit_app/src:/home/app/packages/shared/src” WORKDIR /home/app # Add venv to path ENV VIRTUAL_ENV=/home/app/.venv ENV PATH=“/home/app/.venv/bin:$PATH” # UV installation and setup RUN wget -O install.sh https://astral.sh/uv/install.sh && env UV_UNMANAGED_INSTALL=“${BINARY_INSTALL_PATH}” sh install.sh RUN chmod +x ${BINARY_INSTALL_PATH}/uv # Copy dependency definition files COPY pyproject.toml uv.lock* ./ # Copy workspace packages so they can be installed by uv COPY packages ./packages # Use UV to install dependencies # This creates a cached layer for our dependencies RUN uv sync # Install LiveKit related dependencies like torch RUN uv pip install torch==2.7.0 torchvision==0.22.0 torchaudio==2.7.0 --index-url https://download.pytorch.org/whl/test/cpu # Copy over application files to container COPY --chown=app:app . . # Install LiveKit plugins RUN mv .env.example .env RUN uv run python -m livekit_app.livekit_worker download-files # Stage 2: Runtime FROM python:3.13-slim # Set non-root user RUN groupadd --gid 3000 app && \ useradd --uid 10001 --gid 3000 --create-home app USER app # Set environment variables ENV HOME=/home/app ENV BINARY_INSTALL_PATH=/usr/local/bin ENV PYTHONPATH=“/home/app/packages/chat/src/home/app/packages/fastapi app/src/home/app/packages/livekit_app/src:/home/app/packages/shared/src” ENV VIRTUAL_ENV=/home/app/.venv ENV PATH=“/home/app/.venv/bin:$PATH” # Set working directory WORKDIR /home/app # Copy Python dependencies from builder COPY --from=builder /home/app/.venv /home/app/.venv # Copy HuggingFace cache to main container # This is needed for LiveKit COPY --from=builder /home/app/.cache /home/app/.cache # Copy UV binary from builder step COPY --from=builder ${BINARY_INSTALL_PATH}/uv ${BINARY_INSTALL_PATH}/uv # Copy application code from builder COPY --from=builder --chown=app:app /home/app /home/app # Command to run the app CMD [“python”, “-m”, “livekit_app.livekit_worker”, “dev”] how to make the livekit docker build faster. most of the build time is spent on uv run python -m livekit_app.livekit_worker download-files
t
Thanks for reaching out, Oliver. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To speed up the LiveKit Docker build, especially during the
uv run python -m livekit_app.livekit_worker download-files
step, here are some friendly tips you might find helpful: • Leverage UV for Dependency Management: Try using
uv sync --locked
to make sure your dependencies install smoothly and consistently. • Pre-download Files: Including the
download-files
step right in the build process can save you from waiting later on. • Optimize Dockerfile Layers: Combining commands like
apt-get update
and
apt-get install
into one layer can really cut down build time. • Cache Dependencies: Setting up a cache directory for dependencies and making sure the ownership is correct can speed things up quite a bit. • Use a Minimal Base Image: Picking a lightweight base image like
<http://ghcr.io/astral-sh/uv:python3.11-bookworm-slim|ghcr.io/astral-sh/uv:python3.11-bookworm-slim>
helps keep your image size nice and small. Following these tips should make the build process smoother and reduce the time spent on that
download-files
step. If you have any questions or want to chat more about this, I’m here to help! Sources: taskfile.yaml