diff --git a/Dockerfile b/Dockerfile index becd37f..e116b30 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,78 +1,62 @@ -# Multi-stage Dockerfile for Django application -# Stage 1: Builder stage - Install dependencies -FROM python:3.11-slim as builder +# Multi-stage Dockerfile for Django backend (zonco site API) +# - funzone-site/docker-compose.yml: dev (runserver + bind mount) +# - site_backend/docker-compose.yml: prod (gunicorn) + +FROM python:3.11-slim AS builder -# Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PIP_NO_CACHE_DIR=1 \ PIP_DISABLE_PIP_VERSION_CHECK=1 -# Install system dependencies required for building Python packages RUN apt-get update && apt-get install -y --no-install-recommends \ gcc \ postgresql-client \ libpq-dev \ && rm -rf /var/lib/apt/lists/* -# Create and set working directory WORKDIR /app -# Copy requirements file COPY requirements.txt . - -# Install Python dependencies RUN pip install --upgrade pip && \ pip install --user -r requirements.txt -# Stage 2: Production stage - Minimal runtime image FROM python:3.11-slim -# Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ - PATH="/home/django/.local/bin:$PATH" + PATH="/home/django/.local/bin:$PATH" \ + POSTGRES_HOST=db \ + POSTGRES_PORT=5432 \ + ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0,panel.zoneco.org -# Install runtime dependencies only RUN apt-get update && apt-get install -y --no-install-recommends \ postgresql-client \ libpq5 \ bash \ + curl \ && rm -rf /var/lib/apt/lists/* -# Create non-root user for security RUN groupadd -r django && useradd -r -g django django -# Create necessary directories RUN mkdir -p /app/staticfiles /app/media && \ chown -R django:django /app -# Set working directory WORKDIR /app -# Copy Python dependencies from builder stage COPY --from=builder /root/.local /home/django/.local +RUN chown -R django:django /home/django/.local -# Copy project files COPY --chown=django:django . . - -# Copy and set permissions for entrypoint script COPY --chown=django:django entrypoint.sh /app/entrypoint.sh RUN chmod +x /app/entrypoint.sh -# Switch to non-root user USER django -# Expose port EXPOSE 8000 -# Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ - CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/api/')" || exit 1 + CMD curl -f http://localhost:8000/api/ || exit 1 -# Use entrypoint script ENTRYPOINT ["/app/entrypoint.sh"] - -# Default command (can be overridden in docker-compose) CMD ["gunicorn", "zonco_backend.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "3", "--timeout", "120"] -