1. CI Status (build and test) |
2. CD status (docker build and push in DockerHub) |
3. CD Status (AWS EC2 / AZURE - docker pull and run) |
---|---|---|
or |
This is the demonstration project for the Course - Duke university: Specialization Building Cloud Computing Solutions at Scale by Noah Gift.
-
Link to the Specialization in Coursera: Building Cloud Computing Solutions at Scale Specialization - Duke University & Coursera
-
Link to my personal notes: Specialization
This project demonstrates how to develop a Flask web application for image classification using the MobileNetV2 pre-trained model from TensorFlow Hub. MobileNetV2 is a lightweight convolutional neural network (CNN) architecture, making it ideal for deploying on mobile devices and web applications.
The project utilizes the TensorFlow Hub library to load the pre-trained MobileNetV2 model and integrate it with the Flask application. Users can upload images to the application, which are then processed by the MobileNetV2 model to predict the class of the image. The predicted class is displayed to the user along with the model's confidence score.
- (AZURE): The app is live in this URL: ML Image Classificator
- (AWS): The app is live in this URL: ML Image Classificator
If the previous links are down (maybe my free-tier is over), you can run the app locally after installing python and the project dependencies:
Step 1: clone the repository. Step 2. Install Python 3.11 Step 3. Install dependencies.
$ pip install -r requirements.txt
Step 4. Run the project:
$ python app.py
The project is structured as follows:
- github\workflows: This directory contains the yaml files for CI configuration and CD configuration.
- /templates: This directory contains the static HTML and CSS files for the web application's user interface.
- app.py: This file defines the Flask application and runs the web server.
- app_test.py: this file contains the unit test for each method (using pytest).>
- Dockerfile: file that create the image of the APP to be deployed in a environment where docker is available.
- requirements.txt : file that contains all the dependency needed by the project.
The following diagram describe the high level architecture of the Application and the CI/CD process:
The code for the app is stored in a GitHub repository, which allows for easy version control and collaboration. The app is automatically build and test in a github workflow.
Then a docker image is create and pushed in DockerHub public repository in another workflow.
A third workflow is executed when the first two are executed successfully and the image is pulled and deployed in a AWS Ubuntu EC2 instance or AZURE Container Instance:
Link to YML: docker-run.yml AWS EC2
or
Link to YML: docker-run.yml AZURE
Validate that the workflows works properly:
The last step is wait until the image is pulled and running in the EC2 Ubuntu or in AZURE Container instance and access the public URL to log into the landing page of the app: (Depending of the Free Tier that I have at the moment I use one or another)
- AWS EC2: Landing page on EC2 instance
- Azure Container: Landing page on AZURE instance
- Install Python v3.11 (does not work with python 3.12)
- Install Docker
- Install Git and create a github account. Configure credential and SSH connection.
- Execute first time in the console:
matias@ml-demo-project$ pip install -r requirements.txt
- validate that all the dependencies listed in the "requirements.txt" are properly installed.
Launch new instance of EC2 with Ubuntu 20.04, using all the default parameters of the Free-Tier.
Ensure that you enable all the traffic (in and out) for testing purposes:
Follow the next instructions to install docker on the Ubuntu instance.
After the installation, verify that docker is properly configured and running:
After the EC2 instance is properly up and running with docker, is needed to configure the workflows and runners in github to communicate to EC2 to pull and run the builded image of the application from a public repository, in this case: DockerHub.
To do this, follow the instructions on the github actions section:
After installed the runner daemon in the EC2 Ubuntu instance, validate that is properly installed and running in background:
Verify is running:
The development flow need to follow the best practices:
- Clean code
- Modularity
- Cohesion
- Testing
- Commit (small) to a version control.
- Verify CI
- Verify CD
- Integration / acceptance testing
- Documentation.
- Load Test
The project comes with a very basic unit test in the file: "app_test.py".
To execute the tests and view the report, prompt the following:
$ pytest.exe -vv --html=report.html app_test.py
This command will execute and generate a HTML report as follow:
The report can be opened with any browser:
And even, the test execution and result can be monitored in the GitHub Action Pipeline:
For the validation of the current application exits a series of images in the folder: /images/test/ that can be used to "acceptance testing" as follow:
Test Case | Test input Images | Expected Restult |
---|---|---|
01 | image.jpg | solar_dish 0.7601 |
02 | image1.jpg | boathouse 0.2617 |
03 | image2.jpg | tabby 0.2365 |
04 | image3.jpg | sports_car 0.5183 |
05 | image4.jpg | dining_table 0.3249 |
Each result gives 3 matches from the highest to the lowest probability of similarity, like the following example:
For the load test, the tool: https://locust.io/ was used. There is a "task" defined for the "/" home endpoint and another task defined for the "/predict" endpoint:
To the execution, run the following command on the root of the project:
- Publish the docker image in DockerHub as private.
- Deploy the private image in ubuntu using SSH Keys.
- Change deploy platform to Digital Ocean: https://m.do.co/c/97f4ed2d8b7a