dockerfile

This commit is contained in:
Ben Cherry
2025-08-12 21:42:00 -07:00
parent 83c1eb0069
commit 5a7c9c73d6
2 changed files with 64 additions and 70 deletions
+41 -13
View File
@@ -1,20 +1,48 @@
*.egg-info # Python bytecode and artifacts
__pycache__ __pycache__/
.pytest_cache *.py[cod]
.ruff_cache
.env
.env.*
.DS_Store
.idea
.venv
.vscode
*.pyc
*.pyo *.pyo
*.pyd *.pyd
*.egg-info/
dist/
build/
# Virtual environments
.venv/
venv/
# Caches and test output
.cache/
.pytest_cache/
.ruff_cache/
coverage/
# Logs and temp files
*.log
*.gz
*.tgz
.tmp
.cache
# Environment variables
.env
.env.*
# VCS, editor, OS
.git .git
.gitignore .gitignore
.gitattributes
.github/
.idea/
.vscode/
.DS_Store
# Project docs and misc
README.md README.md
LICENSE LICENSE
.github
tests/
# Project tests
test/
tests/
eval/
evals/
+23 -57
View File
@@ -1,77 +1,43 @@
# This sample Dockerfile creates a production-ready container for a LiveKit voice AI agent
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
# Use the official UV Python base image with Python 3.11 on Debian Bookworm ARG PYTHON_VERSION=3.11
# UV is a fast Python package manager that provides better performance than pip # Fast Python builds using uv on Debian bookworm-slim
# We use the slim variant to keep the image size smaller while still having essential tools FROM ghcr.io/astral-sh/uv:python${PYTHON_VERSION}-bookworm-slim AS base
FROM ghcr.io/astral-sh/uv:python3.11-bookworm-slim
# Keeps Python from buffering stdout and stderr to avoid situations where ARG UID=10001
# the application crashes without emitting any logs due to buffering.
# Ensures that logs are captured in realtime
ENV PYTHONUNBUFFERED=1 ENV PYTHONUNBUFFERED=1
# Define the program entrypoint file where your agent is started # Create unprivileged user
ARG PROGRAM_MAIN="src/agent.py"
ENV PROGRAM_MAIN=${PROGRAM_MAIN}
# Create a non-privileged user that the app will run under.
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
ARG UID=10001
RUN adduser \ RUN adduser \
--disabled-password \ --disabled-password \
--gecos "" \ --gecos "" \
--home "/home/appuser" \ --home "/app" \
--shell "/sbin/nologin" \ --shell "/sbin/nologin" \
--uid "${UID}" \ --uid "${UID}" \
appuser appuser
# Install build dependencies required for Python packages with native extensions # System build deps for common Python wheels
# gcc: C compiler needed for building Python packages with C extensions RUN apt-get update && apt-get install -y \
# python3-dev: Python development headers needed for compilation
# We clean up the apt cache after installation to keep the image size down
RUN apt-get update && \
apt-get install -y \
gcc \ gcc \
python3-dev \ python3-dev \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Set the working directory to the user's home directory WORKDIR /app
# This is where our application code will live
WORKDIR /home/appuser
# Copy all application files into the container # Dependency install first for better caching
# This includes source code, configuration files, and dependency specifications COPY pyproject.toml uv.lock ./
# (Excludes files specified in .dockerignore) RUN mkdir -p src
COPY . .
# Change ownership of all app files to the non-privileged user
# This ensures the application can read/write files as needed
RUN chown -R appuser:appuser /home/appuser
# Switch to the non-privileged user for all subsequent operations
# This improves security by not running as root
USER appuser
# Create a cache directory for the user
# This is used by UV and Python for caching packages and bytecode
RUN mkdir -p /home/appuser/.cache
# Install Python dependencies using UV's lock file
# --locked ensures we use exact versions from uv.lock for reproducible builds
# This creates a virtual environment and installs all dependencies
# Ensure your uv.lock file is checked in for consistency across environments
RUN uv sync --locked RUN uv sync --locked
# Pre-download any ML models or files the agent needs # Copy application code
# This ensures the container is ready to run immediately without downloading COPY . .
# dependencies at runtime, which improves startup time and reliability RUN chown -R appuser:appuser /app
RUN uv run "$PROGRAM_MAIN" download-files USER appuser
# Expose the healthcheck port # Pre-download models/assets at build time
# This allows Docker and orchestration systems to check if the container is healthy RUN uv run src/agent.py download-files
EXPOSE 8081
# Run the application using UV # Start the agent
# UV will activate the virtual environment and run the agent CMD ["uv", "run", "src/agent.py", "start"]
# The "start" command tells the worker to connect to LiveKit and begin waiting for jobs
CMD ["uv", "run", "$PROGRAM_MAIN", "start"]