Skip to content

Commit c34cf1c

Browse files
committed
making the requested changes
1 parent 77d09fe commit c34cf1c

File tree

12 files changed

+804
-2110
lines changed

12 files changed

+804
-2110
lines changed

README.md

Lines changed: 113 additions & 2110 deletions
Large diffs are not rendered by default.

docs/getting-started/configuration.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,25 @@ DEFAULT_RATE_LIMIT_LIMIT=10 # Default: 10 requests
115115
DEFAULT_RATE_LIMIT_PERIOD=3600 # Default: 3600 seconds (1 hour)
116116
```
117117

118+
### CORS Configuration
119+
120+
Configure Cross-Origin Resource Sharing for your frontend:
121+
122+
```env
123+
# CORS Settings
124+
CORS_ORIGINS="*" # Comma-separated origins (use specific domains in production)
125+
CORS_METHODS="*" # Comma-separated HTTP methods or "*" for all
126+
CORS_HEADERS="*" # Comma-separated headers or "*" for all
127+
```
128+
129+
!!! warning "CORS in Production"
130+
Never use `"*"` for CORS_ORIGINS in production. Specify exact domains:
131+
```env
132+
CORS_ORIGINS="https://yourapp.com,https://www.yourapp.com"
133+
CORS_METHODS="GET,POST,PUT,DELETE,PATCH"
134+
CORS_HEADERS="Authorization,Content-Type"
135+
```
136+
118137
### First Tier
119138

120139
```env

docs/user-guide/configuration/environment-variables.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,40 @@ ADMIN_PASSWORD="secure_admin_password"
172172
- `ADMIN_USERNAME`: Username for admin login
173173
- `ADMIN_PASSWORD`: Initial password (change after first login)
174174

175+
### CORS Configuration
176+
177+
Cross-Origin Resource Sharing (CORS) settings for frontend integration:
178+
179+
```env
180+
# ------------- CORS -------------
181+
CORS_ORIGINS="*"
182+
CORS_METHODS="*"
183+
CORS_HEADERS="*"
184+
```
185+
186+
**Variables Explained:**
187+
188+
- `CORS_ORIGINS`: Comma-separated list of allowed origins (e.g., `"https://app.com,https://www.app.com"`)
189+
- `CORS_METHODS`: Comma-separated list of allowed HTTP methods (e.g., `"GET,POST,PUT,DELETE"`)
190+
- `CORS_HEADERS`: Comma-separated list of allowed headers (e.g., `"Authorization,Content-Type"`)
191+
192+
**Environment-Specific Values:**
193+
194+
```env
195+
# Development - Allow all origins
196+
CORS_ORIGINS="*"
197+
CORS_METHODS="*"
198+
CORS_HEADERS="*"
199+
200+
# Production - Specific domains only
201+
CORS_ORIGINS="https://yourapp.com,https://www.yourapp.com"
202+
CORS_METHODS="GET,POST,PUT,DELETE,PATCH"
203+
CORS_HEADERS="Authorization,Content-Type,X-Requested-With"
204+
```
205+
206+
!!! danger "Security Warning"
207+
Never use wildcard (`*`) for `CORS_ORIGINS` in production environments. Always specify exact allowed domains to prevent unauthorized cross-origin requests.
208+
175209
### User Tiers
176210

177211
Initial tier configuration:
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: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
# ------------- CORS -------------
58+
CORS_ORIGINS="*"
59+
CORS_METHODS="*"
60+
CORS_HEADERS="*"
61+
62+
# ------------- test -------------
63+
TEST_NAME="Tester User"
64+
TEST_EMAIL="[email protected]"
65+
TEST_USERNAME="testeruser"
66+
TEST_PASSWORD="Str1ngT3st!"
67+
68+
# ------------- environment -------------
69+
ENVIRONMENT="local"
70+
71+
# ------------- first tier -------------
72+
TIER_NAME="free"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# --------- Builder Stage ---------
2+
FROM ghcr.io/astral-sh/uv:python3.11-bookworm-slim AS builder
3+
4+
# Set environment variables for uv
5+
ENV UV_COMPILE_BYTECODE=1
6+
ENV UV_LINK_MODE=copy
7+
8+
WORKDIR /app
9+
10+
# Install dependencies first (for better layer caching)
11+
RUN --mount=type=cache,target=/root/.cache/uv \
12+
--mount=type=bind,source=uv.lock,target=uv.lock \
13+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
14+
uv sync --locked --no-install-project
15+
16+
# Copy the project source code
17+
COPY . /app
18+
19+
# Install the project in non-editable mode
20+
RUN --mount=type=cache,target=/root/.cache/uv \
21+
uv sync --locked --no-editable
22+
23+
# --------- Final Stage ---------
24+
FROM python:3.11-slim-bookworm
25+
26+
# Create a non-root user for security
27+
RUN groupadd --gid 1000 app \
28+
&& useradd --uid 1000 --gid app --shell /bin/bash --create-home app
29+
30+
# Copy the virtual environment from the builder stage
31+
COPY --from=builder --chown=app:app /app/.venv /app/.venv
32+
33+
# Ensure the virtual environment is in the PATH
34+
ENV PATH="/app/.venv/bin:$PATH"
35+
36+
# Switch to the non-root user
37+
USER app
38+
39+
# Set the working directory
40+
WORKDIR /code
41+
42+
# -------- replace with comment to run with gunicorn --------
43+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
44+
# CMD ["gunicorn", "app.main:app", "-w", "4", "-k", "uvicorn.workers.UvicornWorker", "-b", "0.0.0.0:8000"]

0 commit comments

Comments
 (0)