docker-compose.wsl.yml 5.7 KB

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