How mohanishkhatri/staging-server works
Project type and purpose
• This is a full-stack Django application (“Staging-Server”) whose job is to let developers spin up, configure, and test Docker containers on a staging subdomain. It provides a web GUI (HTML/CSS/JS), a REST/WSGI backend, asynchronous deployment via Celery, and configures Nginx dynamically.
File structure
• Top-level deploy files: Dockerfile, docker-compose.yml, deploy/*.sh, nginx/configs/*.conf
• Django project root:
• manage.py, stagingserver/ (settings, wsgi, asgi, celery, routing, middleware)
• apps: main/, repositories/, gitlab_social/ (models, views, services)
• static assets: assets/admin (Django admin CSS/JS), frontail (log viewer), xterm (web terminal)
• templates/ (HTML for UI)
• docs/ (setup & folder structure)
• Key patterns:
• Standard Django MVC (apps with models→views→templates)
• Celery for asynchronous tasks (stagingserver/celery.py)
• Django Channels/WebSockets for live logs and terminal (stagingserver/routing.py)
• Shell scripts for Nginx config management & container cleanup
Extract insights from the README
• Launch GUI to deploy any GIT repo as a Docker container
• Auto-generate Nginx vhost for each deployment
• Real-time logs (searchable) using frontail
• Interactive shell via xterm.js over WebSockets
• Asynchronous workflow (Celery)
• Environment variables, mounts, pre/post hooks
Main components & how they interact
a. Browser (User Interface)
• HTML templates + JS libraries (xterm.js, frontail)
• Communicates via HTTP(S) and WebSocket to the backend
b. Nginx
• Reverse proxy for the Django app and Channels (WS)
• Serves static files (admin CSS/JS, xterm.css, frontail CSS)
• Dynamically reloaded when new site vhosts are added/removed
c. Gunicorn (WSGI) / Daphne (ASGI)
• Hosts the Django application (stagingserver)
• ASGI server for Channels to support WebSockets
d. Django application
• URL routing (stagingserver/urls.py + app urls.py)
• Business logic in services.py for each app
• Models persisted in a relational database (SQLite in dev; env configurable)
e. Celery Worker + Message Broker
• Handles long-running container builds and deployments asynchronously
• Publishes task status back to Django for UI updates
f. Docker Engine
• Programmatically controlled by Django services to pull images, run containers, map ports, set env vars, mounts
g. Database
• Stores metadata: repositories, running instances, logs pointers, user data
h. External Git Repository
• Source of code to be deployed
i. Scripts & Automation
• Shell scripts under deploy/ and scripts/ for Nginx management and cleanup
Architectural patterns & design principles
• MVC (Django apps) with clear separation of models, views, templates
• Asynchronous task queue for non-blocking operations (Celery)
• Event-driven WS connections for real-time logs and shell (Django Channels)
• Infrastructure as code: Docker, docker-compose, Nginx configs as templates/scripts
• Modular services layer (services.py in each app) for single-responsibility