docker中添加auth的配置;创建auth的测试程序和requirements.txt文件
This commit is contained in:
parent
c246ffc676
commit
f7d230f11b
1
.gitignore
vendored
1
.gitignore
vendored
@ -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
18
backend/auth/app.py
Normal 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)
|
||||
1
backend/auth/dockerfile/.dockerignore
Normal file
1
backend/auth/dockerfile/.dockerignore
Normal file
@ -0,0 +1 @@
|
||||
../.venv/
|
||||
12
backend/auth/dockerfile/Dockerfile
Normal file
12
backend/auth/dockerfile/Dockerfile
Normal 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"]
|
||||
10
backend/auth/requirements.txt
Normal file
10
backend/auth/requirements.txt
Normal 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
|
||||
@ -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
|
||||
Loading…
Reference in New Issue
Block a user