CI/CD Project: Deploy a Python App with /healthcheck Endpoint on Docker, ECR, Kubernetes, Terraform, and GitHub Actions
- [DevOps]
- Introduction
- Prerequisites
- Key Technologies & Tools
- Pipeline Workflow Overview
- Repository Structure
- Setup and Configuration
- Local Build and Testing
- CI/CD Pipeline Implementation
- Kubernetes Configuration
- Security Checks
- Branching Strategy
- Known Risks
- Final Testing and Push/Merge to Production
- Conclusion
- Demonstration
- Contact
I was able to develop a CI/CD pipeline for a containerized Python application using GitHub Actions, Docker, AWS ECR, Kubernetes (EKS), and Terraform. The pipeline handled automatic builds, tests, security scans, and deployments to AWS EKS based on branch triggers (dev for staging, main for production) with \healthcheck
endpoint that shows the last_commit_sha.
- Create a CI/CD pipeline that performs the following steps:
- Build and test a containerized Python application.
- Push Docker images to AWS Elastic Container Registry (ECR).
- Deploy the application to a Kubernetes cluster in AWS EKS using Terraform.
- Perform security scans using tools like Bandit, Safety, and Trivy.
- Deploy automatically upon commits to the dev or main branch in GitHub.
- Implement a
/healthcheck
endpoint that returns application version, description, and the last commit SHA in JSON format.
- A functional GitHub Actions pipeline that builds, tests, and deploys based on branch (dev or main).
- Successful deployment of the Dockerized application to AWS EKS.
- Security scans are implemented, and reports are available for review.
/healthcheck
endpoint responds with accurate JSON data.- Documentation is complete.
This guide walks you through how i was able to up a CI/CD pipeline for a containerized Python application. Using Docker, Terraform, GitHub Actions, Kubernetes, and AWS ECR, you will build, test, and deploy the application in an automated workflow. The goal is to enable automatic deployment on each new code commit.
Before beginning, ensure you have:
- AWS Account with permissions for ECR and EKS.
- GitHub Repository for version control and triggering the pipeline.
- AWS CLI configured on your local machine.
- Kubectl for Kubernetes management.
- Terraform for provisioning infrastructure.
- VS Code or any text editor of choice.
- Docker: For containerizing the Python application.
- AWS ECR: As the Docker image registry.
- AWS EKS: To deploy the containerized application in a Kubernetes cluster.
- Terraform: For provisioning EKS and related resources.
- GitHub Actions: For CI/CD, including building, testing, security scanning, and deployment.
- Security Tools: Trivy, Bandit, and Safety for scanning code and Docker images for vulnerabilities.
.
├── .github/
│ └── workflows/
│ └── cicdpipeline.yml
├── terraform/
│ ├── main.tf
│ └── variables.tf
├── app/
│ └── main.py
├── tests/
│ └── test_app.py
├── gab-app-local.sh
└── README.md
The CI/CD pipeline executes the following steps:
- Code Commit
- Dependency Installation
- Lint and Unit Test
- Environment Configuration
- Build Docker Image
- Security Scans
- Push to ECR
- Update Kubernetes Config
- Deploy to Kubernetes
- Health Check
git clone https://github.com/ougabriel/gab-test-mod.git
cd gab-test-mod
Run the provided script to build and test the application locally:
./gab-app-local.sh
Test the healthcheck endpoint:
curl http://localhost:3000/healthcheck
- Login to AWS: Set up AWS credentials.
- Use Terraform: Initialize and create workspaces.
cd terraform
terraform init
terraform workspace new dev
terraform workspace new prod
terraform workspace select dev
terraform apply
- GitHub Actions Workflow: Create the
.github/workflows/cicdpipeline.yml
file with the pipeline configuration.
Add necessary secrets for AWS account and ECR repository names in your GitHub repository settings.
Make changes and push to the dev
branch to trigger the pipeline:
git checkout -b dev
git add .
git commit -m "Initial commit"
git push origin dev
- Build and Test: Runs unit tests and linting.
- Security Scans: Uses Bandit, Safety, and Trivy.
- Docker Image Creation: Builds and pushes the image to ECR.
- Deployment: Deploys to EKS and verifies health.
- Automated CI/CD workflow with GitHub Actions.
- Use of Terraform for infrastructure provisioning.
- Dockerized Python application with healthcheck endpoint.
- Comprehensive security checks for code and Docker images.
For a live demonstration of the project, you can view the deployment in action at [CHECK THE BLOG HERE].
For questions or further discussions, feel free to reach out to me or connect with me on [LinkedIn Profile].