diff --git a/Dockerfile.simple b/Dockerfile.simple new file mode 100644 index 0000000..8ffadb3 --- /dev/null +++ b/Dockerfile.simple @@ -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"] diff --git a/docker-compose.dokploy-simple.yml b/docker-compose.dokploy-simple.yml new file mode 100644 index 0000000..33c6470 --- /dev/null +++ b/docker-compose.dokploy-simple.yml @@ -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"