docker-compose.yml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. version: '3.7'
  2. services:
  3. # ==========================================
  4. # Nginx (Frontend Production)
  5. # ==========================================
  6. nginx:
  7. build:
  8. context: ./frontend
  9. target: production-stage
  10. args:
  11. # Defaults to /api/v1 which works with the proxy config in nginx.conf
  12. - VITE_API_BASE_URL=/api/v1
  13. ports:
  14. - "80:80"
  15. # - "443:443" # Uncomment if you configure SSL in nginx.conf
  16. depends_on:
  17. - backend
  18. restart: always
  19. # ==========================================
  20. # Backend (FastAPI)
  21. # ==========================================
  22. backend:
  23. build:
  24. context: ./backend
  25. environment:
  26. - TZ=Asia/Shanghai
  27. - MYSQL_SERVER=db
  28. - MYSQL_PORT=3306
  29. - MYSQL_USER=uap_user
  30. - MYSQL_PASSWORD=uap_pass
  31. - MYSQL_DB=uap_db
  32. - REDIS_HOST=redis
  33. - REDIS_PORT=6379
  34. - HYDRA_ADMIN_URL=http://hydra:4445
  35. # CORS: Add your production domain here
  36. - BACKEND_CORS_ORIGINS=["http://localhost", "http://127.0.0.1", "http://YOUR_DOMAIN_OR_IP"]
  37. depends_on:
  38. db:
  39. condition: service_healthy
  40. redis:
  41. condition: service_healthy
  42. hydra:
  43. condition: service_started
  44. volumes:
  45. - ./backend/logs:/app/logs # Persist logs
  46. # - ./backend:/app # Remove hot reload in production for stability
  47. restart: always
  48. # ==========================================
  49. # Database (MySQL)
  50. # ==========================================
  51. db:
  52. image: mysql:8.0
  53. command: --default-authentication-plugin=mysql_native_password
  54. restart: always
  55. environment:
  56. TZ: Asia/Shanghai
  57. MYSQL_ROOT_PASSWORD: root_password # CHANGE THIS IN PRODUCTION
  58. MYSQL_DATABASE: uap_db
  59. MYSQL_USER: uap_user
  60. MYSQL_PASSWORD: uap_pass # CHANGE THIS IN PRODUCTION
  61. volumes:
  62. - db_data:/var/lib/mysql
  63. healthcheck:
  64. test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost", "-u", "uap_user", "-p$$MYSQL_PASSWORD"]
  65. interval: 10s
  66. timeout: 5s
  67. retries: 10
  68. start_period: 10s
  69. # ==========================================
  70. # Redis
  71. # ==========================================
  72. redis:
  73. image: redis:alpine
  74. restart: always
  75. volumes:
  76. - redis_data:/data
  77. healthcheck:
  78. test: ["CMD", "redis-cli", "ping"]
  79. interval: 10s
  80. timeout: 5s
  81. retries: 5
  82. # ==========================================
  83. # Ory Hydra Services
  84. # ==========================================
  85. hydra-migrate:
  86. image: oryd/hydra:v2.2.0
  87. environment:
  88. - TZ=Asia/Shanghai
  89. - DSN=postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable&max_conns=20&max_idle_conns=4
  90. command: migrate sql -e --yes
  91. depends_on:
  92. postgresd:
  93. condition: service_healthy
  94. restart: on-failure
  95. hydra:
  96. image: oryd/hydra:v2.2.0
  97. depends_on:
  98. hydra-migrate:
  99. condition: service_completed_successfully
  100. ports:
  101. - "4444:4444" # Public port
  102. - "4445:4445" # Admin port
  103. - "5555:5555" # Token port? (Usually not needed if 4444 is used)
  104. # Production command: Remove --dev, remove -c if config file missing
  105. # Using --dangerous-force-http because we assume SSL is terminated by an external Nginx/LoadBalancer
  106. # If exposing directly without SSL, this is INSECURE but necessary to start.
  107. command: serve all --dangerous-force-http
  108. environment:
  109. - TZ=Asia/Shanghai
  110. - DSN=postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable&max_conns=20&max_idle_conns=4
  111. # IMPORTANT: Change URLs to your production domain
  112. - URLS_SELF_ISSUER=http://192.168.254.105:4444
  113. - URLS_CONSENT=http://192.168.254.105/consent
  114. - URLS_LOGIN=http://192.168.254.105/login
  115. - URLS_LOGOUT=http://192.168.254.105/login
  116. # IMPORTANT: Change these secrets!
  117. - SECRETS_SYSTEM=youReallyNeedToChangeThis
  118. - OIDC_SUBJECT_IDENTIFIERS_SUPPORTED_TYPES=public,pairwise
  119. - OIDC_SUBJECT_IDENTIFIERS_PAIRWISE_SALT=youReallyNeedToChangeThis
  120. # CORS
  121. - SERVE_PUBLIC_CORS_ENABLED=true
  122. - SERVE_PUBLIC_CORS_ALLOWED_ORIGINS=*
  123. - SERVE_PUBLIC_CORS_ALLOWED_METHODS=POST,GET,PUT,DELETE,PATCH,OPTIONS
  124. - SERVE_PUBLIC_CORS_ALLOWED_HEADERS=Authorization,Content-Type
  125. - SERVE_ADMIN_CORS_ENABLED=true
  126. - SERVE_ADMIN_CORS_ALLOWED_ORIGINS=*
  127. postgresd:
  128. image: postgres:15
  129. environment:
  130. - TZ=Asia/Shanghai
  131. - POSTGRES_USER=hydra
  132. - POSTGRES_PASSWORD=secret # CHANGE THIS
  133. - POSTGRES_DB=hydra
  134. volumes:
  135. - postgres_data:/var/lib/postgresql/data
  136. healthcheck:
  137. test: ["CMD-SHELL", "pg_isready -U hydra"]
  138. interval: 10s
  139. timeout: 5s
  140. retries: 5
  141. start_period: 10s
  142. volumes:
  143. db_data:
  144. postgres_data:
  145. redis_data: