From 98cc088518970d4bb4e5e81080402f53b5544866 Mon Sep 17 00:00:00 2001 From: thecyberlearn Date: Fri, 5 Sep 2025 09:22:06 +0530 Subject: [PATCH] Fix Dokploy deployment 404 errors - Updated Dockerfile.dokploy with proper startup script - Added start-dokploy.sh for database migrations and health checks - Enhanced dokploy.json with required environment variables - Added debug Dockerfile for troubleshooting (Dockerfile.dokploy.debug) - Added debug config (dokploy.debug.json) for testing - Fixed static file collection and gunicorn configuration - Improved error handling and logging for deployment issues --- Dockerfile.dokploy | 9 ++++--- Dockerfile.dokploy.debug | 54 ++++++++++++++++++++++++++++++++++++++++ dokploy.debug.json | 15 +++++++++++ dokploy.json | 8 ++++-- start-dokploy.sh | 34 +++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 Dockerfile.dokploy.debug create mode 100644 dokploy.debug.json create mode 100755 start-dokploy.sh diff --git a/Dockerfile.dokploy b/Dockerfile.dokploy index 08a67ea..e42741f 100644 --- a/Dockerfile.dokploy +++ b/Dockerfile.dokploy @@ -20,10 +20,13 @@ ENV PYTHONUNBUFFERED=1 \ SECRET_KEY="build-time-dummy-key-change-in-production" # Collect static files -RUN python manage.py collectstatic --noinput +RUN python manage.py collectstatic --noinput --settings=netcop_hub.settings + +# Make startup script executable +RUN chmod +x start-dokploy.sh # Expose port 3000 for Dokploy EXPOSE 3000 -# Start gunicorn on port 3000 -CMD ["gunicorn", "netcop_hub.wsgi:application", "--bind", "0.0.0.0:3000"] \ No newline at end of file +# Use startup script +CMD ["./start-dokploy.sh"] diff --git a/Dockerfile.dokploy.debug b/Dockerfile.dokploy.debug new file mode 100644 index 0000000..678586f --- /dev/null +++ b/Dockerfile.dokploy.debug @@ -0,0 +1,54 @@ +FROM python:3.11-slim + +WORKDIR /app + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + gcc \ + libpq-dev \ + curl \ + && rm -rf /var/lib/apt/lists/* + +# Copy and install Python dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy application code +COPY . . + +# Set environment variables +ENV PYTHONUNBUFFERED=1 \ + DEBUG=true \ + SECRET_KEY="build-time-dummy-key-change-in-production" \ + ALLOWED_HOSTS="*" + +# Collect static files +RUN python manage.py collectstatic --noinput --settings=netcop_hub.settings || true + +# Make startup script executable +RUN chmod +x start-dokploy.sh + +# Expose port 3000 for Dokploy +EXPOSE 3000 + +# Debug: Print Django info +RUN python manage.py --version +RUN python manage.py check --settings=netcop_hub.settings || true + +# Start with debug info +CMD echo "🐛 Debug Mode - Django $(python manage.py --version)" && \ + echo "🔍 Environment:" && \ + echo " - DEBUG: $DEBUG" && \ + echo " - ALLOWED_HOSTS: $ALLOWED_HOSTS" && \ + echo " - SECRET_KEY: $(echo $SECRET_KEY | cut -c1-10)..." && \ + echo "🌐 Testing Django config..." && \ + python manage.py check --settings=netcop_hub.settings && \ + echo "✅ Django config OK" && \ + echo "🚀 Starting server..." && \ + gunicorn netcop_hub.wsgi:application \ + --bind 0.0.0.0:3000 \ + --workers 1 \ + --timeout 120 \ + --log-level debug \ + --access-logfile - \ + --error-logfile - diff --git a/dokploy.debug.json b/dokploy.debug.json new file mode 100644 index 0000000..ba94d54 --- /dev/null +++ b/dokploy.debug.json @@ -0,0 +1,15 @@ +{ + "name": "quantum-tasks-ai-debug", + "type": "dockerfile", + "dockerfile": "./Dockerfile.dokploy.debug", + "port": 3000, + "healthCheck": "/health/", + "buildArgs": {}, + "buildOptions": ["--no-cache"], + "env": { + "PYTHONUNBUFFERED": "1", + "DEBUG": "true", + "SECRET_KEY": "debug-key-change-in-production", + "ALLOWED_HOSTS": "*" + } +} diff --git a/dokploy.json b/dokploy.json index 26bb043..4846f31 100644 --- a/dokploy.json +++ b/dokploy.json @@ -3,9 +3,13 @@ "type": "dockerfile", "dockerfile": "./Dockerfile.dokploy", "port": 3000, + "healthCheck": "/health/", "buildArgs": {}, "buildOptions": ["--no-cache"], "env": { - "PYTHONUNBUFFERED": "1" + "PYTHONUNBUFFERED": "1", + "DEBUG": "false", + "SECRET_KEY": "build-time-dummy-key-change-in-production", + "ALLOWED_HOSTS": "*" } -} \ No newline at end of file +} diff --git a/start-dokploy.sh b/start-dokploy.sh new file mode 100755 index 0000000..7fbf753 --- /dev/null +++ b/start-dokploy.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Dokploy startup script + +set -e # Exit on any error + +echo "🚀 Starting Quantum Tasks AI on Dokploy" +echo "=======================================" + +# Run database migrations +echo "📄 Running database migrations..." +python manage.py migrate --noinput + +# Create cache table if needed +echo "🗄️ Ensuring cache table exists..." +python manage.py createcachetable || true + +# Check if we can access the database +echo "🔍 Testing database connection..." +python manage.py check --database default + +# Start the application +echo "🌐 Starting gunicorn server on port 3000..." +echo "Health check endpoint: /health/" +echo "=======================================" + +exec gunicorn netcop_hub.wsgi:application \ + --bind 0.0.0.0:3000 \ + --workers 2 \ + --timeout 120 \ + --max-requests 1000 \ + --preload \ + --log-level info \ + --access-logfile - \ + --error-logfile -