-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (43 loc) · 1.38 KB
/
Dockerfile
File metadata and controls
57 lines (43 loc) · 1.38 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
FROM python:3.11-slim
WORKDIR /app
# Install system dependencies in a single layer
RUN apt-get update && apt-get install -y \
libmagic1 \
libmagic-dev \
libpq-dev \
gcc \
g++ \
curl \
build-essential \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Install UV
RUN pip install --no-cache-dir uv
# Create non-root user early
RUN useradd --create-home --shell /bin/bash --uid 1000 app
# Copy dependency files with proper ownership
COPY --chown=app:app pyproject.toml uv.lock* ./
# Before creating the venv, ensure clean state
RUN rm -rf .venv || true
RUN uv venv .venv
# Install dependencies using UV
RUN uv sync --frozen && \
uv cache clean
# Copy application code with proper ownership
COPY --chown=app:app . .
# Switch to non-root user
USER app
# Create cache directory for HuggingFace models
RUN mkdir -p /home/app/.cache/huggingface
# Set environment variables for better Python performance in containers
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV TOKENIZERS_PARALLELISM=false
ENV HF_HOME=/home/app/.cache/huggingface
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Run the application (remove --reload for production)
CMD ["uv", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]