FinMK / Dockerfile
Kumar
Refactor: Achieve Perfect Deployment by standardizing on port 7860 and hardening security
ddde0db
# 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"]