Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
cedd678
Uploading first draft of the new README.md. File: NEW_README.md
carlosplanchon Nov 8, 2025
ec4f2dd
Rebasing.
carlosplanchon Nov 10, 2025
be4aea2
Adding files for Running locally with Uvicorn, previously living in a…
carlosplanchon Nov 8, 2025
19945ee
Adding example files for running locally with Uvicorn.
carlosplanchon Nov 8, 2025
d8196a7
Improving README.md
carlosplanchon Nov 8, 2025
67284ff
Adding the rest of the scripts for running the boilerplate with Gunic…
carlosplanchon Nov 8, 2025
584d14f
Adding Contributing, References, License and Contact section from the…
carlosplanchon Nov 10, 2025
ee2e7f0
Removing deprecated version keyword from docker-compose.yml files.
carlosplanchon Nov 13, 2025
5ffc12d
With Claude Code: Addressing production nginx docker-compose missing …
carlosplanchon Nov 13, 2025
b8bb72c
With Claude Code: Addressing Instructions don't mention copying defau…
carlosplanchon Nov 13, 2025
01ca271
With Claude Code: Files named env should be renamed to .env.example t…
carlosplanchon Nov 13, 2025
69a7fc0
With Claude Code: The copy-paste commands in the README haven't been …
carlosplanchon Nov 13, 2025
662894b
fix syntax, change password so warning is gone
igorbenav Nov 15, 2025
0f723e6
add some other stuff to readme
igorbenav Nov 15, 2025
59f1e28
fix some things in the readme
igorbenav Nov 15, 2025
59e51ea
some more fixes
igorbenav Nov 15, 2025
f4e8740
some other improvements
igorbenav Nov 15, 2025
ccda306
setup script added for convenience
igorbenav Nov 16, 2025
f6ec929
script linting
igorbenav Nov 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,14 @@ cython_debug/
.idea

.vscode/

# Config files:
src/.env

# Ignore root files:
/Dockerfile
/docker-compose.yml

