Skip to content

A base Docker image for microservices using FastAPI. The Docker image environment is based on Alpine Linux or Debian.

License

Notifications You must be signed in to change notification settings

Midnighter/fastapi-base

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI-Base

Docker Image CI Docker image pulls License

A base Docker image for microservices using FastAPI. The Docker image environment is based on Debian and provides a Python environment with FastAPI, gunicorn, and uvicorn workers acting as an Asynchronous Server Gateway Interface (ASGI).

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 including package hashes so that you can recreate the image exactly.
  2. Every week, a cron job re-compiles the dependencies and if they changed, commits them.
  3. When the dependencies change, the image is re-built 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-buster

3.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:

ARG TAG=3.8-slim-buster_2020-07-03_d517373

FROM 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 if you require others.

Tag Python Distribution
3.8-slim-bookworm 3.8 Debian Bookworm
3.9-slim-bookworm 3.9 Debian Bookworm
3.10-slim-bookworm 3.10 Debian Bookworm
3.11-slim-bookworm 3.11 Debian Bookworm

Copyright

About

A base Docker image for microservices using FastAPI. The Docker image environment is based on Alpine Linux or Debian.

Topics

Resources

License

Stars

Watchers

Forks

Languages