The GitHub Actions CI/CD pipeline for the Orange Country Lettings project was configured to ensure the code’s quality and seamless deployment. Here’s an overview of the setup and each key component.
Pipeline Overview
The CI/CD pipeline is triggered on pushes and pull requests to the main branch. It contains two primary jobs: test_app
, which focuses on code testing and quality checks, and docker
, which handles building and pushing a Docker image to Docker Hub. Each of these jobs has specific tasks designed to verify code standards and prepare the application for deployment.
Job Breakdown
1. Testing the App (test_app job)
-
-
- Linting with Flake8: This job begins by checking the project’s Python code with Flake8 to identify any syntax or style errors that could lead to issues in production. Running Flake8 enforces code quality and adherence to PEP8 standards.
- Testing and Coverage Check: It then runs all test cases using Django’s manage.py test. To ensure that code coverage is adequate, the pipeline is set to fail if test coverage is below 80%. This threshold helps maintain high standards for reliability and functionality. The coverage tool is used here, generating a report that identifies any untested lines of code and enforcing a minimum coverage percentage.
2. Building and Deploying Docker Image (docker job)
-
-
- Docker Image Creation: After testing, the docker job builds a Docker image for the project, which encapsulates the app’s environment and dependencies. The job tags the image using the latest commit hash, making it easy to track each image back to its code version.
- Login to Docker Hub and Push Image: The job then logs into Docker Hub using credentials stored securely as secrets in GitHub. Once authenticated, the newly created image is pushed to the specified Docker Hub repository,
doridoro/oc_lettings_site
. This step ensures that a fresh, versioned image is available for deployment.
Key Benefits
-
- Automated Quality Assurance: The Flake8 and test coverage checks help maintain code standards, catching potential issues early in development.
- Efficient Deployment with Docker: By pushing tagged images to Docker Hub, the project can be reliably deployed with a tracked, consistent environment.
- Version Control: Tagging images with the commit hash ensures each Docker image corresponds to a specific code version, supporting easy rollbacks and tracking.
This GitHub Actions CI/CD setup delivers a streamlined, quality-focused approach, improving confidence in code quality and providing an efficient, automated way to prepare the project for deployment.