- 从 nginx X-Authenticated-User header 获取用户名 - 自动查找/创建用户 - 颁发 8小时有效期 JWT token - 安全机制:只 trusting nginx-verified header - 集成到 FastAPI router - 依赖:PyJWT - 文档:注释中包含完整使用说明
121 lines
2.9 KiB
YAML
121 lines
2.9 KiB
YAML
# PLM Test Environment Docker Compose
|
|
# 测试环境部署配置
|
|
# 访问地址: http://localhost:3800
|
|
|
|
version: '3.8'
|
|
|
|
services:
|
|
# PostgreSQL 14 Database
|
|
postgres:
|
|
image: postgres:14-alpine
|
|
container_name: plm-test-postgres
|
|
restart: unless-stopped
|
|
environment:
|
|
POSTGRES_USER: plm
|
|
POSTGRES_PASSWORD: plm123456
|
|
POSTGRES_DB: plm_dev
|
|
PGDATA: /var/lib/postgresql/data/pgdata
|
|
volumes:
|
|
- postgres_data:/var/lib/postgresql/data
|
|
# 不暴露端口,仅内部网络访问
|
|
networks:
|
|
- plm-test-network
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "pg_isready -U plm -d plm_dev"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
|
|
# Redis Cache
|
|
redis:
|
|
image: redis:7-alpine
|
|
container_name: plm-test-redis
|
|
restart: unless-stopped
|
|
volumes:
|
|
- redis_data:/data
|
|
# 不暴露端口,仅内部网络访问
|
|
networks:
|
|
- plm-test-network
|
|
command: redis-server --appendonly yes
|
|
healthcheck:
|
|
test: ["CMD", "redis-cli", "ping"]
|
|
interval: 10s
|
|
timeout: 5s
|
|
retries: 5
|
|
|
|
# PLM Backend Service
|
|
backend:
|
|
build:
|
|
context: .
|
|
dockerfile: Dockerfile
|
|
container_name: plm-test-backend
|
|
restart: unless-stopped
|
|
environment:
|
|
# Application
|
|
APP_NAME: PLM System
|
|
APP_VERSION: 1.0.0
|
|
DEBUG: "true"
|
|
ENVIRONMENT: development
|
|
# Server
|
|
HOST: 0.0.0.0
|
|
PORT: 8000
|
|
WORKERS: 1
|
|
# Database
|
|
DATABASE_URL: postgresql+asyncpg://plm:plm123456@postgres:5432/plm_dev
|
|
DATABASE_SYNC_URL: postgresql://plm:plm123456@postgres:5432/plm_dev
|
|
DB_POOL_SIZE: 10
|
|
DB_MAX_OVERFLOW: 20
|
|
# Redis
|
|
REDIS_URL: redis://redis:6379/0
|
|
REDIS_PASSWORD: ""
|
|
# JWT
|
|
JWT_SECRET_KEY: plm-test-secret-key-2024
|
|
JWT_ALGORITHM: HS256
|
|
JWT_ACCESS_TOKEN_EXPIRE_MINUTES: 30
|
|
JWT_REFRESH_TOKEN_EXPIRE_DAYS: 7
|
|
# CORS
|
|
CORS_ORIGINS: '["http://localhost:3800","http://localhost:8000","*"]'
|
|
# Security
|
|
PASSWORD_MIN_LENGTH: 8
|
|
PASSWORD_REQUIRE_UPPERCASE: "true"
|
|
PASSWORD_REQUIRE_LOWERCASE: "true"
|
|
PASSWORD_REQUIRE_DIGIT: "true"
|
|
PASSWORD_REQUIRE_SPECIAL: "false"
|
|
ports:
|
|
- "8000:8000"
|
|
networks:
|
|
- plm-test-network
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
redis:
|
|
condition: service_healthy
|
|
healthcheck:
|
|
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
|
|
# PLM Frontend Service (Simple HTML for testing)
|
|
frontend:
|
|
image: nginx:alpine
|
|
container_name: plm-test-frontend
|
|
restart: unless-stopped
|
|
ports:
|
|
- "3800:80"
|
|
volumes:
|
|
- ./nginx/html:/usr/share/nginx/html:ro
|
|
- ./nginx/test-frontend.conf:/etc/nginx/conf.d/default.conf:ro
|
|
depends_on:
|
|
- backend
|
|
networks:
|
|
- plm-test-network
|
|
|
|
networks:
|
|
plm-test-network:
|
|
driver: bridge
|
|
|
|
volumes:
|
|
postgres_data:
|
|
redis_data:
|