-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (49 loc) · 1.69 KB
/
Dockerfile
File metadata and controls
64 lines (49 loc) · 1.69 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
58
59
60
61
62
63
64
# ============================================
# Stage 1: Builder (Install dependencies)
# ============================================
FROM python:3.11-slim AS builder
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install uv for faster package installation
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Copy requirements
COPY requirements.txt .
# Install Python dependencies to /opt/venv
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN uv pip install --no-cache -r requirements.txt
# ============================================
# Stage 2: Runtime (Minimal final image)
# ============================================
FROM python:3.11-slim
WORKDIR /app
# Install ONLY runtime dependencies (no build tools)
RUN apt-get update && apt-get install -y \
curl \
libgomp1 \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Copy Python virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
# Copy ONLY application code (tests/docs excluded via .dockerignore)
COPY backend ./backend
COPY alembic ./alembic
COPY alembic.ini .
# Set Python path and use venv
ENV PYTHONPATH=/app
ENV PATH="/opt/venv/bin:$PATH"
# Run as non-root user for security
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser
# Expose the Render default web port
EXPOSE 10000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD sh -c 'curl -f http://localhost:${PORT:-10000}/api/v1/health || exit 1'
# Default command
CMD ["sh", "-c", "uvicorn backend.api.main:app --host 0.0.0.0 --port ${PORT:-10000}"]