Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
76 lines (55 loc) · 2.14 KB
/
Copy pathDockerfile
File metadata and controls
76 lines (55 loc) · 2.14 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
FROM python:3.11-slim AS builder
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /app
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends gcc libc-dev; \
rm -rf /var/lib/apt/lists/*
RUN python -m pip install --no-cache-dir --upgrade pip "setuptools>=84.1.0" "wheel>=0.46.2"
RUN python -m pip install --no-cache-dir --index-url https://download.pytorch.org/whl/cpu \
'torch<3' 'torchvision<1'
COPY pyproject.toml ./
COPY README.md ./
COPY backend/core/ ./backend/core/
COPY backend/domain/ ./backend/domain/
COPY backend/services/ ./backend/services/
COPY backend/ocr/ ./backend/ocr/
COPY backend/storage/ ./backend/storage/
COPY backend/handlers/ ./backend/handlers/
COPY backend/alembic/ ./backend/alembic/
COPY backend/alembic.ini ./backend/
COPY backend/config.py ./backend/
COPY bot.py ./
RUN python -m pip install --no-cache-dir --upgrade . \
&& python -m pip uninstall -y pip setuptools wheel
# Runtime stage: minimal runtime image
FROM python:3.11-slim AS runtime
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Apply OS security updates and remove base packaging tools/metadata from runtime image
RUN set -eux; \
apt-get update; \
apt-get upgrade -y; \
apt-get install -y --no-install-recommends tesseract-ocr tesseract-ocr-eng tesseract-ocr-rus; \
rm -rf /var/lib/apt/lists/*; \
rm -rf /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/ensurepip \
/usr/local/bin/pip* /usr/local/bin/wheel*
# Create non-root user
RUN useradd -m botuser
WORKDIR /app
# Copy installed Python packages from builder
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
COPY . /app
# Create data directory for SQLite database
RUN mkdir -p /app/data/huggingface
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
RUN chown -R botuser:botuser /app
USER botuser
ENV INVOICE_DB_PATH=../data.sqlite
ENV HF_HOME=/app/data/huggingface
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD python backend/healthcheck.py || exit 1
ENTRYPOINT ["/entrypoint.sh"]