https://github.com/midnighter/fastapi-base
A base Docker image for microservices using FastAPI. The Docker image environment is based on Alpine Linux or Debian.
https://github.com/midnighter/fastapi-base
alpine-image asgi debian-image docker fastapi microservices py38 python starlette
Last synced: 17 days ago
JSON representation
A base Docker image for microservices using FastAPI. The Docker image environment is based on Alpine Linux or Debian.
- Host: GitHub
- URL: https://github.com/midnighter/fastapi-base
- Owner: Midnighter
- License: apache-2.0
- Created: 2019-04-26T23:02:04.000Z (about 6 years ago)
- Default Branch: stable
- Last Pushed: 2025-04-29T11:03:43.000Z (about 1 month ago)
- Last Synced: 2025-05-13T01:13:49.313Z (17 days ago)
- Topics: alpine-image, asgi, debian-image, docker, fastapi, microservices, py38, python, starlette
- Language: Shell
- Homepage: https://hub.docker.com/r/midnighter/fastapi-base
- Size: 394 KB
- Stars: 9
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FastAPI-Base
[](https://github.com/Midnighter/fastapi-base/actions)
[](https://hub.docker.com/r/midnighter/fastapi-base)
[](https://opensource.org/licenses/Apache-2.0)A base [Docker](https://www.docker.com/) image for microservices using
[FastAPI](https://fastapi.tiangolo.com/). The Docker image environment is based
on [Debian](https://www.debian.org/) and provides a Python environment with
FastAPI, [gunicorn](https://gunicorn.org/), and [uvicorn
workers](https://www.uvicorn.org/) acting as an [Asynchronous Server Gateway
Interface (ASGI)](https://asgi.readthedocs.io/en/latest/).## Design
What is special about this Docker image? There are two key elements:
1. The image is completely deterministic in the sense that all Python
dependencies are pinned exactly using the `pip-compile` command from the
[pip-tools](https://pypi.org/project/pip-tools/) including package hashes so
that you can recreate the image exactly.
2. Every week, a [cron job](.github/workflows/cron-upgrade.yml) re-compiles the
dependencies and if they changed, commits them.
3. When the dependencies change, the image is
[re-built](.github/workflows/docker-image-ci.yml) and tagged with the
information shown below, with the date of creation, and the short version of
the commit hash, for example, `midnighter/fastapi-base:3.8-slim-buster_2020-07-03_d517373` That means, if
you use these tags, you know _exactly_ what you are getting.## Usage
You can combine this deterministic base image with your own in the following
ways. A tool like tag-spy can be used to retrieve the latest tag for each image
when you build your own.```
docker run --rm dddecaf/tag-spy:latest tag-spy midnighter/fastapi-base 3.8-slim-buster3.8-slim-buster_2020-07-03_d517373
```All actual implementations of such microservices should be based on this image
and include the fastapi-requirements in their own requirements. In practice,
their `Dockerfile` needs to specify:```dockerfile
ARG TAG=3.8-slim-buster_2020-07-03_d517373FROM midnighter/fastapi-base:${TAG}
```and their `requirements.in` file:
```
-r /opt/requirements/fastapi-requirements.txt
```such that pinned (deterministic) versions are guaranteed.
## Python Environments
Images are generated for the following environments. Please [open an
issue](https://github.com/Midnighter/fastapi-base/issues/new) if you require
others.| Tag | Python | Distribution |
| ------------------ | ------ | ------------------------------------------ |
| 3.8-slim-bookworm | 3.8 | [Debian Bookworm](https://www.debian.org/) |
| 3.9-slim-bookworm | 3.9 | [Debian Bookworm](https://www.debian.org/) |
| 3.10-slim-bookworm | 3.10 | [Debian Bookworm](https://www.debian.org/) |
| 3.11-slim-bookworm | 3.11 | [Debian Bookworm](https://www.debian.org/) |## Copyright
- Copyright © 2019-23, Moritz E. Beber.
- Free software licensed under the [Apache License, Version 2.0](LICENSE).