A Flask-based web application that displays real-time Nigerian Naira (NGN) to US Dollar (USD) exchange rates with automated CI/CD deployment to AWS EC2. This project will enhance your understanding of Python, Flask framework, Docker, AWS EC2 and storage of container Images in a private ECR repository.
- Real-time Exchange Rates: Fetches current NGN/USD exchange rates from ExchangeRate-API
- Web Interface: Clean, responsive web UI displaying exchange rates
- Command Line Support: Can be run from terminal for quick rate checks
- Dockerized: Containerized application for consistent deployment
- CI/CD Pipeline: Automated deployment using GitHub Actions
- AWS Integration: Deployed on EC2 with ECR for container registry
βββββββββββββββββββ ββββββββββββββββ βββββββββββββββββββ
β GitHub Repo βββββΆβ GitHub ActionsβββββΆβ AWS ECR β
βββββββββββββββββββ ββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
ββββββββββββββββ βββββββββββββββββββ
β Build & β β AWS EC2 β
β Push Image β β (Production) β
ββββββββββββββββ βββββββββββββββββββ
- Python 3.9+
- Docker
- AWS Account with ECR and EC2 access
- GitHub repository with Actions enabled
-
Clone the repository
git clone <repository-url> cd Python-app---CI-CD
-
Install dependencies
pip install -r requirements.txt
-
Run the application
python app.py
-
Access the application
- Web interface: http://localhost:5000
- Command line: Run
python app.pyand check terminal output
-
Build the image
docker build -t exchange-rate-app . -
Run the container
docker run -p 5000:5000 exchange-rate-app
-
Create ECR Repository
aws ecr create-repository --repository-name tekktribe --region eu-west-2
-
Launch EC2 Instance
- AMI: Amazon Linux 2
- Instance Type: t2.micro (or preferred)
- Security Group: Allow HTTP (80) and SSH (22)
- Install Docker and AWS CLI
-
Configure EC2 Instance
# Install Docker sudo yum update -y sudo yum install -y docker sudo systemctl start docker sudo systemctl enable docker sudo usermod -a -G docker ec2-user # Install AWS CLI sudo yum install -y aws-cli
Add the following secrets to your GitHub repository:
| Secret Name | Description |
|---|---|
AWS_ACCESS_KEY_ID |
AWS Access Key ID |
AWS_SECRET_ACCESS_KEY |
AWS Secret Access Key |
EC2_HOST |
EC2 instance public IP/hostname |
EC2_USER |
EC2 username (usually ec2-user) |
EC2_SSH_KEY |
Private SSH key for EC2 access |
The GitHub Actions workflow (.github/workflows/pipeline.yml) automatically:
- Triggers on push/PR to
mainbranch - Builds Docker image with commit SHA and
latesttags - Pushes images to AWS ECR
- Deploys to EC2 by:
- Stopping existing containers on port 80
- Pulling latest image from ECR
- Running new container on port 80
Python-app---CI-CD/
βββ .github/
β βββ workflows/
β βββ pipeline.yml # CI/CD pipeline configuration
βββ app.py # Main Flask application
βββ Dockerfile # Container configuration
βββ requirements.txt # Python dependencies
βββ deploy.sh # Manual deployment script
βββ LICENSE # Project license
βββ README.md # Project documentation
| Variable | Default | Description |
|---|---|---|
AWS_REGION |
eu-west-2 |
AWS region for ECR/EC2 |
ECR_REPOSITORY |
tekktribe |
ECR repository name |
- Port: 5000 (container) β 80 (host)
- API: ExchangeRate-API (free tier)
- Update Frequency: Real-time on page refresh
GET /- Display exchange rates in web interface
- Provider: ExchangeRate-API
- Endpoint:
https://open.er-api.com/v6/latest/USD - Rate Limit: 1,500 requests/month (free tier)
-
Port 80 already in use
- Pipeline automatically kills processes using port 80
- Manual fix:
sudo fuser -k 80/tcp
-
ECR authentication failed
- Verify AWS credentials in GitHub secrets
- Check ECR repository exists in correct region
-
EC2 connection failed
- Verify EC2 security group allows SSH (22) and HTTP (80)
- Check SSH key format in GitHub secrets
- Application logs:
docker logs python-app - GitHub Actions: Check Actions tab in repository
- EC2 system logs:
/var/log/messages
- AWS credentials stored as GitHub secrets
- Docker containers run with non-root user
- Security groups restrict access to necessary ports only
- Regular dependency updates via Dependabot
- Health Check: Access application URL
- Container Status:
docker ps - Resource Usage:
docker stats python-app
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:




