This project demonstrates a complete pipeline for building, deploying, and maintaining a machine learning model in production.
- Python 3.9+
- Virtual Environment: Create a virtual environment using
venv
orconda
- Clone the repository:
git clone https://github.com/AbdullahMansoor123/ml_end2end
- Navigate to the project directory:
cd end-to-end-ml-project
- Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # For Windows: venv\Scripts\activate
- Install the required dependencies:
pip install -r requirements.txt
- Run Flask App:
- Run the app by running
python app.py
in the terminal with virtual environment enabled.
- Run the app by running
-
Clone the GitHub Repo
git clone https://github.com/AbdullahMansoor123/ml_end2end cd ml_end2end
-
Create a Dockerfile
- Define the Dockerfile to build the application.
-
Create a GitHub Workflow
- Set up GitHub Actions workflow for continuous integration.
-
Create IAM User and Download Access Key
- Create an IAM user in AWS with necessary permissions and download the access key and secret key.
-
Create AWS ECR Repo and Copy URL
- Create a repository in AWS Elastic Container Registry (ECR) and copy the repository URL.
-
Set Up EC2 Instance
- Launch an EC2 instance and configure it as follows:
check if the setup completed successfully by running
sudo apt-get update -y sudo apt-get update curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh sudo usermod -aG docker ubuntu newgrp docker
docker images
on the EC2 instance
- Launch an EC2 instance and configure it as follows:
-
Create Runner on GitHub to Connect Repo with EC2
-
Create a Folder for the Runner
mkdir actions-runner && cd actions-runner
-
Download the Latest Runner Package
curl -o actions-runner-linux-x64-2.319.1.tar.gz -L https://github.com/actions/runner/releases/download/v2.319.1/actions-runner-linux-x64-2.319.1.tar.gz
-
Optional: Validate the Hash
echo "3f6efb7488a183e291fc2c62876e14c9ee732864173734facc85a1bfb1744464 actions-runner-linux-x64-2.319.1.tar.gz" | shasum -a 256 -c
-
Extract the Installer
tar xzf ./actions-runner-linux-x64-2.319.1.tar.gz
-
Configure the Runner
./config.sh --url https://github.com/AbdullahMansoor123/ml_end2end --token <your_github_token>
-
Run the Runner
./run.sh
-
Update GitHub Workflow YAML
Use the following in your GitHub Actions workflow file:runs-on: self-hosted
-
-
Add GitHub Secrets for AWS
- Add AWS credentials (access key and secret key) as GitHub secrets for your workflow to access AWS services.
-
Edit Inbound Rules for EC2 Instance
- Go to the Security settings of your EC2 instance.
- Navigate to Security Groups.
- Edit the Inbound Rules by adding a Custom TCP rule with the port number
4242
as specified in the GitHub workflow file
-
Initiate CICD github workflow
- Commit and push any change in the git repo to intiate cicd workflow.