-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.backend
74 lines (62 loc) · 2.07 KB
/
Dockerfile.backend
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
# Stage 1: Build dependencies
FROM python:3.10-slim-bullseye as builder
# Set environment variables
ENV PYTHONPATH=/app \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
DEBIAN_FRONTEND=noninteractive
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
python3-dev \
cmake \
poppler-utils \
tesseract-ocr \
tesseract-ocr-eng \
postgresql-client \
libpq-dev \
wget \
curl \
gfortran \
&& rm -rf /var/lib/apt/lists/*
# Create and activate virtual environment
WORKDIR /app
COPY requirements.txt .
# Create virtual environment and install dependencies
RUN python -m venv /opt/venv && \
. /opt/venv/bin/activate && \
pip install --upgrade pip setuptools wheel && \
# Install numpy and scikit-learn first with binary preference
pip install --prefer-binary \
numpy==1.24.3 \
scikit-learn==1.2.2 && \
# Install remaining requirements
pip install --prefer-binary -r requirements.txt
# Stage 2: Runtime
FROM python:3.10-slim-bullseye as runtime
# Set environment variables
ENV PYTHONPATH=/app \
PYTHONUNBUFFERED=1 \
PATH="/opt/venv/bin:$PATH"
# Install runtime dependencies only
RUN apt-get update && apt-get install -y --no-install-recommends \
poppler-utils \
tesseract-ocr \
tesseract-ocr-eng \
postgresql-client \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
# Set working directory and copy application code
WORKDIR /app
COPY . .
# Install wait-for-it script
ADD https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh /wait-for-it.sh
RUN chmod +x /wait-for-it.sh
# Set up health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Run the application
CMD ["/bin/sh", "-c", "/wait-for-it.sh postgres:5432 -t 60 -- /wait-for-it.sh redis:6379 -t 60 -- uvicorn app.main:app --host 0.0.0.0 --port 8000"]