https://github.com/dudeperf3ct/8-fastapi-tests-gcp-gke
https://github.com/dudeperf3ct/8-fastapi-tests-gcp-gke
docker fastapi gke mlops model-serving
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/dudeperf3ct/8-fastapi-tests-gcp-gke
- Owner: dudeperf3ct
- Created: 2021-12-15T11:40:47.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-15T12:04:46.000Z (over 3 years ago)
- Last Synced: 2024-12-31T10:17:35.548Z (5 months ago)
- Topics: docker, fastapi, gke, mlops, model-serving
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Sentiment Classification
Exposed endpoint : http://34.72.165.159:8000/
In this project, we will deploy a sentiment analyser model using fastapi on GCP using GKE.
- Containerizing different components of projects
- Writing tests and testing individual modules using `pytest`
- Using [trunk](https://docs.trunk.io/) for automatic code checking, formatting and liniting
- Deploying application on GKE## Run
### Locally
- Sentiment Model
```bash
cd sentiment
docker build -t sentiment -f Dockerfile.t .
cd ..
docker run --rm -it -v $(pwd):/app sentiment bash
python3 sentiment/model.py
pytest tests/test_sentiment_model.py
```- FastAPI
> Note: To run `pytest` replace `requirements-fastapi.txt` with `requirements-dev.txt` in `Dockerfile`
```bash
docker build -t sentiment -f Dockerfile.fastapi .
docker run --rm -it -v $(pwd):/app -p 8000:8000 sentiment bash
uvicorn main:app --host=0.0.0.0
pytest --cov tests/
```- GKE
Deploy the application on Google Kubernetes Engine (GKE).
Guide: https://cloud.google.com/kubernetes-engine/docs/how-to/automated-deployment
> Expose port of 8000 after deploy under `Workloads > ACTIONS > Expose` in Kubernetes Engine.
> Setup up automatic deploy using Cloud Build and Github under `Workloads > ACTIONS > Automated deployment`.
Test the application endpoint
```bash
curl -X 'POST' \
'http://34.72.165.159:8000/classify?input_text=i%20like%20you' \
-H 'accept: application/json' \
-d ''
```## Additional Exercise
- Deploy this application using gcloud cli