-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile.backend
More file actions
executable file
·88 lines (68 loc) · 2.63 KB
/
Dockerfile.backend
File metadata and controls
executable file
·88 lines (68 loc) · 2.63 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
78
79
80
81
82
83
84
85
86
87
88
# ============================================
# TEST: Can we build without gcc/g++?
# This will fail if any package needs compilation
# ============================================
FROM python:3.11-slim AS builder
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
WORKDIR /build
# NO gcc/g++ installation - testing if wheels are enough
# (only install minimal utils if needed)
# Copy only files needed for package installation
COPY pyproject.toml /build/
COPY src /build/src
# Create virtual environment and install dependencies
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Upgrade pip and install (will fail if source compilation needed)
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir --only-binary=:all: . || \
(echo "ERROR: Some packages don't have wheels, need compilers" && exit 1)
# Install additional runtime dependencies
RUN pip install --no-cache-dir --only-binary=:all: \
pydantic-settings \
sqlalchemy \
alembic || \
(echo "ERROR: Runtime deps need compilers" && exit 1)
# SAFE cleanup
RUN find /opt/venv -type d -name "tests" -o -name "test" -o -name "__pycache__" | xargs rm -rf 2>/dev/null || true && \
find /opt/venv -type f \( -name "*.pyc" -o -name "*.pyo" \) -delete && \
find /opt/venv -type f \( -name "*.c" -o -name "*.pxd" -o -name "*.pyd" \) -delete
# ============================================
# Stage 2: Runtime - Minimal production image
# ============================================
FROM python:3.11-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1
WORKDIR /app
# Install ONLY runtime system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
sqlite3 \
poppler-utils \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /usr/share/doc/* \
&& rm -rf /usr/share/man/*
# Copy virtual environment from builder stage
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy only runtime-required application files
COPY backend /app/backend
COPY config /app/config
# Create data directory structure
RUN mkdir -p /app/backend/data/assets /app/backend/data/jobs
# Set working directory to backend app
WORKDIR /app/backend
# Copy migration entrypoint
COPY backend/docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
# Environment for lightweight cleanup
ENV EINK_CLEANUP_TTL_DAYS=14
EXPOSE 8000
# Run migrations via entrypoint, then start server
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]