mirror of
https://github.com/thecyberlearn/modern-django-starter.git
synced 2026-08-18 08:52:55 +00:00
Add simplified Dokploy configuration based on working quantum-digital project
Based on analysis of successfully deployed project: - Create docker-compose.dokploy-simple.yml with ports instead of expose - Remove complex Traefik labels (let Dokploy handle routing via Domain UI) - Hardcode environment variables in compose file - Run migrations in the command directly - Add Dockerfile.simple following their working multi-stage pattern - Includes Tailwind build and health check Use docker-compose.dokploy-simple.yml and configure domain via Dokploy UI
This commit is contained in:
parent
db923db446
commit
6185c25776
81
Dockerfile.simple
Normal file
81
Dockerfile.simple
Normal file
@ -0,0 +1,81 @@
|
||||
# Multi-stage Dockerfile for Django production deployment
|
||||
|
||||
# Build stage
|
||||
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
|
||||
RUN apt-get update && apt-get install -y \
|
||||
build-essential \
|
||||
libpq-dev \
|
||||
curl \
|
||||
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
|
||||
&& apt-get install -y nodejs \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create and set work directory
|
||||
WORKDIR /app
|
||||
|
||||
# Install Python dependencies
|
||||
COPY requirements/production.txt ./requirements/
|
||||
RUN pip install --no-cache-dir -r requirements/production.txt
|
||||
|
||||
# Production stage
|
||||
FROM python:3.11-slim
|
||||
|
||||
# Set environment variables
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
DJANGO_SETTINGS_MODULE=django_project.settings.production
|
||||
|
||||
# Install system dependencies for production
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libpq5 \
|
||||
curl \
|
||||
&& curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
|
||||
&& apt-get install -y nodejs \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create non-root user
|
||||
RUN groupadd -r django && useradd -r -g django django
|
||||
|
||||
# Set work directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy Python dependencies from builder stage
|
||||
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
|
||||
COPY --from=builder /usr/local/bin /usr/local/bin
|
||||
|
||||
# Copy project files
|
||||
COPY . .
|
||||
|
||||
# Install Tailwind and build CSS
|
||||
RUN DJANGO_SETTINGS_MODULE=django_project.settings.build python manage.py tailwind install
|
||||
RUN DJANGO_SETTINGS_MODULE=django_project.settings.build python manage.py tailwind build
|
||||
|
||||
# Create static and media directories
|
||||
RUN mkdir -p staticfiles media
|
||||
|
||||
# Collect static files
|
||||
RUN python manage.py collectstatic --noinput
|
||||
|
||||
# Change ownership to django user
|
||||
RUN chown -R django:django /app
|
||||
|
||||
# Switch to non-root user
|
||||
USER django
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8000
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD python -c "import requests; requests.get('http://localhost:8000/health/', timeout=10)" || exit 1
|
||||
|
||||
# Start server
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "--timeout", "120", "django_project.wsgi:application"]
|
||||
21
docker-compose.dokploy-simple.yml
Normal file
21
docker-compose.dokploy-simple.yml
Normal file
@ -0,0 +1,21 @@
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
ports:
|
||||
- "8000:8000"
|
||||
environment:
|
||||
- DEBUG=False
|
||||
- ALLOWED_HOSTS=dt.netcoptech.com,localhost,127.0.0.1
|
||||
- DATABASE_URL=${DATABASE_URL}
|
||||
- SECRET_KEY=${SECRET_KEY}
|
||||
- DJANGO_SETTINGS_MODULE=django_project.settings.production
|
||||
- CSRF_TRUSTED_ORIGINS=https://dt.netcoptech.com
|
||||
- SECURE_SSL_REDIRECT=True
|
||||
- GOOGLE_OAUTH2_CLIENT_ID=${GOOGLE_OAUTH2_CLIENT_ID:-demo-google-client-id}
|
||||
- GOOGLE_OAUTH2_CLIENT_SECRET=${GOOGLE_OAUTH2_CLIENT_SECRET:-demo-google-client-secret}
|
||||
command: >
|
||||
sh -c "python manage.py migrate &&
|
||||
python manage.py create_groups &&
|
||||
python manage.py setup_social_apps &&
|
||||
python manage.py collectstatic --noinput &&
|
||||
gunicorn --bind 0.0.0.0:8000 --workers 3 --timeout 120 django_project.wsgi:application"
|
||||
Loading…
Reference in New Issue
Block a user