FROM python:3.11-alpine
WORKDIR /usr/src/app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Copy only requirements first to leverage Docker cache
COPY requirements.txt .
# Install system dependencies and Python packages in a single layer
RUN apk update \
&& apk add --no-cache \
nano \
gobject-introspection-dev \
pango-dev \
cairo-dev \
libffi-dev \
libmagic \
libxml2-dev \
libxslt-dev \
&& python -m pip install --upgrade pip \
&& pip install -r requirements.txt
# Copy the rest of the application
COPY . .
RUN cp .env.dev.sample .env \
&& chmod +x entrypoint.prod.sh
ENV APP_HOME=/usr/src/app
# No need to create directories twice
RUN mkdir -p $APP_HOME/staticfiles \
&& mkdir -p $APP_HOME/mediafiles
RUN echo "Running from production dockerfile"
# Collect static files
RUN python manage.py collectstatic --noinput
CMD ["sh", "entrypoint.prod.sh"]