Django app with CI/CD

Hello there, thanks for reading my blog, let’s start.
Django
So, before deploying the Django app I needed a Django application, I searched online for many such projects, but wasn’t satisfied because they were not my own, so I decided to make one and for that I needed to learn Django, so it took me a day to learn the basics of creating an application in Django, why so less time ??? because I was already familiar with python. so, I made one, a simple portfolio web app with Django’s in-built database.
Infrastructure as code
For the application to run I needed infrastructure, so I created one with Terraform on AWS. I am already building projects on Terraform for the past time, so it was easy to create the infrastructure. You can find the infrastructure files on infra branch in my repo.
Docker
The next step was to run the application on Docker, Django applications need env to run, but I preferred Docker because why not, so I created a docker file, and from that created Docker image which created my container, and my app was running on Docker. also, with the help of docker networks I created this container and bridged it with a network to be used later. And last but not least I pushed my latest images to Docker hub.
Nginx
If my port was already running and I can see my app on the browser why use NGINX??? It is because NGINX works as a reverse proxy, which has a ton of benefits like load balancing, caching responses etc. But why not use an AWS load balancer?? simple answer, not free yet. And then I created nginx’s Docker file bridged it with the same network as my app, and the container was running. You might be wondering where he implemented CI/CD??? he’s just yapping around and not telling the actual thing lol, read below.
CI/CD
The above manual setup took me like 3 to 4 hours, so I decided to use Jenkins to automate the whole above process with single “git push “from my VS code and you won’t believe my actual deployment time including setting up Django, Docker, Docker networks, Nginx etc. was reduced to 99.223%, which is 1 minutes 38 seconds only, see the image below, also with this I was less prone to human errors while setting this manually, so every time I make changes in my code, a new docker image was generated while deleting the old ones for my app and nginx both the newer images were automatically pushed to docker hub and my app was deployed on my ec2 instance all with a single command “git push“.
Repo Link
In my repo you can find the details on how to run this application
Subscribe to my newsletter
Read articles from adnan khan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
