Skip to content

GrantBirki/caddy-fastapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

caddy-fastapi ⛳

test

This is a template repo to deploy Caddy + FastAPI with docker-compose

Usage 🔨

To use this repo simply do the following:

  1. Clone the repo

  2. Run the following command:

    docker-compose up --build
  3. Navigate to your domain: localhost

That's it!

TLS Certificate 🔐

Caddy automatically provisions TLS certificates for you. In order to make use of this awesome feature, do the following:

  1. Ensure your server has ports 80 and 443 open

  2. Have a DNS record pointed to your server for the domain you wish to obtain a certificate for (e.g. app.example.org -> <IP address>)

  3. Export the env var for the domain you wish to use:

    export DOMAIN=app.example.org
  4. Start the docker-compose stack:

    docker-compose up --build
  5. Navigate to your domain and enjoy your easy TLS setup with Caddy! -> https://app.example.org

Extra Info 📚

Here is some extra info about the setup

Volumes 🛢️

The docker-compose file creates two volumes:

  • ./data/caddy_data:/data
  • ./data/caddy_config:/config

The config volume is used to mount Caddy configuration

The data volume is used to store certificate information. This is really important so that you are not re-requesting TLS certs each time you start your container. Doing so can cause you to hit Let's Encrypt rate limits that will prevent you from provisioning certificates.

Environment Variables 📝

If you run the stack without the DOMAIN variable set in your environment, the stack will default to using localhost. This is ideal for testing out the stack locally.

If you set the DOMAIN variable, Caddy will attempt to provision a certificate for that domain. In order to do so, you will need DNS records pointed to that domain and you will need need traffic to access your server via port 80 and 443.

Disclaimer

This repo is extremely simple on purpose. You should tailor this to your needs if you plan on adapting it for production usage of any kind.

That being said, I will admit that I am currently running this setup (fastapi swapped for nodejs stack because the API was already written in JS) in production and it is working great for me. I'm just running this docker-compose stack on a 2vCPU/4GB memory VM in Azure and its handling traffic just fine. Here is a 30 day snapshot of general metrics for this setup:

Azure Metrics