A production-ready DevOps workflow — Dockerized Django app with Jenkins CI/CD, PostgreSQL, Nginx reverse proxy, and automated AWS EC2 deployment. Zero manual deployments.
Every git push to main triggers the full automated pipeline — from code checkout to live deployment on AWS EC2.
Full-stack architecture running inside Docker containers on AWS EC2 — Nginx handles all incoming traffic, routing to the Django/Gunicorn app, backed by PostgreSQL.
The Jenkinsfile defines 5 automated stages. Every push to main runs the full pipeline end-to-end — no human intervention required.
pipeline { agent any stages { stage('Checkout') { steps { checkout scm } } stage('Build Docker Images') { steps { sh 'docker-compose build' } } stage('Run Tests') { steps { sh 'docker-compose run --rm web python manage.py test' } } stage('Deploy to EC2') { steps { sh ''' docker-compose down docker-compose up -d --build ''' } } } post { success { echo '✅ Deployed successfully!' } failure { echo '❌ Build failed — check logs' } } }
Three services defined in docker-compose.yml — isolated, networked, and orchestrated with shared volumes and environment config.
# Multi-stage Python build FROM python:3.11-slim WORKDIR /app ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 # System dependencies RUN apt-get update && apt-get install \ libpq-dev gcc --no-install-recommends # Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . # Collect static files RUN python manage.py collectstatic --noinput EXPOSE 8000 ENTRYPOINT ["./entrypoint.sh"]
upstream django { server web:8000; } server { listen 80; location /static/ { alias /vol/web/static/; } location /media/ { alias /vol/web/media/; } location / { proxy_pass http://django; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } }
Ubuntu EC2 instance hosts the entire containerized stack. Security groups open only the required ports. Jenkins deploys via SSH using key-based authentication.
Full deployment walkthrough — from cloning the repo to a live production app on AWS EC2 in 6 steps.
.env with your DB credentials, Django SECRET_KEY, and ALLOWED_HOSTS.install.sh script which installs Docker, Docker Compose, and all required system dependencies.main triggers the Jenkinsfile pipeline automatically.docker compose up -d --build manually on EC2. After this, all subsequent deploys happen automatically via Jenkins on every git push.docker compose ps. Access the app at your EC2 IP on port 80. Admin panel at /admin/. Watch live logs with the logs command.# Django Configuration SECRET_KEY=your-super-secret-django-key-here DEBUG=0 ALLOWED_HOSTS=your-ec2-ip,your-domain.com # Database Configuration DB_NAME=saikrupa_db DB_USER=postgres_user DB_PASSWORD=strong-password-here DB_HOST=db DB_PORT=5432 # Django static / media STATIC_URL=/static/ MEDIA_URL=/media/