Internal
Public Access
Add Docker deployment configuration
- Add Dockerfile for production (multi-stage build) - Add Dockerfile.dev for development with hot reload - Add docker-compose.yml with 5 services (web, mariadb, redis, celery-worker, celery-beat) - Add docker-compose.dev.yml for development overrides - Add .dockerignore for optimized builds - Add docker/entrypoint.sh startup script - Add .env.docker.example template - Add Makefile for common commands - Add deploy.sh for one-command deployment - Update config/settings/selfhosted.py to support MariaDB via DATABASE_URL - Add mysqlclient to requirements.txt for MariaDB support - Update .gitignore to exclude .env.docker 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.5
parent
a2097dcad3
commit
71399e54b8
+65
@@ -0,0 +1,65 @@
|
||||
# ===================================================================
|
||||
# Stage 1: Builder - Install dependencies
|
||||
# ===================================================================
|
||||
FROM python:3.12-slim-bookworm AS builder
|
||||
|
||||
# Install build dependencies for mysqlclient and other packages
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
gcc \
|
||||
default-libmysqlclient-dev \
|
||||
pkg-config \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Python dependencies
|
||||
COPY requirements.txt /tmp/
|
||||
RUN pip install --user --no-cache-dir -r /tmp/requirements.txt \
|
||||
&& pip install --user --no-cache-dir mysqlclient gunicorn
|
||||
|
||||
# ===================================================================
|
||||
# Stage 2: Runtime - Minimal production image
|
||||
# ===================================================================
|
||||
FROM python:3.12-slim-bookworm
|
||||
|
||||
# Install runtime dependencies only
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
default-mysql-client \
|
||||
curl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create django user (non-root for security)
|
||||
RUN useradd -m -u 1000 -s /bin/bash django
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy Python dependencies from builder stage
|
||||
COPY --from=builder /root/.local /home/django/.local
|
||||
|
||||
# Copy application code
|
||||
COPY --chown=django:django . /app/
|
||||
|
||||
# Create directories for media and static files
|
||||
RUN mkdir -p /app/media /app/staticfiles && \
|
||||
chown -R django:django /app/media /app/staticfiles
|
||||
|
||||
# Switch to django user
|
||||
USER django
|
||||
|
||||
# Add .local/bin to PATH for installed packages
|
||||
ENV PATH=/home/django/.local/bin:$PATH
|
||||
|
||||
# Set Python to run in unbuffered mode (better for Docker logs)
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# Expose port 8000 for Gunicorn
|
||||
EXPOSE 8000
|
||||
|
||||
# Health check - ping the API endpoint
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
||||
CMD curl -f http://localhost:8000/api/ || exit 1
|
||||
|
||||
# Entrypoint script handles migrations, static collection, and service startup
|
||||
ENTRYPOINT ["/app/docker/entrypoint.sh"]
|
||||
|
||||
# Default command is to run Gunicorn
|
||||
CMD ["gunicorn"]
|
||||
Reference in New Issue
Block a user