# Use a slim Python base image for a smaller image size
FROM python:3.11.8-slim

# Set environment variables to prevent Python from writing bytecode files
# and to ensure unbuffered output
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

# Set the working directory inside the container
WORKDIR /usr/src/app

# Install system dependencies
# This is a good practice as some Python libraries require them
RUN apt-get update && apt-get install -y \
    gcc \
    default-libmysqlclient-dev \
    pkg-config \
    netcat-traditional \
    && rm -rf /var/lib/apt/lists/*

# Copy the requirements file first to leverage Docker's caching
# This means if requirements.txt doesn't change, this layer is cached
COPY requirements.txt .
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Copy the entire Django project into the container
COPY . .

# Change the working directory to your Django project folder
# This makes it easier to run Django commands
WORKDIR /usr/src/app/RPS_project

# Create logs directory
RUN mkdir -p /var/log

# Expose port 8786 for the Gunicorn server (matching team leader's suggestion)
EXPOSE 8791

# The command to run the application using Gunicorn for production
# Note: This will be overridden by docker-compose command

# Use Daphne for ASGI (WebSockets + HTTP)
CMD ["daphne", "-b", "0.0.0.0", "-p", "8791", "RPS_project.asgi:application"]