-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
52 lines (39 loc) Β· 1.45 KB
/
Copy pathDockerfile
File metadata and controls
52 lines (39 loc) Β· 1.45 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
# Stage 1: Dependencies
FROM python:3.11-slim as deps
# Install system dependencies required for building Python packages
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Stage 2: Application
FROM python:3.11-slim as runtime
WORKDIR /app
# Install system dependencies required for runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq5 \
curl \
postgresql-client \
redis-tools \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN adduser --disabled-password --gecos "" --no-create-home appuser
# Copy installed packages from deps stage
COPY --from=deps /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=deps /usr/local/bin /usr/local/bin
# Copy application code
COPY backend/ backend/
COPY app.py .
COPY scripts/ scripts/
# Make scripts executable
RUN chmod +x scripts/*.sh
# Create data directories
RUN mkdir -p /app/data /app/logs /app/backend/data/raw && chown -R appuser:appuser /app
USER appuser
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/api/v1/health')"
ENTRYPOINT ["./scripts/entrypoint.sh"]
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "2"]