FROM python:3.11-slim-bullseye AS nasim_core
# Install system dependencies with retry logic
RUN apt-get update --fix-missing
RUN apt-get install apt-utils -y
RUN apt-get install build-essential -y
RUN apt-get install gcc -y
RUN apt-get install graphviz -y
RUN apt-get install graphviz-dev -y
RUN apt-get install vim -y
RUN apt-get install libmagickwand-dev -y
RUN apt-get install curl -y
RUN apt-get install iputils-ping -y
RUN apt-get install python3-dev -y
RUN apt-get install default-libmysqlclient-dev -y
RUN apt-get install pkg-config -y
RUN apt-get install libffi-dev -y
# Create and set work directory
RUN mkdir /opt/app && chown www-data:www-data /opt/app
WORKDIR /opt/app
COPY ./app/requirements.txt /opt/app
RUN pip install --upgrade pip
RUN pip install --upgrade -r requirements.txt --no-cache-dir
RUN pip install uwsgi
# Create logs directory and set permissions
RUN mkdir /opt/app/logs && touch /opt/app/logs/operation.log /opt/app/logs/system.log
RUN mkdir -p /opt/app/uploads/documents
RUN chmod -R 777 /opt/app/logs
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Copy project
COPY ./app /opt/app/
# Run Daphne
CMD ["uwsgi", "--http", "0.0.0.0:8000", "--module", "core.wsgi:application", "--master", "--processes", "4", "--threads", "4"]