Files
tyapi-server/docker-compose.prod.yml

172 lines
4.3 KiB
YAML
Raw Normal View History

2025-07-02 16:17:59 +08:00
version: "3.8"
services:
# PostgreSQL 数据库 (生产环境)
postgres:
image: postgres:16.9
container_name: tyapi-postgres-prod
environment:
2025-07-11 21:05:58 +08:00
TZ: Asia/Shanghai
PGTZ: Asia/Shanghai
2025-07-28 02:07:53 +08:00
POSTGRES_DB: tyapi
POSTGRES_USER: tyapi_user
POSTGRES_PASSWORD: Pg9mX4kL8nW2rT5y
2025-07-02 16:17:59 +08:00
POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --lc-collate=C --lc-ctype=C"
# 性能优化配置
POSTGRES_SHARED_PRELOAD_LIBRARIES: pg_stat_statements
volumes:
- postgres_data:/var/lib/postgresql/data
- ./scripts/init.sql:/docker-entrypoint-initdb.d/init.sql
networks:
- tyapi-network
healthcheck:
2025-07-28 02:07:53 +08:00
test: ["CMD-SHELL", "pg_isready -U tyapi_user"]
2025-07-02 16:17:59 +08:00
interval: 30s
timeout: 10s
retries: 5
start_period: 60s
restart: unless-stopped
deploy:
resources:
limits:
memory: 2G
cpus: "1.0"
reservations:
memory: 512M
cpus: "0.5"
2025-07-28 01:46:39 +08:00
# 生产环境暴露数据库端口到主机
ports:
2025-07-28 02:07:53 +08:00
- "25010:5432"
2025-07-02 16:17:59 +08:00
# Redis 缓存 (生产环境)
redis:
image: redis:8.0.2
container_name: tyapi-redis-prod
environment:
2025-07-11 21:05:58 +08:00
TZ: Asia/Shanghai
2025-07-28 02:07:53 +08:00
REDIS_PASSWORD: ""
2025-07-02 16:17:59 +08:00
volumes:
- redis_data:/data
- ./deployments/docker/redis.conf:/usr/local/etc/redis/redis.conf
2025-07-28 02:07:53 +08:00
command: redis-server /usr/local/etc/redis/redis.conf
2025-07-02 16:17:59 +08:00
networks:
- tyapi-network
healthcheck:
2025-07-28 02:07:53 +08:00
test: redis-cli ping
2025-07-02 16:17:59 +08:00
interval: 30s
timeout: 10s
retries: 5
restart: unless-stopped
deploy:
resources:
limits:
memory: 1G
cpus: "0.5"
reservations:
memory: 256M
cpus: "0.2"
# 生产环境不暴露端口到主机
# ports:
# - "6379:6379"
# TYAPI 应用程序
tyapi-app:
2025-07-28 01:46:39 +08:00
build:
context: .
dockerfile: Dockerfile
args:
2025-07-28 02:07:53 +08:00
VERSION: 1.0.0
COMMIT: dev
BUILD_TIME: ""
2025-07-02 16:17:59 +08:00
container_name: tyapi-app-prod
environment:
2025-07-11 21:05:58 +08:00
# 时区配置
TZ: Asia/Shanghai
2025-07-02 16:17:59 +08:00
# 环境设置
ENV: production
# 服务器配置
2025-07-28 02:07:53 +08:00
SERVER_PORT: 8080
2025-07-02 16:17:59 +08:00
SERVER_MODE: release
# 数据库配置
DB_HOST: postgres
DB_PORT: 5432
2025-07-28 02:07:53 +08:00
DB_USER: tyapi_user
DB_PASSWORD: Pg9mX4kL8nW2rT5y
DB_NAME: tyapi
DB_SSLMODE: require
2025-07-02 16:17:59 +08:00
# Redis配置
REDIS_HOST: redis
REDIS_PORT: 6379
2025-07-28 02:07:53 +08:00
REDIS_PASSWORD: ""
2025-07-02 16:17:59 +08:00
# JWT配置
2025-07-28 02:07:53 +08:00
JWT_SECRET: JwT8xR4mN9vP2sL7kH3oB6yC1zA5uF0qE9tW
2025-07-02 16:17:59 +08:00
# 监控配置
2025-07-28 01:46:39 +08:00
TRACING_ENABLED: false
METRICS_ENABLED: false
2025-07-02 16:17:59 +08:00
# 日志配置
2025-07-28 02:07:53 +08:00
LOG_LEVEL: warn
2025-07-02 16:17:59 +08:00
LOG_FORMAT: json
# 短信配置
2025-07-28 02:07:53 +08:00
SMS_ACCESS_KEY_ID: LTAI5tKGB3TVJbMHSoZN3yr9
SMS_ACCESS_KEY_SECRET: OCQ30GWp4yENMjmfOAaagksE18bp65
SMS_SIGN_NAME: 天远数据
SMS_TEMPLATE_CODE: SMS_474525324
2025-07-02 16:17:59 +08:00
ports:
2025-07-28 02:07:53 +08:00
- "25000:8080"
2025-07-02 16:17:59 +08:00
volumes:
- app_logs:/app/logs
networks:
- tyapi-network
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 5
start_period: 60s
restart: unless-stopped
deploy:
resources:
limits:
memory: 1G
cpus: "1.0"
reservations:
memory: 256M
cpus: "0.3"
2025-07-28 01:46:39 +08:00
2025-07-02 16:17:59 +08:00
volumes:
postgres_data:
driver: local
redis_data:
driver: local
app_logs:
driver: local
networks:
tyapi-network:
driver: bridge