docker-compose.yml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. command: --default-authentication-plugin=mysql_native_password
  70. restart: always
  71. environment:
  72. TZ: Asia/Shanghai
  73. MYSQL_ROOT_PASSWORD: root_password
  74. MYSQL_DATABASE: uap_db
  75. MYSQL_USER: uap_user
  76. MYSQL_PASSWORD: uap_pass
  77. ports:
  78. - "3308:3306"
  79. volumes:
  80. - db_data:/var/lib/mysql
  81. healthcheck:
  82. test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost", "-u", "uap_user", "-p$$MYSQL_PASSWORD"]
  83. interval: 10s
  84. timeout: 5s
  85. retries: 10
  86. start_period: 10s
  87. # ==========================================
  88. # Redis
  89. # ==========================================
  90. redis:
  91. image: redis:alpine
  92. ports:
  93. - "6379:6379"
  94. restart: always
  95. healthcheck:
  96. test: ["CMD", "redis-cli", "ping"]
  97. interval: 10s
  98. timeout: 5s
  99. retries: 5
  100. # ==========================================
  101. # Ory Hydra Services
  102. # ==========================================
  103. hydra-migrate:
  104. image: oryd/hydra:v2.2.0
  105. environment:
  106. - TZ=Asia/Shanghai
  107. - DSN=postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable&max_conns=20&max_idle_conns=4
  108. command: migrate sql -e --yes
  109. depends_on:
  110. postgresd:
  111. condition: service_healthy
  112. restart: on-failure
  113. hydra:
  114. image: oryd/hydra:v2.2.0
  115. depends_on:
  116. hydra-migrate:
  117. condition: service_completed_successfully
  118. ports:
  119. - "4444:4444"
  120. - "4445:4445"
  121. - "5555:5555"
  122. command: serve -c /etc/config/hydra/hydra.yml all --dev
  123. environment:
  124. - TZ=Asia/Shanghai
  125. - DSN=postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable&max_conns=20&max_idle_conns=4
  126. - URLS_SELF_ISSUER=http://127.0.0.1:4444
  127. - URLS_CONSENT=http://localhost:5173/consent
  128. - URLS_LOGIN=http://localhost:5173/login
  129. - URLS_LOGOUT=http://localhost:5173/login
  130. - SECRETS_SYSTEM=youReallyNeedToChangeThis
  131. - OIDC_SUBJECT_IDENTIFIERS_SUPPORTED_TYPES=public,pairwise
  132. - OIDC_SUBJECT_IDENTIFIERS_PAIRWISE_SALT=youReallyNeedToChangeThis
  133. - SERVE_COOKIES_SAME_SITE_MODE=Lax
  134. - SERVE_COOKIES_SAME_SITE_LEGACY_WORKAROUND=true
  135. - SERVE_PUBLIC_CORS_ENABLED=true
  136. - SERVE_PUBLIC_CORS_ALLOWED_ORIGINS=*
  137. - SERVE_PUBLIC_CORS_ALLOWED_METHODS=POST,GET,PUT,DELETE,PATCH,OPTIONS
  138. - SERVE_PUBLIC_CORS_ALLOWED_HEADERS=Authorization,Content-Type
  139. - SERVE_ADMIN_CORS_ENABLED=true
  140. - SERVE_ADMIN_CORS_ALLOWED_ORIGINS=*
  141. postgresd:
  142. image: postgres:15
  143. environment:
  144. - TZ=Asia/Shanghai
  145. - POSTGRES_USER=hydra
  146. - POSTGRES_PASSWORD=secret
  147. - POSTGRES_DB=hydra
  148. volumes:
  149. - postgres_data:/var/lib/postgresql/data
  150. healthcheck:
  151. test: ["CMD-SHELL", "pg_isready -U hydra"]
  152. interval: 10s
  153. timeout: 5s
  154. retries: 5
  155. start_period: 10s
  156. volumes:
  157. db_data:
  158. postgres_data: