Simple boilerplate fastapi + celery playground to get started.
I created this while trying to learn it myself and keep it as a reference for future use.
Firstly clone the repo
git clone https://github.com/krishnasism/fastapi-celery-playground.git
cd fastapi-celery-playground
Copy the .env.example
file values into a new .env
file to have the environment variables correctly set.
After that, simply run
docker compose up --build
Note: I added --without-mingle
to celery, you can drop it. This was to mitigate a bug mentioned in this issue.
For now, I have tested it only with a local k8s cluster with minikube. It's pretty nifty!
Another tool that I found very handy is k9s
The commands to deploy in the local cluster are all present in the Makefile. Simply follow them one by one to have your local k8s cluster running the application.
But I believe that if you are connected to the correct k8s
cluster through kubectl, it will be deployed directly!
make <command>
Note: In case you want to pull your docker image from your own registry, please change the values in the api/ and celery/ deployment.yml
files from krishnasismandal/fastapi-celery-playground-fastapi:latest
to your own <docker-registry>/<image-name>:<tag>
Also don't forget to change the push_images_to_docker_registry
command in the Makefile to point to your registry.
- Do a GET request to
http://localhost:8000/api/v1/process/
to trigger the example task. - Navigate to
http://localhost:5556/
to view the Flower Dashboard.
If you want to run ingress
and view the app in the specified url, for example - fastapiapp.info
mentioned in ingress file, don't forget to update your /etc/hosts
file to contain the following line
127.0.0.1 fastapiapp.info
To install the dependencies locally, use poetry
pip install poetry
Clone the repo and install the dependencies
poetry install
We also have a couple of pre-commit hooks
pre-commit install
To run the app on K8s locally, you will need to also set up the following:
- Local K8s cluster (e.g: Minikube)
- Helm (v3)
Before kubectl apply
or helm install
don't forget to run make prepare_local
to prepare local K8s cluster.
To install using k8s follow the Makefile
.
cd .helm
helm install fastapi-celery-pg-1 .\fastapi-celery-playground\
I am using this as a playground to play around with FastAPI, Celery, and some other concepts. This is not meant to be a production project, but a simple playground to experiment and learn, but can serve as a good starting point.
Things to do (at least the basics):
- FastAPI
- Celery
- Docker
- Linting
- Kubernetes
- Helm
- SSL Support
- Tests
- Terraform
- Observability
- Logging
- Type Checking
- CeleryDocs: https://docs.celeryq.dev/
- FastAPI Docs: https://fastapi.tiangolo.com/
- Kubernetes Docs: https://kubernetes.io/docs/home/