Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Python Exchange Rate App - CI/CD Pipeline

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.

πŸš€ Features

  • 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

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   GitHub Repo   │───▢│ GitHub Actions│───▢│   AWS ECR       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚                       β”‚
                              β–Ό                       β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   Build &    β”‚    β”‚   AWS EC2       β”‚
                       β”‚   Push Image β”‚    β”‚   (Production)  β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‹ Prerequisites

  • Python 3.9+
  • Docker
  • AWS Account with ECR and EC2 access
  • GitHub repository with Actions enabled

πŸ› οΈ Local Development

Setup

  1. Clone the repository

    git clone <repository-url>
    cd Python-app---CI-CD
  2. Install dependencies

    pip install -r requirements.txt
  3. Run the application

    python app.py
  4. Access the application

Docker Development

  1. Build the image

    docker build -t exchange-rate-app .
  2. Run the container

    docker run -p 5000:5000 exchange-rate-app

πŸš€ Deployment

AWS Infrastructure Setup

  1. Create ECR Repository

    aws ecr create-repository --repository-name tekktribe --region eu-west-2
  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
  3. 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

GitHub Secrets Configuration

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

CI/CD Pipeline

The GitHub Actions workflow (.github/workflows/pipeline.yml) automatically:

  1. Triggers on push/PR to main branch
  2. Builds Docker image with commit SHA and latest tags
  3. Pushes images to AWS ECR
  4. Deploys to EC2 by:
    • Stopping existing containers on port 80
    • Pulling latest image from ECR
    • Running new container on port 80

πŸ“ Project Structure

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

πŸ”§ Configuration

Environment Variables

Variable Default Description
AWS_REGION eu-west-2 AWS region for ECR/EC2
ECR_REPOSITORY tekktribe ECR repository name

Application Settings

  • Port: 5000 (container) β†’ 80 (host)
  • API: ExchangeRate-API (free tier)
  • Update Frequency: Real-time on page refresh

πŸ” API Reference

Endpoints

  • GET / - Display exchange rates in web interface

External API

  • Provider: ExchangeRate-API
  • Endpoint: https://open.er-api.com/v6/latest/USD
  • Rate Limit: 1,500 requests/month (free tier)

πŸ› Troubleshooting

Common Issues

  1. Port 80 already in use

    • Pipeline automatically kills processes using port 80
    • Manual fix: sudo fuser -k 80/tcp
  2. ECR authentication failed

    • Verify AWS credentials in GitHub secrets
    • Check ECR repository exists in correct region
  3. EC2 connection failed

    • Verify EC2 security group allows SSH (22) and HTTP (80)
    • Check SSH key format in GitHub secrets

Logs

  • Application logs: docker logs python-app
  • GitHub Actions: Check Actions tab in repository
  • EC2 system logs: /var/log/messages

πŸ”’ Security

  • 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

πŸ“ˆ Monitoring

  • Health Check: Access application URL
  • Container Status: docker ps
  • Resource Usage: docker stats python-app

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™‹β€β™‚οΈ Support

For support and questions:

  • Create an issue in the GitHub repository
  • Check troubleshooting section above
  • Review GitHub Actions logs for deployment issues
  • Screenshot (67) Screenshot (66) Screenshot (71) Screenshot (69) Screenshot (68)

About

This repository holds my python application configured with a github actions ci/cd pipeline The application will display welcome to dataforte on the browser

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages