Secret key multi-worker generating bugfix, volume instead of dir in mariadb, upd deps
This commit is contained in:
parent
4509d02425
commit
edbf0233ba
6 changed files with 64 additions and 16 deletions
6
.env
6
.env
|
@ -1,6 +1,12 @@
|
|||
APP_HOST=0.0.0.0
|
||||
APP_PORT=8000
|
||||
|
||||
# Generate a strong secret key
|
||||
# On Linux: openssl rand -hex 32
|
||||
# If this variable is not set,
|
||||
# the key is generated automatically
|
||||
#SECRET_KEY=secret
|
||||
|
||||
DB_HOST=${REPO_NAME_SNAKE}_db
|
||||
DB_PORT=3306
|
||||
DB_USER=${REPO_NAME_SNAKE}
|
||||
|
|
|
@ -7,26 +7,47 @@ from pydantic import BaseSettings
|
|||
|
||||
# Directories
|
||||
file_dir = Path(__file__).parent
|
||||
templates_dir = str(
|
||||
file_dir.parent / 'templates'
|
||||
)
|
||||
static_dir = str(
|
||||
file_dir.parent / 'static'
|
||||
)
|
||||
templates_dir = str(file_dir.parent / 'templates')
|
||||
static_dir = str(file_dir.parent / 'static')
|
||||
|
||||
|
||||
# Main configuration
|
||||
class Settings(BaseSettings):
|
||||
debug: bool = False
|
||||
secret_key: str = secrets.token_hex(32)
|
||||
secret_key: str = 'secret'
|
||||
app_host: str = '127.0.0.1'
|
||||
app_port: int = 8000
|
||||
|
||||
|
||||
# Instantiate Settings class
|
||||
settings = Settings()
|
||||
|
||||
|
||||
# Jinja templates handler
|
||||
templates = Jinja2Templates(
|
||||
directory=templates_dir,
|
||||
)
|
||||
|
||||
|
||||
def secret_key_check() -> None:
|
||||
"""Generates a secret key automatically
|
||||
if the env var `secret_key` is not set
|
||||
or contains text `secret`"""
|
||||
|
||||
if settings.secret_key == 'secret':
|
||||
|
||||
key_file = Path('/tmp/secret_key')
|
||||
|
||||
if key_file.exists():
|
||||
with key_file.open('rt') as f:
|
||||
secret_key = f.read()
|
||||
|
||||
else:
|
||||
secret_key = secrets.token_hex(32)
|
||||
with key_file.open('wt') as f:
|
||||
f.write(secret_key)
|
||||
|
||||
settings.secret_key = secret_key
|
||||
|
||||
|
||||
# Call the function
|
||||
secret_key_check()
|
||||
|
|
|
@ -20,10 +20,14 @@ services:
|
|||
container_name: ${REPO_NAME_SNAKE}_db
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- "./database:/var/lib/mysql"
|
||||
#- "./database:/var/lib/mysql"
|
||||
- "db_data:/var/lib/mysql"
|
||||
env_file: .env_db
|
||||
healthcheck:
|
||||
test: sh -c "mysqladmin ping -u$$$$MYSQL_USER -p$$$$MYSQL_PASSWORD"
|
||||
interval: 1s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
|
||||
volumes:
|
||||
db_data:
|
||||
|
|
4
mypy.ini
4
mypy.ini
|
@ -1,4 +0,0 @@
|
|||
[mypy]
|
||||
show_error_codes = True
|
||||
ignore_missing_imports = True
|
||||
warn_redundant_casts = True
|
21
pyproject.toml
Normal file
21
pyproject.toml
Normal file
|
@ -0,0 +1,21 @@
|
|||
[project]
|
||||
name = "app"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"fastapi",
|
||||
"uvicorn[standard]",
|
||||
"jinja2",
|
||||
"starlette-wtf",
|
||||
"sqlalchemy",
|
||||
"sqlalchemy-utils",
|
||||
"mysqlclient",
|
||||
"python-dotenv",
|
||||
]
|
||||
|
||||
[tool.setuptools]
|
||||
packages = []
|
||||
|
||||
[tool.mypy]
|
||||
show_error_codes = true
|
||||
ignore_missing_imports = true
|
||||
warn_redundant_casts = true
|
|
@ -1,8 +1,8 @@
|
|||
fastapi~=0.93.0
|
||||
starlette~=0.25.0
|
||||
pydantic~=1.10.6
|
||||
starlette
|
||||
pydantic
|
||||
|
||||
uvicorn[standard]~=0.20.0
|
||||
uvicorn[standard]~=0.21.0
|
||||
gunicorn~=20.1.0
|
||||
|
||||
jinja2~=3.1.2
|
||||
|
|
Loading…
Add table
Reference in a new issue