bugfix: 修复Dockerfile错误
This commit is contained in:
parent
2ee8beb276
commit
598bb654c7
|
|
@ -16,11 +16,10 @@ COPY pyproject.toml .
|
||||||
# && apt-get clean
|
# && apt-get clean
|
||||||
|
|
||||||
# RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --prefix=/install
|
# RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --prefix=/install
|
||||||
RUN pip install -r poetry -i https://mirrors.aliyun.com/pypi/simple/
|
RUN pip install poetry -i https://mirrors.aliyun.com/pypi/simple/ \
|
||||||
|
&& poetry source add --priority=primary mirrors https://pypi.tuna.tsinghua.edu.cn/simple/ \
|
||||||
|
&& poetry install -C /install
|
||||||
|
|
||||||
RUN poetry source add --priority=primary mirrors https://pypi.tuna.tsinghua.edu.cn/simple/
|
|
||||||
|
|
||||||
RUN poetry install -C /install
|
|
||||||
# 应用启动
|
# 应用启动
|
||||||
FROM python:3.11-slim
|
FROM python:3.11-slim
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,16 @@ lifetime_seconds=3600
|
||||||
|
|
||||||
[mysql]
|
[mysql]
|
||||||
username=root
|
username=root
|
||||||
password=123456
|
password=Chenweijia113!
|
||||||
host=mysql
|
host=127.0.0.1
|
||||||
port=3306
|
port=3306
|
||||||
database=test
|
database=test
|
||||||
|
|
||||||
|
|
||||||
[redis]
|
[redis]
|
||||||
redis_url=""
|
redis_host=127.0.0.1
|
||||||
redis_host=redis
|
|
||||||
redis_port=6379
|
redis_port=6379
|
||||||
redis_password=""
|
redis_password=
|
||||||
|
|
||||||
[rabbitmq]
|
[rabbitmq]
|
||||||
rabbitmq_host=rabbitmq
|
rabbitmq_host=rabbitmq
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,16 @@ lifetime_seconds=3600
|
||||||
|
|
||||||
[mysql]
|
[mysql]
|
||||||
username=root
|
username=root
|
||||||
password=123456
|
password=Chenweijia113!
|
||||||
host=mysql
|
host=mysql
|
||||||
port=3306
|
port=3306
|
||||||
database=test
|
database=test
|
||||||
|
|
||||||
|
|
||||||
[redis]
|
[redis]
|
||||||
redis_url=""
|
|
||||||
redis_host=redis
|
redis_host=redis
|
||||||
redis_port=6379
|
redis_port=6379
|
||||||
redis_password=""
|
redis_password=Chenweijia113!
|
||||||
|
|
||||||
[rabbitmq]
|
[rabbitmq]
|
||||||
rabbitmq_host=rabbitmq
|
rabbitmq_host=rabbitmq
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ class MySQLConfig(BaseSettings):
|
||||||
|
|
||||||
|
|
||||||
class RedisConfig(RedisSettings):
|
class RedisConfig(RedisSettings):
|
||||||
redis_url: str = None
|
|
||||||
redis_host: Optional[str] = 'localhost'
|
redis_host: Optional[str] = 'localhost'
|
||||||
redis_port: Optional[int] = 6379
|
redis_port: Optional[int] = 6379
|
||||||
redis_password: str = None
|
redis_password: str = None
|
||||||
|
|
@ -60,7 +59,7 @@ def init_config():
|
||||||
# common_config = CommonConfig(**dict(config.items('common')))
|
# common_config = CommonConfig(**dict(config.items('common')))
|
||||||
mysql_config = MySQLConfig(**dict(config.items('mysql')))
|
mysql_config = MySQLConfig(**dict(config.items('mysql')))
|
||||||
redis_config = RedisConfig(**dict(config.items('redis')))
|
redis_config = RedisConfig(**dict(config.items('redis')))
|
||||||
rabbitmq_config = RabbitmqConfig(**dict(config.items("rabbitmq")))
|
# rabbitmq_config = RabbitmqConfig(**dict(config.items("rabbitmq")))
|
||||||
# return common_config, mysql_config, redis_config, rabbitmq_config
|
# return common_config, mysql_config, redis_config, rabbitmq_config
|
||||||
return mysql_config, redis_config
|
return mysql_config, redis_config
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
14
main.py
14
main.py
|
|
@ -15,6 +15,11 @@ from src.utils.exception import (http_exception_handler,
|
||||||
def create_app():
|
def create_app():
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
mysql_config, redis_config = init_config()
|
||||||
|
# 添加sqlalchemy数据库中间件
|
||||||
|
# once the middleware is applied, any route can then access the database session from the global ``db``
|
||||||
|
app.add_middleware(DBSessionMiddleware, db_url=mysql_config.sqlalchemy_db_uri)
|
||||||
|
|
||||||
@app.on_event("startup")
|
@app.on_event("startup")
|
||||||
async def startup_event():
|
async def startup_event():
|
||||||
# 创建日志文件夹和临时文件上传文件夹
|
# 创建日志文件夹和临时文件上传文件夹
|
||||||
|
|
@ -26,13 +31,10 @@ def create_app():
|
||||||
os.mkdir("logs")
|
os.mkdir("logs")
|
||||||
logging_config.fileConfig('conf/log.ini')
|
logging_config.fileConfig('conf/log.ini')
|
||||||
# 初始化配置文件
|
# 初始化配置文件
|
||||||
mysql_config, redis_config = init_config()
|
|
||||||
# 添加sqlalchemy数据库中间件
|
|
||||||
# once the middleware is applied, any route can then access the database session from the global ``db``
|
|
||||||
# app.add_middleware(DBSessionMiddleware, db_url=mysql_config.sqlalchemy_db_uri)
|
|
||||||
# Redis 缓存初始化
|
# Redis 缓存初始化
|
||||||
# await fastapi_plugins.redis_plugin.init_app(app, redis_config)
|
print(redis_config)
|
||||||
# await fastapi_plugins.redis_plugin.init()
|
await fastapi_plugins.redis_plugin.init_app(app, redis_config)
|
||||||
|
await fastapi_plugins.redis_plugin.init()
|
||||||
|
|
||||||
@app.on_event("shutdown")
|
@app.on_event("shutdown")
|
||||||
async def shutdown_event():
|
async def shutdown_event():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue