45 lines
1012 B
Docker
45 lines
1012 B
Docker
# Use Python 3.11 slim image
|
|
FROM python:3.11-slim
|
|
|
|
# Set environment variables
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
|
|
# 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 \
|
|
gettext \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install Python dependencies
|
|
COPY requirements.txt /app/
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Copy project
|
|
COPY . /app/
|
|
|
|
# Create directories for logs and media
|
|
RUN mkdir -p /app/logs /app/media /app/staticfiles
|
|
|
|
# Collect static files
|
|
RUN python manage.py collectstatic --noinput
|
|
|
|
# Create a non-root user
|
|
RUN adduser --disabled-password --gecos '' appuser
|
|
RUN chown -R appuser:appuser /app
|
|
USER appuser
|
|
|
|
# Expose port
|
|
EXPOSE 8000
|
|
|
|
# Run the application
|
|
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "gnxmail.wsgi:application"]
|