mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-09-21 13:12:24 +00:00
Refactor the backend architecture (#299)
* define the basic architecture * Update script and deployment file locations * Update the route registration * Fix CI download dependencies * Updated ruff to 0.3.3 * Update app subdirectory naming * Update the model import * fix pre-commit pdm lock * Update the service directory naming * Add CRUD method documents * Fix the issue of circular import * Update the README document * Update the SQL statement for create tables * Update docker scripts and documentation * Fix docker scripts * Update the backend README.md * Add the security folder and move the redis client * Update the configuration item * Fix environment configuration reads * Update the default configuration * Updated README description * Updated the user registration API * Fix test cases * Update the celery configuration * Update and fix celery configuration * Updated the celery structure * Update celery tasks and api * Add celery flower * Update the import style * Update contributors
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
[program:celery_worker]
|
||||
directory=/fba/backend
|
||||
command=/usr/local/bin/celery -A app.task.celery worker --loglevel=INFO
|
||||
user=root
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startretries=5
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/var/log/celery/fba_celery_worker.log
|
||||
|
||||
[program:celery_beat]
|
||||
directory=/fba/backend
|
||||
command=/usr/local/bin/celery -A app.task.celery beat --loglevel=INFO
|
||||
user=root
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startretries=5
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/var/log/celery/fba_celery_beat.log
|
||||
|
||||
[program:celery_flower]
|
||||
directory=/fba/backend
|
||||
command=/usr/local/bin/celery -A app.task.celery flower --port=8555 --basic-auth=admin:123456
|
||||
user=root
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startretries=5
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/var/log/celery/fba_celery_flower.log
|
||||
@@ -1,3 +1,3 @@
|
||||
# Docker
|
||||
DOCKER_DB_MAP_PORT=13306
|
||||
DOCKER_MYSQL_MAP_PORT=13306
|
||||
DOCKER_REDIS_MAP_PORT=16379
|
||||
@@ -1,19 +1,25 @@
|
||||
# Env: dev、pro
|
||||
ENVIRONMENT='dev'
|
||||
# MySQL
|
||||
DB_HOST='fba_mysql'
|
||||
DB_PORT=3306
|
||||
DB_USER='root'
|
||||
DB_PASSWORD='123456'
|
||||
MYSQL_HOST='fba_mysql'
|
||||
MYSQL_PORT=3306
|
||||
MYSQL_USER='root'
|
||||
MYSQL_PASSWORD='123456'
|
||||
# Redis
|
||||
REDIS_HOST='fba_redis'
|
||||
REDIS_PORT=6379
|
||||
REDIS_PASSWORD=''
|
||||
REDIS_DATABASE=0
|
||||
# Token
|
||||
TOKEN_SECRET_KEY='1VkVF75nsNABBjK_7-qz7GtzNy3AMvktc9TCPwKczCk'
|
||||
# Opera Log
|
||||
OPERA_LOG_ENCRYPT_SECRET_KEY='d77b25790a804c2b4a339dd0207941e4cefa5751935a33735bc73bb7071a005b'
|
||||
# Admin
|
||||
# OAuth2
|
||||
OAUTH2_GITHUB_CLIENT_ID='test'
|
||||
OAUTH2_GITHUB_CLIENT_SECRET='test'
|
||||
# Task
|
||||
# Celery
|
||||
CELERY_REDIS_HOST='fba_redis'
|
||||
CELERY_REDIS_PORT=6379
|
||||
CELERY_REDIS_PASSWORD=''
|
||||
CELERY_BROKER_REDIS_DATABASE=1
|
||||
CELERY_BACKEND_REDIS_DATABASE=2
|
||||
# Rabbitmq
|
||||
@@ -21,10 +27,3 @@ RABBITMQ_HOST='fba_rabbitmq'
|
||||
RABBITMQ_PORT=5672
|
||||
RABBITMQ_USERNAME='guest'
|
||||
RABBITMQ_PASSWORD='guest'
|
||||
# Token
|
||||
TOKEN_SECRET_KEY='1VkVF75nsNABBjK_7-qz7GtzNy3AMvktc9TCPwKczCk'
|
||||
# Opera Log
|
||||
OPERA_LOG_ENCRYPT_SECRET_KEY='d77b25790a804c2b4a339dd0207941e4cefa5751935a33735bc73bb7071a005b'
|
||||
# OAuth2
|
||||
OAUTH2_GITHUB_CLIENT_ID='test'
|
||||
OAUTH2_GITHUB_CLIENT_SECRET='test'
|
||||
+11
-8
@@ -22,8 +22,8 @@ volumes:
|
||||
services:
|
||||
fba_server:
|
||||
build:
|
||||
context: ../../
|
||||
dockerfile: backend.dockerfile
|
||||
context: ../../../
|
||||
dockerfile: backend/backend.dockerfile
|
||||
container_name: fba_server
|
||||
restart: always
|
||||
depends_on:
|
||||
@@ -40,13 +40,13 @@ services:
|
||||
- |
|
||||
wait-for-it -s fba_mysql:3306 -s fba_redis:6379 -t 300
|
||||
mkdir -p /var/log/supervisor/
|
||||
supervisord -c /fba/deploy/supervisor.conf
|
||||
supervisord -c /fba/deploy/backend/supervisor.conf
|
||||
supervisorctl restart fastapi_server
|
||||
|
||||
fba_mysql:
|
||||
image: mysql:8.0.29
|
||||
ports:
|
||||
- "${DOCKER_DB_MAP_PORT:-3306}:3306"
|
||||
- "${DOCKER_MYSQL_MAP_PORT:-3306}:3306"
|
||||
container_name: fba_mysql
|
||||
restart: always
|
||||
environment:
|
||||
@@ -88,7 +88,7 @@ services:
|
||||
- fba_server
|
||||
volumes:
|
||||
- ../nginx.conf:/etc/nginx/nginx.conf:ro
|
||||
- fba_static:/www/fba_server/backend/app/static
|
||||
- fba_static:/www/fba_server/backend/static
|
||||
networks:
|
||||
- fba_network
|
||||
|
||||
@@ -110,8 +110,10 @@ services:
|
||||
|
||||
fba_celery:
|
||||
build:
|
||||
context: ../../
|
||||
dockerfile: celery.dockerfile
|
||||
context: ../../../
|
||||
dockerfile: backend/celery.dockerfile
|
||||
ports:
|
||||
- "8555:8555"
|
||||
container_name: fba_celery
|
||||
restart: always
|
||||
depends_on:
|
||||
@@ -124,6 +126,7 @@ services:
|
||||
- |
|
||||
wait-for-it -s fba_rabbitmq:5672 -t 300
|
||||
mkdir -p /var/log/supervisor/
|
||||
supervisord -c /fba/deploy/supervisor.conf
|
||||
supervisord -c /fba/deploy/backend/supervisor.conf
|
||||
supervisorctl restart celery_worker
|
||||
supervisorctl restart celery_beat
|
||||
supervisorctl restart celery_flower
|
||||
@@ -1,6 +1,6 @@
|
||||
[program:fastapi_server]
|
||||
directory=/fba
|
||||
command=/usr/local/bin/gunicorn -c /fba/deploy/gunicorn.conf.py main:app
|
||||
command=/usr/local/bin/gunicorn -c /fba/deploy/backend/gunicorn.conf.py main:app
|
||||
user=root
|
||||
autostart=true
|
||||
autorestart=true
|
||||
@@ -1,8 +1,8 @@
|
||||
# 监听内网端口
|
||||
bind = '0.0.0.0:8001'
|
||||
bind = "0.0.0.0:8001"
|
||||
|
||||
# 工作目录
|
||||
chdir = '/fba/backend/app'
|
||||
chdir = "/fba/backend/"
|
||||
|
||||
# 并行工作进程数
|
||||
workers = 1
|
||||
@@ -22,25 +22,25 @@ timeout = 120
|
||||
daemon = False
|
||||
|
||||
# 工作模式协程
|
||||
worker_class = 'uvicorn.workers.UvicornWorker'
|
||||
worker_class = "uvicorn.workers.UvicornWorker"
|
||||
|
||||
# 设置最大并发量
|
||||
worker_connections = 2000
|
||||
|
||||
# 设置进程文件目录
|
||||
pidfile = '/fba/gunicorn.pid'
|
||||
pidfile = "/fba/gunicorn.pid"
|
||||
|
||||
# 设置访问日志和错误信息日志路径
|
||||
accesslog = '/var/log/fastapi_server/gunicorn_access.log'
|
||||
errorlog = '/var/log/fastapi_server/gunicorn_error.log'
|
||||
accesslog = "/var/log/fastapi_server/gunicorn_access.log"
|
||||
errorlog = "/var/log/fastapi_server/gunicorn_error.log"
|
||||
|
||||
# 设置这个值为true 才会把打印信息记录到错误日志里
|
||||
capture_output = True
|
||||
|
||||
# 设置日志记录水平
|
||||
loglevel = 'debug'
|
||||
loglevel = "debug"
|
||||
|
||||
# python程序
|
||||
pythonpath = '/usr/local/lib/python3.10/site-packages'
|
||||
pythonpath = "/usr/local/lib/python3.10/site-packages"
|
||||
|
||||
# 启动 gunicorn -c gunicorn.conf.py main:app
|
||||
@@ -52,7 +52,7 @@ http {
|
||||
}
|
||||
|
||||
location /static/ {
|
||||
alias /www/fba_server/backend/app/static;
|
||||
alias /www/fba_server/backend/static;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
[program:celery_worker]
|
||||
directory=/fba/backend/app
|
||||
command=/usr/local/bin/celery -A tasks worker --loglevel=INFO
|
||||
user=root
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startretries=5
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/var/log/celery/fba_celery_worker.log
|
||||
|
||||
[program:celery_beat]
|
||||
directory=/fba/backend/app
|
||||
command=/usr/local/bin/celery -A tasks beat --loglevel=INFO
|
||||
user=root
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startretries=5
|
||||
redirect_stderr=true
|
||||
stdout_logfile=/var/log/celery/fba_celery_beat.log
|
||||
Reference in New Issue
Block a user