Orange Country Lettings

Project information


Introduction

This Django project involved a major refactoring of an existing codebase, modularizing the structure into multiple apps and setting up a robust CI/CD pipeline. The project was containerized using Docker, deployed on Render, and thoroughly documented to ensure maintainability and scalability.

Project Highlights:

    • Refactoring: Restructured the project into multiple Django apps, enhancing modularity and scalability.
    • Database Migrations: Used Django’s migration system to safely update the database schema without data loss.
    • Containerization and Hosting: Created a Dockerfile, hosted the Docker image on Docker Hub, and deployed the project on Render.
    • CI/CD Pipeline: Implemented GitHub Actions for continuous integration and deployment, including linting, testing, and Docker image creation.
    • Test Coverage: Achieved 80% test coverage using TestCase for models and views.
    • Multi-Environment Settings Management: Managed separate settings files for development, CI/CD, and production.
    • Production Optimization: Used Gunicorn and WhiteNoise for a production-ready setup.
    • Documentation: Documented the project using Sphinx and Read the Docs for clear, accessible project guidance.
    • Makefile: Automated routine tasks with a Makefile for enhanced productivity.

This project exemplifies best practices in Django application development, covering the full cycle from refactoring and testing to deployment and documentation. By integrating Docker, CI/CD, and detailed documentation, the project is built to be scalable, maintainable, and easy to extend.


Competences

    • refactoring a Django app: all content was in one single folder, reorganized the app, created several Django applications
    • migrate the existing database to other migration files, using the Django way of migration (use: SeparateDatabaseAndState and RemoveField and DeleteModel and AlterModelTable)
    • create a Dockerfile, host the Docker Image on Docker Hub
    • host the project on Render
    • create CI/CD with Github actions, verifies with Flake8 and all tests in tests.py files and create a Docker Image
    • couverage of tests
    • Makefile
    • several settings files (settings.py, settings-local.py, settings-ci.py, settings-local-template.py)
    • make the project production ready with gunicorn and whitenoise
    • TestCase: test models and views


Learning Experience

1. Refactoring the Django Application into a Modular Structure

Initially, the entire codebase was contained within a single monolithic folder, making it difficult to manage and scale. To improve code organization and adhere to Django's best practices, I refactored the project into multiple Django applications, each representing a distinct functionality. This modular approach simplified the development process, enabled independent app testing, and laid the foundation for smoother future enhancements.

2. Database Migration Using Django’s Built-In Migration System

To accommodate the refactored structure, I used Django’s migration framework to manage the necessary database schema changes. Leveraging SeparateDatabaseAndState, I separated the logical schema updates from physical changes, and performed tasks such as field removals, model deletions, and table alterations without losing existing data. This minimized disruption and ensured the database remained consistent throughout the refactoring.

3. Docker Containerization and Deployment

A Dockerfile was created to containerize the Django application, enabling isolated and reproducible environments for development and production. After building the Docker image, I hosted it on Docker Hub, making it easily accessible for deployment. This containerized setup facilitated seamless transitions between local and production environments, minimizing the risk of environment-specific issues.

4. Deployment on Render

The application was then deployed on Render, utilizing its scalable hosting platform. Render’s flexibility allowed me to configure environment variables, handle static files, and manage multiple settings files, making the deployment process straightforward and efficient.

5. CI/CD Pipeline with GitHub Actions

A complete CI/CD pipeline was established using GitHub Actions. This automated workflow included:

      • Code Linting with Flake8: To enforce coding standards and maintain a clean codebase.
      • Running Tests: Integrated test runs ensured that all functionality was validated before deployment.
      • Building Docker Images: Each successful run automatically built and pushed an updated Docker image to Docker Hub.

This automated pipeline reduced the risk of human error and ensured continuous integration and deployment, keeping the application stable and up-to-date.

6. Comprehensive Test Coverage

Using Django’s TestCase, I created unit tests for both models and views, achieving a maximum test coverage of 80%. This ensured that the core functionality of each Django app was verified, minimizing the risk of regression during future updates. The testing approach focused on validating individual components as well as their interactions, guaranteeing a reliable and well-tested system.

7. Managing Multiple Settings Files

The project required multiple settings files to accommodate different environments. I created separate configurations for:

      • Development (settings-local.py)
      • CI/CD (settings-ci.py)
      • Production (settings.py)

Additionally, I provided a settings-local-template.py to serve as a blueprint for local development setups, reducing setup time for new developers joining the project.

8. Production-Ready Setup with Gunicorn and WhiteNoise

The deployment environment was optimized using Gunicorn as the WSGI server and WhiteNoise for static file management. This setup improved performance and ensured that the application could handle high traffic in a production setting. WhiteNoise enabled efficient serving of static files without the need for an external CDN, simplifying the deployment and reducing external dependencies.

9. Documentation with Sphinx and Read the Docs

Comprehensive documentation was created using Sphinx and hosted on Read the Docs. This documentation covered the project’s architecture, individual application functionalities, API endpoints, and setup instructions, making it easy for both developers and end-users to understand and navigate the system. This level of detail ensured that the project was well-documented, facilitating smooth onboarding and future maintenance.

10. Makefile for Streamlined Management

A Makefile was added to simplify common commands, such as running the development server, building Docker images, or running tests. This streamlined the workflow, allowing developers to perform routine tasks with a single command, thereby improving efficiency.

Designed by BootstrapMade and modified by DoriDoro