# Multi-stage build for Django backend FROM python:3.11-slim as backend # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 # Set work directory WORKDIR /app # Install system dependencies RUN apt-get update \ && apt-get install -y --no-install-recommends \ postgresql-client \ build-essential \ libpq-dev \ && rm -rf /var/lib/apt/lists/* # Install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy project COPY . . # Create directories RUN mkdir -p /app/logs /app/media /app/staticfiles # Collect static files RUN python manage.py collectstatic --noinput # Expose port EXPOSE 8000 # Run the application CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "dubai_analytics.wsgi:application"] # Frontend build stage FROM node:18-alpine as frontend WORKDIR /app/frontend # Copy package files COPY frontend/package*.json ./ # Install dependencies RUN npm ci --only=production # Copy source code COPY frontend/ . # Build the application RUN npm run build # Production stage FROM nginx:alpine # Copy built frontend COPY --from=frontend /app/frontend/dist /usr/share/nginx/html # Copy nginx configuration COPY nginx.conf /etc/nginx/nginx.conf # Copy backend static files COPY --from=backend /app/staticfiles /usr/share/nginx/html/static EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]