-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
45 lines (31 loc) · 1.52 KB
/
Dockerfile
File metadata and controls
45 lines (31 loc) · 1.52 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
# ---------------------------------------------------------------------------
# Stage 1: Build — install dependencies into a virtual environment
# ---------------------------------------------------------------------------
FROM python:3.12-slim AS builder
WORKDIR /app
# Install build tools
RUN pip install --upgrade pip setuptools wheel
COPY pyproject.toml ./
COPY src/ ./src/
# Install runtime dependencies only (no dev extras)
RUN pip install --no-cache-dir .
# ---------------------------------------------------------------------------
# Stage 2: Runtime — minimal final image
# ---------------------------------------------------------------------------
FROM python:3.12-slim AS runtime
# Create a non-root user for security
RUN useradd --create-home --shell /bin/bash appuser
WORKDIR /app
# Copy installed packages and application code from builder
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin/uvicorn /usr/local/bin/uvicorn
COPY --from=builder /app/src ./src
# The SQLite database file will be stored in a named volume
VOLUME ["/app/data"]
# Override the database path via environment variable
ENV DATABASE_URL="sqlite+aiosqlite:///./data/energy_assets.db"
USER appuser
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]