-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
77 lines (54 loc) · 2.25 KB
/
Copy pathDockerfile
File metadata and controls
77 lines (54 loc) · 2.25 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
65
66
67
68
69
70
71
72
73
74
75
76
77
# =============================================================================
# Stage 1: Frontend Builder
# =============================================================================
FROM node:20-slim AS frontend-builder
WORKDIR /app/frontend
# Copy package files first for layer caching
COPY frontend/package.json frontend/package-lock.json ./
# Install dependencies
RUN npm ci
# Copy frontend source
COPY frontend/ ./
# Build the frontend with relative API path for production
ARG VITE_API_BASE_URL=/api
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
RUN npm run build
# =============================================================================
# Stage 2: Python Dependencies
# =============================================================================
FROM python:3.13-slim AS python-builder
WORKDIR /app
# Install UV
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Copy dependency files
COPY pyproject.toml uv.lock ./
# Install dependencies (without dev dependencies)
RUN uv sync --frozen --no-dev
# =============================================================================
# Stage 3: Production Runtime
# =============================================================================
FROM python:3.13-slim AS production
WORKDIR /app
# Copy UV from builder (useful for potential runtime commands)
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Copy virtual environment from python-builder
COPY --from=python-builder /app/.venv /app/.venv
# Copy dependency files (needed for uv to recognize the project)
COPY pyproject.toml uv.lock ./
# Copy application code
COPY backend/ ./backend/
# Copy built frontend assets
COPY --from=frontend-builder /app/frontend/dist ./frontend/dist
# Create data directories with proper permissions
RUN mkdir -p /app/backend/api/data/output && chmod -R 777 /app/backend/api/data
# Set environment variables
ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONPATH="/app"
ENV PYTHONUNBUFFERED=1
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
# Run the application
CMD ["uvicorn", "backend.api.app.main:app", "--host", "0.0.0.0", "--port", "8000"]