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 for automatic code checking, formatting and liniting
- Deploying application on GKE
- Sentiment Model
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
replacerequirements-fastapi.txt
withrequirements-dev.txt
inDockerfile
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
curl -X 'POST' \
'http://34.72.165.159:8000/classify?input_text=i%20like%20you' \
-H 'accept: application/json' \
-d ''
- Deploy this application using gcloud cli