{"id":16201887,"url":"https://github.com/ossycodes/udacity-machinelearning-project","last_synced_at":"2025-04-07T18:46:24.115Z","repository":{"id":104476110,"uuid":"594759252","full_name":"ossycodes/udacity-machinelearning-project","owner":"ossycodes","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-30T23:45:51.000Z","size":2845,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-13T20:35:21.942Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ossycodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-29T15:03:49.000Z","updated_at":"2023-01-29T15:21:57.000Z","dependencies_parsed_at":"2023-03-13T14:54:59.292Z","dependency_job_id":null,"html_url":"https://github.com/ossycodes/udacity-machinelearning-project","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ossycodes%2Fudacity-machinelearning-project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ossycodes%2Fudacity-machinelearning-project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ossycodes%2Fudacity-machinelearning-project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ossycodes%2Fudacity-machinelearning-project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ossycodes","download_url":"https://codeload.github.com/ossycodes/udacity-machinelearning-project/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247712616,"owners_count":20983678,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T09:44:45.958Z","updated_at":"2025-04-07T18:46:24.098Z","avatar_url":"https://github.com/ossycodes.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CircleCI](https://dl.circleci.com/status-badge/img/gh/ossycodes/udacity-machinelearning-project/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/img/gh/ossycodes/udacity-machinelearning-project/tree/master.svg?style=svg)\n\n## Project Overview\n\nIn this project, you will apply the skills you have acquired in this course to operationalize a Machine Learning Microservice API. \n\nYou are given a pre-trained, `sklearn` model that has been trained to predict housing prices in Boston according to several features, such as average rooms in a home and data about highway access, teacher-to-pupil ratios, and so on. You can read more about the data, which was initially taken from Kaggle, on [the data source site](https://www.kaggle.com/c/boston-housing). This project tests your ability to operationalize a Python flask app—in a provided file, `app.py`—that serves out predictions (inference) about housing prices through API calls. This project could be extended to any pre-trained machine learning model, such as those for image recognition and data labeling.\n\n### Project Tasks\n\nYour project goal is to operationalize this working, machine learning microservice using [kubernetes](https://kubernetes.io/), which is an open-source system for automating the management of containerized applications. In this project you will:\n* Test your project code using linting\n* Complete a Dockerfile to containerize this application\n* Deploy your containerized application using Docker and make a prediction\n* Improve the log statements in the source code for this application\n* Configure Kubernetes and create a Kubernetes cluster\n* Deploy a container using Kubernetes and make a prediction\n* Upload a complete Github repo with CircleCI to indicate that your code has been tested\n\nYou can find a detailed [project rubric, here](https://review.udacity.com/#!/rubrics/2576/view).\n\n**The final implementation of the project will showcase your abilities to operationalize production microservices.**\n\n---\n\n## Setup the Environment\n\n* Create a virtualenv with Python 3.7 and activate it. Refer to this link for help on specifying the Python version in the virtualenv. \n```bash\npython3 -m pip install --user virtualenv\n# You should have Python 3.7 available in your host. \n# Check the Python path using `which python3`\n# Use a command similar to this one:\npython3 -m virtualenv --python=\u003cpath-to-Python3.7\u003e .devops\nsource .devops/bin/activate\n```\n* Run `make install` to install the necessary dependencies\n\n### Running `app.py`\n\n1. Standalone:  `python app.py`\n2. Run in Docker:  `./run_docker.sh`\n3. Run in Kubernetes:  `./run_kubernetes.sh`\n\n### Kubernetes Steps\n\n* Setup and Configure Docker locally\n* Setup and Configure Kubernetes locally\n* Create Flask app in Container\n* Run via kubectl\n\n### Files in Repository\n\n* Files to build and run docker image\n\n   -- run_docker.sh\n\n* Files to upload images to docker hub\n\n  -- upload_docker.sh\n\n* Files to deploy to kubernetes\n\n  -- run_kubernetes.sh\n\n* Files to build application\n\n  -- Makefile\n\n* Application file\n\n  -- app.py\n\n  -- requirements.txt\n\n* Application Output Log Files\n\n  -- output_txt_files/docker_out.txt\n\n  -- output_txt_files/kubernetes_out.txt\n\n* Folder for Application Models\n\n  -- model_data/\n  \n* Folder for Circleci Config Files\n\n  -- .circleci/\n\n## Tasks / Replicate the project\n\nTo see the screenshots of each task go to the `screenshots` directory.\n\n### 1. Complete the Dockerfile\n\n-   Specify your python version\n-   Specify a working directory.\n-   Copy the app.py source code to that directory\n-   Install any dependencies in requirements.txt (`make install`)\n-   Expose a port when the container is created (port 80 is standard).\n-   Specify that the app runs at container launch.\n\n\u003e **Note:** If you want to install python dependencies and hadolint use `make install` and `make install-hadolint`\nTo run `make lint` don't forget create and activate the virtual env before:\n\n```sh\n$ make setup # create the virtual env\n$ source ~/.devops/bin/activate # active the virtual env\n$ make lint\n```\n\n### 2. Run a Container \u0026 Make a Prediction\n\n-   Build the docker image from the Dockerfile; it is recommended that you use an optional --tag parameter as described in the build documentation.\n-   List the created docker images (for logging purposes).\n-   Run the containerized Flask app; publish the container’s port (`80`) to a host port (`8000`).\n\nRun the container using the `run_docker.sh` script created before following the steps above:\n\n```sh\n$ . ./run_docker.sh \n```\n\nAfter running the container (docker app) we can able to run the prediction using the `make_prediction.sh` script:\n\n```sh\n$ . ./make_prediction.sh # Don't forget run the container before\n```\n\n### 3. Improve Logging \u0026 Save Output\n\n-   Add a prediction log statement\n-   Run the container and make a prediction to check the logs\n\n\u003e **Note:** If you don't see any logs on your terminal you can use the `docker logs` command, to get container id of your docker app you can use `docker ps` and used that with the `docker logs` command. e.g: `docker ps` and the container id is `4c01db0b339c` your command to get the logs is `docker logs 4c01db0b339c`\n```sh\n$ docker ps\n```\n\n\u003e **Note:** Don't forget copy the output to `docker_out.txt`\n### 4. Upload the Docker Image\n\n-   Create a [Docker Hub](https://hub.docker.com/) account\n-   Built the docker container with this command `docker build --tag=\u003cyour_tag\u003e .` **(Don't forget the tag name)**\n-   Define a `dockerpath` which is `\u003cdocker_hub_username\u003e/\u003cproject_name\u003e` e.g: `osaigbovoemmanuel/skylearnmlproject`\n-   Authenticate and tag image\n-   Push your docker image to the `dockerpath`\n\n\u003e Note: replace \u003cyour_tag\u003e with the tag name that you want to use. For example: api -\u003e `docker build --tag=api .`\nAfter complete all steps run the upload using the `upload_docker.sh` script:\n\n```sh\n$ . ./upload_docker.sh\n```\n\n### 5. Configure Kubernetes to Run Locally\n\n-   [Install Kubernetes](https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-linux)\n-   [Install Minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/)\n\n### 6. Deploy with Kubernetes and Save Output Logs\n\n-   Define a dockerpath which will be `\u003cdocker_hub_username\u003e/\u003cproject_name\u003e`, this should be the same name as your uploaded repository (the same as in upload_docker.sh)\n-   Run the docker container with kubectl; you’ll have to specify the container and the port\n-   List the kubernetes pods\n-   Forward the container port to a host port, using the same ports as before\n\nAfter complete all steps run the kubernetes using `run_kubernetes.sh` script:\n\n```sh\n$ . ./run_kubernetes.sh\n```\n\nAfter running the kubernete make a prediction using the `make_prediction.sh` script as we do in the [second task](#2-run-container--make-prediction).\n\n\u003e **Note:** Don't forget copy the output to the `kubernetes_out.txt`\n### 7. Delete Cluster\n\nIf you want to delete the kubernetes cluster just run this command `minikube delete`. You can also stop the kubernetes cluster with this command `minikube stop`\n\n### 8. CircleCI Integration\n\n-   Create a [CircleCI Account](https://circleci.com/) (use your Github account for a better integration)\n-   Create a config using this [template](https://raw.githubusercontent.com/udacity/DevOps_Microservices/master/Lesson-2-Docker-format-containers/class-demos/.circleci/config.yml)\n-   Add a status badge using this template: `[![\u003cgithub_username\u003e](https://circleci.com/gh/\u003cgithub_username\u003e/\u003crepository\u003e.svg?style=svg)](https://circleci.com/gh/\u003cgithub_username\u003e/\u003crepository\u003e)` replace `\u003cgithub_username\u003e` and `\u003crepository\u003e` with your data and paste on top of your readme file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fossycodes%2Fudacity-machinelearning-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fossycodes%2Fudacity-machinelearning-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fossycodes%2Fudacity-machinelearning-project/lists"}