docker中添加auth的配置;创建auth的测试程序和requirements.txt文件

This commit is contained in:
jayhgq 2026-02-24 22:43:16 +08:00
parent c246ffc676
commit f7d230f11b
7 changed files with 80 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.trae/documents/add_traefik_config_plan.md
redis/data/dump.rdb
redis/logs/redis-server.log
backend/auth/__pycache__/app.cpython-313.pyc

18
backend/auth/app.py Normal file
View File

@ -0,0 +1,18 @@
from fastapi import FastAPI
#实例化FastAPI
app = FastAPI()
# 声明装饰器方法和路径
@app.get("/")
# 声明装饰器函数
async def home():
return {"message": "Hello World"}
# 如果使用命令行启动使用uvicorn 文件名:app --reload启动即可下面命令就不用写
# 如果写下面的命令就不需要命令行启动了直接用IDE运行即可
if __name__ == "__main__":
import uvicorn
import os
name = f"{os.path.splitext(os.path.basename(os.path.abspath(__file__)))[0]}:app"
uvicorn.run(name, host="0.0.0.0", port=8000)

View File

@ -0,0 +1 @@
../.venv/

View File

@ -0,0 +1,12 @@
FROM python:3.13-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY .. .
EXPOSE 8000
CMD ["python", "app.py"]

View File

@ -0,0 +1,10 @@
# FastAPI核心
fastapi>=0.133.0
uvicorn[standard]>=0.41.0
# PostgreSQL + SQLAlchemy ORM包含异步支持
sqlalchemy>=2.0.46
asyncpg>=0.31.0
# Redis异步客户端
redis>=7.2.0

View File

@ -100,6 +100,44 @@ services:
networks:
- bs-network
# Auth 服务
auth:
build:
context: ../backend/auth/dockerfile
dockerfile: Dockerfile
container_name: bs-auth
restart: always
ports:
- "${AUTH_PORT}:8000"
volumes:
# 挂载宿主机代码目录到容器,实现实时同步
- ../backend/auth:/app
environment:
- DB_HOST=postgres
- DB_PORT=5432
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DB_NAME=${DB_NAME}
- REDIS_HOST=redis
- REDIS_PORT=6379
- REDIS_PASSWORD=${REDIS_PASSWORD}
depends_on:
- postgres
- redis
labels:
# Traefik 配置
- "traefik.enable=true"
- "traefik.docker.network=bs-network"
- "traefik.http.routers.auth.rule=Host(`localhost`) && PathPrefix(`/auth`)"
- "traefik.http.services.auth.loadbalancer.server.port=8000"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
timeout: 10s
retries: 3
networks:
- bs-network
networks:
bs-network:
driver: bridge