# Don't ignore files inside of script folder:
!scripts/*

2,228 changes: 112 additions & 2,116 deletions README.md

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions docker-compose.test.yml

This file was deleted.

22 changes: 19 additions & 3 deletions docs/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,35 @@ Install these tools on your system:
cd fastapi-boilerplate
```

1. **Set up environment**:
1. **Quick setup** (recommended):

```bash
cp src/.env.example src/.env
# Edit src/.env with your configuration
# Interactive setup - choose your deployment type
./setup.py

# Or specify directly: ./setup.py local, ./setup.py staging, ./setup.py production
```

This automatically copies the correct `Dockerfile`, `docker-compose.yml`, and `.env` files for your chosen deployment scenario.

1. **Start services**:

```bash
docker compose up -d
```

#### Manual Setup Alternative

If you prefer to set up manually:

```bash
# Copy configuration files for local development
cp scripts/local_with_uvicorn/Dockerfile Dockerfile
cp scripts/local_with_uvicorn/docker-compose.yml docker-compose.yml
cp scripts/local_with_uvicorn/.env.example src/.env
# Edit src/.env with your configuration if needed
```

1. **Verify installation**:

```bash
Expand Down
16 changes: 16 additions & 0 deletions docs/user-guide/configuration/docker-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

Learn how to configure and run the FastAPI Boilerplate using Docker Compose. The project includes a complete containerized setup with PostgreSQL, Redis, background workers, and optional services.

## Quick Start

The fastest way to get started is with the setup script:

```bash
./setup.py
```

This script helps you choose between three deployment configurations:

- **Local development** (`./setup.py local`) - Uvicorn with auto-reload
- **Staging** (`./setup.py staging`) - Gunicorn with workers
- **Production** (`./setup.py production`) - NGINX + Gunicorn

Each option copies the appropriate `Dockerfile`, `docker-compose.yml`, and `.env.example` files from the `scripts/` folder.

## Docker Compose Architecture

The boilerplate includes these core services:
Expand Down
67 changes: 67 additions & 0 deletions scripts/gunicorn_managing_uvicorn_workers/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# ============================================================================
# WARNING: EXAMPLE CONFIGURATION - DO NOT USE IN PRODUCTION AS-IS
# ============================================================================
# This file contains example values for development/testing purposes only.
#
# SECURITY CRITICAL: Before deploying to production, you MUST:
# 1. Copy this file to src/.env
# 2. Generate a new SECRET_KEY using: openssl rand -hex 32
# 3. Change all passwords (POSTGRES_PASSWORD, ADMIN_PASSWORD, etc.)
# 4. Update all sensitive configuration values
#
# Using these example values in production is a SECURITY RISK.
# ============================================================================

# ------------- app settings -------------
APP_NAME="My Project"
APP_DESCRIPTION="My Project Description"
APP_VERSION="0.1"
CONTACT_NAME="Me"
CONTACT_EMAIL="my.email@example.com"
LICENSE_NAME="MIT"

# ------------- database -------------
POSTGRES_USER="postgres"
POSTGRES_PASSWORD=1234
POSTGRES_SERVER="db"
POSTGRES_PORT=5432
POSTGRES_DB="postgres"
POSTGRES_ASYNC_PREFIX="postgresql+asyncpg://"

# ------------- crypt -------------
SECRET_KEY=953843cd400d99a039698e7feb46ca1b3e33c44fee2c24c6d88cf0f0b290fb61
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=60

# ------------- admin -------------
ADMIN_NAME="admin"
ADMIN_EMAIL="admin@example.com"
ADMIN_USERNAME="admin"
ADMIN_PASSWORD="Str1ngst!"

# ------------- redis cache -------------
REDIS_CACHE_HOST="redis"
REDIS_CACHE_PORT=6379

# ------------- redis queue -------------
REDIS_QUEUE_HOST="redis"
REDIS_QUEUE_PORT=6379

# ------------- redis rate limit -------------
REDIS_RATE_LIMIT_HOST="redis"
REDIS_RATE_LIMIT_PORT=6379

# ------------- client side cache -------------
CLIENT_CACHE_MAX_AGE=60

# ------------- test -------------
TEST_NAME="Tester User"
TEST_EMAIL="test@tester.com"
TEST_USERNAME="testeruser"
TEST_PASSWORD="Str1ngT3st!"

# ------------- environment -------------
ENVIRONMENT="staging"

# ------------- first tier -------------
TIER_NAME="free"
27 changes: 27 additions & 0 deletions scripts/gunicorn_managing_uvicorn_workers/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# --------- requirements ---------

FROM python:3.11 as requirements-stage

WORKDIR /tmp

RUN pip install poetry

COPY ./pyproject.toml ./poetry.lock* /tmp/

RUN poetry export -f requirements.txt --output requirements.txt --without-hashes


# --------- final image build ---------
FROM python:3.11

WORKDIR /code

COPY --from=requirements-stage /tmp/requirements.txt /code/requirements.txt

RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

COPY ./src/app /code/app

# -------- replace with comment to run with gunicorn --------
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
CMD ["gunicorn", "app.main:app", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "-b", "0.0.0.0:8000"]
112 changes: 112 additions & 0 deletions scripts/gunicorn_managing_uvicorn_workers/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
services:
web:
build:
context: .
dockerfile: Dockerfile
# -------- Both of the following commands should be commented to run with nginx --------

# -------- replace with comment to run with gunicorn or just uvicorn --------
# command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
command: gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000
env_file:
- ./src/.env
# -------- replace with expose if you are using nginx --------
ports:
- "8000:8000"
# expose:
# - "8000"
depends_on:
- db
- redis
volumes:
- ./src/app:/code/app
- ./src/.env:/code/.env

worker:
build:
context: .
dockerfile: Dockerfile
command: arq app.core.worker.settings.WorkerSettings
env_file:
- ./src/.env
depends_on:
- db
- redis
volumes:
- ./src/app:/code/app
- ./src/.env:/code/.env

db:
image: postgres:13
env_file:
- ./src/.env
volumes:
- postgres-data:/var/lib/postgresql/data
expose:
- "5432"

redis:
image: redis:alpine
volumes:
- redis-data:/data
expose:
- "6379"

#-------- uncomment to run with nginx --------
# nginx:
# image: nginx:latest
# ports:
# - "80:80"
# volumes:
# - ./default.conf:/etc/nginx/conf.d/default.conf
# depends_on:
# - web

#-------- uncomment to create first superuser --------
create_superuser:
build:
context: .
dockerfile: Dockerfile
env_file:
- ./src/.env
depends_on:
- db
- web
command: python -m src.scripts.create_first_superuser
volumes:
- ./src:/code/src

#-------- uncomment to run tests --------
# pytest:
# build:
# context: .
# dockerfile: Dockerfile
# env_file:
# - ./src/.env
# depends_on:
# - db
# - create_superuser
# - redis
# command: python -m pytest ./tests
# volumes:
# - .:/code

#-------- uncomment to create first tier --------
# create_tier:
# build:
# context: .
# dockerfile: Dockerfile
# env_file:
# - ./src/.env
# depends_on:
# - create_superuser
# - db
# - web
# command: python -m src.scripts.create_first_tier
# volumes:
# - ./src:/code/src

volumes:
postgres-data:
redis-data:

67 changes: 67 additions & 0 deletions scripts/local_with_uvicorn/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# ============================================================================
# WARNING: EXAMPLE CONFIGURATION - DO NOT USE IN PRODUCTION AS-IS
# ============================================================================
# This file contains example values for development/testing purposes only.
#
# SECURITY CRITICAL: Before deploying to production, you MUST:
# 1. Copy this file to src/.env
# 2. Generate a new SECRET_KEY using: openssl rand -hex 32
# 3. Change all passwords (POSTGRES_PASSWORD, ADMIN_PASSWORD, etc.)
# 4. Update all sensitive configuration values
#
# Using these example values in production is a SECURITY RISK.
# ============================================================================

# ------------- app settings -------------
APP_NAME="My Project"
APP_DESCRIPTION="My Project Description"
APP_VERSION="0.1"
CONTACT_NAME="Me"
CONTACT_EMAIL="my.email@example.com"
LICENSE_NAME="MIT"

# ------------- database -------------
POSTGRES_USER="postgres"
POSTGRES_PASSWORD=1234
POSTGRES_SERVER="db"
POSTGRES_PORT=5432
POSTGRES_DB="postgres"
POSTGRES_ASYNC_PREFIX="postgresql+asyncpg://"

# ------------- crypt -------------
SECRET_KEY=de2132a4a3a029d6a93a2aefcb519f0219990f92ca258a7c5ed938a444dbe1c8
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=60

# ------------- admin -------------
ADMIN_NAME="admin"
ADMIN_EMAIL="admin@example.com"
ADMIN_USERNAME="admin"
ADMIN_PASSWORD="Str1ngst!"

# ------------- redis cache -------------
REDIS_CACHE_HOST="redis"
REDIS_CACHE_PORT=6379

# ------------- redis queue -------------
REDIS_QUEUE_HOST="redis"
REDIS_QUEUE_PORT=6379

# ------------- redis rate limit -------------
REDIS_RATE_LIMIT_HOST="redis"
REDIS_RATE_LIMIT_PORT=6379

# ------------- client side cache -------------
CLIENT_CACHE_MAX_AGE=60

# ------------- test -------------
TEST_NAME="Tester User"
TEST_EMAIL="test@tester.com"
TEST_USERNAME="testeruser"
TEST_PASSWORD="Str1ngT3st!"

# ------------- environment -------------
ENVIRONMENT="local"

# ------------- first tier -------------
TIER_NAME="free"
File renamed without changes.
Loading