This application is a FastAPI-based web service that integrates with Redis for data caching and storage. It's designed to demonstrate a simple yet powerful setup using Docker for containerization and Kamal for deployment. This a setup that deploys a fastapi application using docker and redis using kamal accessories all deployed on hetzner server(s).
- FastAPI: A modern, fast (high-performance) web framework for building APIs with Python.
- Redis: An in-memory data structure store, used as a database, cache, and message broker.
- Docker: Used for containerizing the application and its dependencies.
- Kamal: A deployment tool that simplifies the process of shipping web apps.
- FastAPI web server with example endpoints
- Redis integration for data storage and retrieval
- Docker containerization for easy setup and deployment
- Kamal configuration for streamlined deployment process
- Hetzner Cloud for hosting
- Docker
- Kamal (for deployment)
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Build the Docker image:
docker build -t fastapi-redis-app .
-
Run the Docker container:
docker run -p 8000:8000 -e REDIS_HOST=<redis-host> -e REDIS_PORT=<redis-port> fastapi-redis-app
Replace
<redis-host>
and<redis-port>
with your Redis server details. -
Access the application at
http://localhost:8000
-
Test the Redis connection at
http://localhost:8000/redis
-
Check the application health at
http://localhost:8000/up
This project uses Kamal for deployment. Kamal simplifies the process of deploying Docker containers to remote servers.
-
Ensure you have Kamal installed:
gem install kamal
-
Configure your deployment settings in
config/deploy.yml
-
Set up your environment variables:
- For CI/CD, ensure these variables are set in your pipeline (e.g., GitHub Actions secrets)
-
Deploy your application:
kamal setup kamal deploy
main.py
: The main FastAPI application fileDockerfile
: Defines the Docker image for the applicationconfig/deploy.yml
: Kamal deployment configurationrequirements.txt
: Python dependencies
Contributions are welcome! Please feel free to submit a Pull Request.