Skip to content

Commit b5a9e0a

Browse files
authored
Merge pull request #218 from carlosplanchon/new_readme
New README.md & installation scripts now live in the scripts folder.
2 parents 16271bb + f6ec929 commit b5a9e0a

File tree

15 files changed

+850
-2164
lines changed

15 files changed

+850
-2164
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,14 @@ cython_debug/
135135
.idea
136136

137137
.vscode/
138+
139+
# Config files:
140+
src/.env
141+
142+
# Ignore root files:
143+
/Dockerfile
144+
/docker-compose.yml
145+
146+
# Don't ignore files inside of script folder:
147+
!scripts/*
148+

README.md

Lines changed: 112 additions & 2116 deletions
Large diffs are not rendered by default.

docker-compose.test.yml

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/getting-started/installation.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,35 @@ Install these tools on your system:
3131
cd fastapi-boilerplate
3232
```
3333

34-
1. **Set up environment**:
34+
1. **Quick setup** (recommended):
3535

3636
```bash
37-
cp src/.env.example src/.env
38-
# Edit src/.env with your configuration
37+
# Interactive setup - choose your deployment type
38+
./setup.py
39+
40+
# Or specify directly: ./setup.py local, ./setup.py staging, ./setup.py production
3941
```
4042

43+
This automatically copies the correct `Dockerfile`, `docker-compose.yml`, and `.env` files for your chosen deployment scenario.
44+
4145
1. **Start services**:
4246

4347
```bash
4448
docker compose up -d
4549
```
4650

51+
#### Manual Setup Alternative
52+
53+
If you prefer to set up manually:
54+
55+
```bash
56+
# Copy configuration files for local development
57+
cp scripts/local_with_uvicorn/Dockerfile Dockerfile
58+
cp scripts/local_with_uvicorn/docker-compose.yml docker-compose.yml
59+
cp scripts/local_with_uvicorn/.env.example src/.env
60+
# Edit src/.env with your configuration if needed
61+
```
62+
4763
1. **Verify installation**:
4864

4965
```bash

docs/user-guide/configuration/docker-setup.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
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.
44

5+
## Quick Start
6+
7+
The fastest way to get started is with the setup script:
8+
9+
```bash
10+
./setup.py
11+
```
12+
13+
This script helps you choose between three deployment configurations:
14+
15+
- **Local development** (`./setup.py local`) - Uvicorn with auto-reload
16+
- **Staging** (`./setup.py staging`) - Gunicorn with workers
17+
- **Production** (`./setup.py production`) - NGINX + Gunicorn
18+
19+
Each option copies the appropriate `Dockerfile`, `docker-compose.yml`, and `.env.example` files from the `scripts/` folder.
20+
521
## Docker Compose Architecture
622

723
The boilerplate includes these core services:
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# ============================================================================
2+
# WARNING: EXAMPLE CONFIGURATION - DO NOT USE IN PRODUCTION AS-IS
3+
# ============================================================================
4+
# This file contains example values for development/testing purposes only.
5+
#
6+
# SECURITY CRITICAL: Before deploying to production, you MUST:
7+
# 1. Copy this file to src/.env
8+
# 2. Generate a new SECRET_KEY using: openssl rand -hex 32
9+
# 3. Change all passwords (POSTGRES_PASSWORD, ADMIN_PASSWORD, etc.)
10+
# 4. Update all sensitive configuration values
11+
#
12+
# Using these example values in production is a SECURITY RISK.
13+
# ============================================================================
14+
15+
# ------------- app settings -------------
16+
APP_NAME="My Project"
17+
APP_DESCRIPTION="My Project Description"
18+
APP_VERSION="0.1"
19+
CONTACT_NAME="Me"
20+
CONTACT_EMAIL="[email protected]"
21+
LICENSE_NAME="MIT"
22+
23+
# ------------- database -------------
24+
POSTGRES_USER="postgres"
25+
POSTGRES_PASSWORD=1234
26+
POSTGRES_SERVER="db"
27+
POSTGRES_PORT=5432
28+
POSTGRES_DB="postgres"
29+
POSTGRES_ASYNC_PREFIX="postgresql+asyncpg://"
30+
31+
# ------------- crypt -------------
32+
SECRET_KEY=953843cd400d99a039698e7feb46ca1b3e33c44fee2c24c6d88cf0f0b290fb61
33+
ALGORITHM=HS256
34+
ACCESS_TOKEN_EXPIRE_MINUTES=60
35+
36+
# ------------- admin -------------
37+
ADMIN_NAME="admin"
38+
ADMIN_EMAIL="[email protected]"
39+
ADMIN_USERNAME="admin"
40+
ADMIN_PASSWORD="Str1ngst!"
41+
42+
# ------------- redis cache -------------
43+
REDIS_CACHE_HOST="redis"
44+
REDIS_CACHE_PORT=6379
45+
46+
# ------------- redis queue -------------
47+
REDIS_QUEUE_HOST="redis"
48+
REDIS_QUEUE_PORT=6379
49+
50+
# ------------- redis rate limit -------------
51+
REDIS_RATE_LIMIT_HOST="redis"
52+
REDIS_RATE_LIMIT_PORT=6379
53+
54+
# ------------- client side cache -------------
55+
CLIENT_CACHE_MAX_AGE=60
56+
57+
# ------------- test -------------
58+
TEST_NAME="Tester User"
59+
TEST_EMAIL="[email protected]"
60+
TEST_USERNAME="testeruser"
61+
TEST_PASSWORD="Str1ngT3st!"
62+
63+
# ------------- environment -------------
64+
ENVIRONMENT="staging"
65+
66+
# ------------- first tier -------------
67+
TIER_NAME="free"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# --------- requirements ---------
2+
3+
FROM python:3.11 as requirements-stage
4+
5+
WORKDIR /tmp
6+
7+
RUN pip install poetry
8+
9+
COPY ./pyproject.toml ./poetry.lock* /tmp/
10+
11+
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes
12+
13+
14+
# --------- final image build ---------
15+
FROM python:3.11
16+
17+
WORKDIR /code
18+
19+
COPY --from=requirements-stage /tmp/requirements.txt /code/requirements.txt
20+
21+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
22+
23+
COPY ./src/app /code/app
24+
25+
# -------- replace with comment to run with gunicorn --------
26+
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
27+
CMD ["gunicorn", "app.main:app", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "-b", "0.0.0.0:8000"]
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
services:
2+
web:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
# -------- Both of the following commands should be commented to run with nginx --------
7+
8+
# -------- replace with comment to run with gunicorn or just uvicorn --------
9+
# command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
10+
command: gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8000
11+
env_file:
12+
- ./src/.env
13+
# -------- replace with expose if you are using nginx --------
14+
ports:
15+
- "8000:8000"
16+
# expose:
17+
# - "8000"
18+
depends_on:
19+
- db
20+
- redis
21+
volumes:
22+
- ./src/app:/code/app
23+
- ./src/.env:/code/.env
24+
25+
worker:
26+
build:
27+
context: .
28+
dockerfile: Dockerfile
29+
command: arq app.core.worker.settings.WorkerSettings
30+
env_file:
31+
- ./src/.env
32+
depends_on:
33+
- db
34+
- redis
35+
volumes:
36+
- ./src/app:/code/app
37+
- ./src/.env:/code/.env
38+
39+
db:
40+
image: postgres:13
41+
env_file:
42+
- ./src/.env
43+
volumes:
44+
- postgres-data:/var/lib/postgresql/data
45+
expose:
46+
- "5432"
47+
48+
redis:
49+
image: redis:alpine
50+
volumes:
51+
- redis-data:/data
52+
expose:
53+
- "6379"
54+
55+
#-------- uncomment to run with nginx --------
56+
# nginx:
57+
# image: nginx:latest
58+
# ports:
59+
# - "80:80"
60+
# volumes:
61+
# - ./default.conf:/etc/nginx/conf.d/default.conf
62+
# depends_on:
63+
# - web
64+
65+
#-------- uncomment to create first superuser --------
66+
create_superuser:
67+
build:
68+
context: .
69+
dockerfile: Dockerfile
70+
env_file:
71+
- ./src/.env
72+
depends_on:
73+
- db
74+
- web
75+
command: python -m src.scripts.create_first_superuser
76+
volumes:
77+
- ./src:/code/src
78+
79+
#-------- uncomment to run tests --------
80+
# pytest:
81+
# build:
82+
# context: .
83+
# dockerfile: Dockerfile
84+
# env_file:
85+
# - ./src/.env
86+
# depends_on:
87+
# - db
88+
# - create_superuser
89+
# - redis
90+
# command: python -m pytest ./tests
91+
# volumes:
92+
# - .:/code
93+
94+
#-------- uncomment to create first tier --------
95+
# create_tier:
96+
# build:
97+
# context: .
98+
# dockerfile: Dockerfile
99+
# env_file:
100+
# - ./src/.env
101+
# depends_on:
102+
# - create_superuser
103+
# - db
104+
# - web
105+
# command: python -m src.scripts.create_first_tier
106+
# volumes:
107+
# - ./src:/code/src
108+
109+
volumes:
110+
postgres-data:
111+
redis-data:
112+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# ============================================================================
2+
# WARNING: EXAMPLE CONFIGURATION - DO NOT USE IN PRODUCTION AS-IS
3+
# ============================================================================
4+
# This file contains example values for development/testing purposes only.
5+
#
6+
# SECURITY CRITICAL: Before deploying to production, you MUST:
7+
# 1. Copy this file to src/.env
8+
# 2. Generate a new SECRET_KEY using: openssl rand -hex 32
9+
# 3. Change all passwords (POSTGRES_PASSWORD, ADMIN_PASSWORD, etc.)
10+
# 4. Update all sensitive configuration values
11+
#
12+
# Using these example values in production is a SECURITY RISK.
13+
# ============================================================================
14+
15+
# ------------- app settings -------------
16+
APP_NAME="My Project"
17+
APP_DESCRIPTION="My Project Description"
18+
APP_VERSION="0.1"
19+
CONTACT_NAME="Me"
20+
CONTACT_EMAIL="[email protected]"
21+
LICENSE_NAME="MIT"
22+
23+
# ------------- database -------------
24+
POSTGRES_USER="postgres"
25+
POSTGRES_PASSWORD=1234
26+
POSTGRES_SERVER="db"
27+
POSTGRES_PORT=5432
28+
POSTGRES_DB="postgres"
29+
POSTGRES_ASYNC_PREFIX="postgresql+asyncpg://"
30+
31+
# ------------- crypt -------------
32+
SECRET_KEY=de2132a4a3a029d6a93a2aefcb519f0219990f92ca258a7c5ed938a444dbe1c8
33+
ALGORITHM=HS256
34+
ACCESS_TOKEN_EXPIRE_MINUTES=60
35+
36+
# ------------- admin -------------
37+
ADMIN_NAME="admin"
38+
ADMIN_EMAIL="[email protected]"
39+
ADMIN_USERNAME="admin"
40+
ADMIN_PASSWORD="Str1ngst!"
41+
42+
# ------------- redis cache -------------
43+
REDIS_CACHE_HOST="redis"
44+
REDIS_CACHE_PORT=6379
45+
46+
# ------------- redis queue -------------
47+
REDIS_QUEUE_HOST="redis"
48+
REDIS_QUEUE_PORT=6379
49+
50+
# ------------- redis rate limit -------------
51+
REDIS_RATE_LIMIT_HOST="redis"
52+
REDIS_RATE_LIMIT_PORT=6379
53+
54+
# ------------- client side cache -------------
55+
CLIENT_CACHE_MAX_AGE=60
56+
57+
# ------------- test -------------
58+
TEST_NAME="Tester User"
59+
TEST_EMAIL="[email protected]"
60+
TEST_USERNAME="testeruser"
61+
TEST_PASSWORD="Str1ngT3st!"
62+
63+
# ------------- environment -------------
64+
ENVIRONMENT="local"
65+
66+
# ------------- first tier -------------
67+
TIER_NAME="free"
File renamed without changes.

0 commit comments

Comments
 (0)