-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.api
More file actions
42 lines (31 loc) · 1.1 KB
/
Dockerfile.api
File metadata and controls
42 lines (31 loc) · 1.1 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
# Multi-stage build for optimized image size
FROM python:3.12-slim as builder
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies into user directory
COPY requirements.txt ./
COPY api/requirements.txt ./api/
RUN pip install --user --no-cache-dir -r requirements.txt -r api/requirements.txt
# Runtime stage
FROM python:3.12-slim
WORKDIR /app
# Copy installed packages from builder
COPY --from=builder /root/.local /root/.local
# Copy source code
COPY src/ src/
COPY api/ api/
# Set environment
ENV PATH=/root/.local/bin:$PATH
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV API_ENV=production
ENV LOG_LEVEL=info
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD python -c "import requests; requests.get('http://localhost:8000/health', timeout=2)" || exit 1
# Use enhanced main with production features
CMD ["python", "-m", "uvicorn", "api.main_enhanced:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]