-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.backend
More file actions
46 lines (31 loc) · 1.03 KB
/
Copy pathDockerfile.backend
File metadata and controls
46 lines (31 loc) · 1.03 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
# Stage 1: Builder
FROM python:3.12-slim AS builder
WORKDIR /app
# Install uv for faster dependency installation
RUN pip install uv
# Copy dependency files
COPY pyproject.toml uv.lock ./
# Create virtual environment and install dependencies
RUN uv sync --frozen --no-install-project
# Copy source code
COPY src/ ./src/
# Stage 2: Production
FROM python:3.12-slim AS production
WORKDIR /app
# Copy virtual environment from builder
COPY --from=builder /app/.venv /app/.venv
ENV PATH="/app/.venv/bin:$PATH"
# Create non-root user for security
RUN useradd -m -u 1000 appuser && \
mkdir -p /app/data_storage && \
chown -R appuser:appuser /app
USER appuser
ENV PYTHONPATH=/app
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import httpx; httpx.get('http://localhost:8000/health').raise_for_status()"
# Run the application
CMD ["python", "-m", "uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]