File size: 1,407 Bytes
24e6f5b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddde0db
24e6f5b
 
 
 
 
 
 
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
# Stage 1: Build Frontend
FROM node:20-alpine AS frontend-builder
WORKDIR /app/frontend

# Copy frontend dependency files
COPY frontend/package.json frontend/package-lock.json ./
RUN npm install

# Copy frontend source and build
COPY frontend/ ./
RUN npm run build

# Stage 2: Build Backend
FROM python:3.11-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /app

# Install system dependencies (including OpenCV requirement)
RUN apt-get update && apt-get install -y \
    build-essential \
    gcc \
    python3-dev \
    libffi-dev \
    libgl1 \
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# Install python dependencies
COPY backend/requirements.txt /app/
RUN pip install --upgrade pip && pip install -r requirements.txt

# Copy backend project files
COPY backend/ /app/

# Copy frontend build artifacts from Stage 1
# This matches STATICFILES_DIRS logic in settings.py
COPY --from=frontend-builder /app/frontend/dist /app/frontend_build

# Final system preparation
RUN mkdir -p /app/staticfiles

# Collect static files
# (Needs dummy secret key for collectstatic to run in build time if not provided)
RUN SECRET_KEY="build-time-dummy-key" python manage.py collectstatic --noinput

# Expose port
EXPOSE 7860

# Prepare start script
RUN sed -i 's/\r$//' /app/start.sh
RUN chmod +x /app/start.sh

# Run the backend start script
CMD ["/app/start.sh"]