Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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,219 changes: 91 additions & 2,128 deletions README.md

Large diffs are not rendered by default.

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

This file was deleted.

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