Deploying the Django project to production required several key steps to ensure stability, performance, and a streamlined workflow. Below is a breakdown of the process:
1. Environment Variables
Instead of using a .env
file, I utilized PyCharm’s project settings to configure DJANGO_SETTINGS_MODULE
directly for each environment. This allowed for flexible management of settings based on development or production needs:
DJANGO_SETTINGS_MODULE
to the relevant settings file within PyCharm. The local settings file contains all necessary environment variables for easy configuration.settings.py
settings-template-local.py
settings-ci.py
2. Installing and Configuring Gunicorn and WhiteNoise
To transition the project to production:
3. Creating the Docker Image
Building a Docker image encapsulates the application environment, enabling consistent deployments across various machines. For detailed steps on Docker configuration, refer to the Docker setup section.
4. Setting Up CI/CD with GitHub Actions
I implemented a CI/CD pipeline via GitHub Actions, which ensures that all code is checked, tested, and automatically deployed when pushed to the main branch.
5. Configuring Docker Hub Webhook on Render
To automate deployment, I linked Docker Hub with Render using a webhook. This setup allows Render to automatically pull the latest Docker image upon updates.
6. Creating the deploy.sh File
Instead of embedding all commands directly in the Dockerfile, I created a separate deploy.sh
script. This allowed me to manage permissions independently and streamline the deployment process:
The script handles all necessary deployment steps, making it reusable and easy to maintain.