docker-compose.wsl.yml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. version: '3.7'
  2. services:
  3. # ==========================================
  4. # Frontend (Vite Dev Server)
  5. # ==========================================
  6. frontend:
  7. build:
  8. context: ./frontend
  9. ports:
  10. - "5173:5173" # Vite default port
  11. depends_on:
  12. - backend
  13. # Hot Reload requires binding volume locally
  14. volumes:
  15. - ./frontend:/app
  16. - /app/node_modules # Avoid overwriting node_modules
  17. environment:
  18. # Browser needs to access backend directly for CORS requests in Dev mode
  19. - VITE_API_BASE_URL=http://localhost:8000/api/v1
  20. restart: always
  21. # ==========================================
  22. # Nginx (Frontend Production)
  23. # ==========================================
  24. nginx:
  25. build:
  26. context: ./frontend
  27. target: production-stage
  28. ports:
  29. - "80:80"
  30. - "443:443"
  31. depends_on:
  32. - backend
  33. volumes:
  34. - certs_data:/etc/nginx/certs
  35. restart: always
  36. # ==========================================
  37. # Backend (FastAPI)
  38. # ==========================================
  39. backend:
  40. build:
  41. context: ./backend
  42. ports:
  43. - "8000:8000"
  44. environment:
  45. - TZ=Asia/Shanghai
  46. - MYSQL_SERVER=db
  47. - MYSQL_PORT=3306
  48. - MYSQL_USER=uap_user
  49. - MYSQL_PASSWORD=uap_pass
  50. - MYSQL_DB=uap_db
  51. - REDIS_HOST=redis
  52. - REDIS_PORT=6379
  53. - HYDRA_ADMIN_URL=http://hydra:4445
  54. # CORS: Add * to allow debugging from any origin if localhost fails
  55. # Also explictly allow 127.0.0.1 and localhost with port 5173
  56. - BACKEND_CORS_ORIGINS=["https://api.hnyunzhu.com"]
  57. depends_on:
  58. db:
  59. condition: service_healthy
  60. redis:
  61. condition: service_healthy
  62. hydra:
  63. condition: service_started
  64. db-migration:
  65. condition: service_completed_successfully
  66. volumes:
  67. - ./backend:/app # Hot Reload for Backend too
  68. - certs_data:/app/certs
  69. - ./backups:/app/backups # 数据库备份目录
  70. restart: always
  71. # ==========================================
  72. # Database (MySQL)
  73. # ==========================================
  74. db:
  75. image: mysql:8.0
  76. container_name: uap_mysql
  77. command: --default-authentication-plugin=mysql_native_password
  78. restart: always
  79. environment:
  80. TZ: Asia/Shanghai
  81. MYSQL_ROOT_PASSWORD: root_password
  82. MYSQL_DATABASE: uap_db
  83. MYSQL_USER: uap_user
  84. MYSQL_PASSWORD: uap_pass
  85. ports:
  86. - "3308:3306"
  87. volumes:
  88. - db_data:/var/lib/mysql
  89. # - ./config/my.cnf:/etc/mysql/conf.d/my.cnf
  90. healthcheck:
  91. test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
  92. interval: 10s
  93. timeout: 5s
  94. retries: 5
  95. # ==========================================
  96. # Database Version Migration (Flyway)
  97. # ==========================================
  98. db-migration:
  99. image: flyway/flyway:9-alpine
  100. container_name: uap_migration
  101. depends_on:
  102. db:
  103. condition: service_healthy
  104. command: -connectRetries=60 -baselineOnMigrate=true migrate
  105. environment:
  106. FLYWAY_URL: jdbc:mysql://db:3306/uap_db
  107. FLYWAY_USER: root
  108. FLYWAY_PASSWORD: root_password
  109. volumes:
  110. - ./sql:/flyway/sql
  111. # ==========================================
  112. # Database Auto Backup (Sidecar)
  113. # ==========================================
  114. db-backup:
  115. image: fradelg/mysql-cron-backup
  116. container_name: uap_backup
  117. restart: always
  118. depends_on:
  119. - db
  120. environment:
  121. - MYSQL_HOST=db
  122. - MYSQL_PORT=3306
  123. - MYSQL_USER=root
  124. - MYSQL_PASS=root_password
  125. - CRON_TIME=0 3 * * *
  126. - MAX_BACKUPS=7
  127. - GZIP_COMPRESSION=true
  128. volumes:
  129. - ./backups:/backup
  130. # ==========================================
  131. # Redis
  132. # ==========================================
  133. redis:
  134. image: redis:7-alpine
  135. ports:
  136. - "6379:6379"
  137. restart: always
  138. healthcheck:
  139. test: ["CMD", "redis-cli", "ping"]
  140. interval: 10s
  141. timeout: 5s
  142. retries: 5
  143. # ==========================================
  144. # Ory Hydra Services
  145. # ==========================================
  146. hydra-migrate:
  147. image: oryd/hydra:v2.2.0
  148. environment:
  149. - TZ=Asia/Shanghai
  150. - DSN=postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable&max_conns=20&max_idle_conns=4
  151. command: migrate sql -e --yes
  152. depends_on:
  153. postgresd:
  154. condition: service_healthy
  155. restart: on-failure
  156. hydra:
  157. image: oryd/hydra:v2.2.0
  158. depends_on:
  159. hydra-migrate:
  160. condition: service_completed_successfully
  161. ports:
  162. - "4444:4444"
  163. - "4445:4445"
  164. - "5555:5555"
  165. command: serve all --dev
  166. environment:
  167. - TZ=Asia/Shanghai
  168. - DSN=postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable&max_conns=20&max_idle_conns=4
  169. - URLS_SELF_ISSUER=https://api.hnyunzhu.com/hydra
  170. - URLS_CONSENT=https://api.hnyunzhu.com/consent
  171. - URLS_LOGIN=https://api.hnyunzhu.com/auto-login
  172. - URLS_LOGOUT=https://api.hnyunzhu.com/auto-logout
  173. - SECRETS_SYSTEM=youReallyNeedToChangeThis
  174. - OIDC_SUBJECT_IDENTIFIERS_SUPPORTED_TYPES=public,pairwise
  175. - OIDC_SUBJECT_IDENTIFIERS_PAIRWISE_SALT=youReallyNeedToChangeThis
  176. - SERVE_COOKIES_SAME_SITE_MODE=Lax
  177. - SERVE_COOKIES_SAME_SITE_LEGACY_WORKAROUND=true
  178. - SERVE_PUBLIC_CORS_ENABLED=true
  179. - SERVE_PUBLIC_CORS_ALLOWED_ORIGINS=*
  180. - SERVE_PUBLIC_CORS_ALLOWED_METHODS=POST,GET,PUT,DELETE,PATCH,OPTIONS
  181. - SERVE_PUBLIC_CORS_ALLOWED_HEADERS=Authorization,Content-Type
  182. - SERVE_ADMIN_CORS_ENABLED=true
  183. - SERVE_ADMIN_CORS_ALLOWED_ORIGINS=*
  184. postgresd:
  185. image: postgres:15
  186. environment:
  187. - TZ=Asia/Shanghai
  188. - POSTGRES_USER=hydra
  189. - POSTGRES_PASSWORD=secret
  190. - POSTGRES_DB=hydra
  191. volumes:
  192. - postgres_data:/var/lib/postgresql/data
  193. healthcheck:
  194. test: ["CMD-SHELL", "pg_isready -U hydra"]
  195. interval: 10s
  196. timeout: 5s
  197. retries: 5
  198. start_period: 10s
  199. volumes:
  200. db_data:
  201. postgres_data:
  202. certs_data: