docker-compose.yml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. # Backend (FastAPI)
  23. # ==========================================
  24. backend:
  25. build:
  26. context: ./backend
  27. ports:
  28. - "8000:8000"
  29. environment:
  30. - TZ=Asia/Shanghai
  31. - MYSQL_SERVER=db
  32. - MYSQL_PORT=3306
  33. - MYSQL_USER=uap_user
  34. - MYSQL_PASSWORD=uap_pass
  35. - MYSQL_DB=uap_db
  36. - REDIS_HOST=redis
  37. - REDIS_PORT=6379
  38. - HYDRA_ADMIN_URL=http://hydra:4445
  39. # CORS: Add * to allow debugging from any origin if localhost fails
  40. # Also explictly allow 127.0.0.1 and localhost with port 5173
  41. - BACKEND_CORS_ORIGINS=["http://localhost:5173", "http://127.0.0.1:5173", "http://frontend:5173"]
  42. depends_on:
  43. db:
  44. condition: service_healthy
  45. redis:
  46. condition: service_healthy
  47. hydra:
  48. condition: service_started
  49. volumes:
  50. - ./backend:/app # Hot Reload for Backend too
  51. restart: always
  52. # ==========================================
  53. # Database (MySQL)
  54. # ==========================================
  55. db:
  56. image: mysql:8.0
  57. command: --default-authentication-plugin=mysql_native_password
  58. restart: always
  59. environment:
  60. TZ: Asia/Shanghai
  61. MYSQL_ROOT_PASSWORD: root_password
  62. MYSQL_DATABASE: uap_db
  63. MYSQL_USER: uap_user
  64. MYSQL_PASSWORD: uap_pass
  65. ports:
  66. - "3308:3306"
  67. volumes:
  68. - db_data:/var/lib/mysql
  69. healthcheck:
  70. test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost", "-u", "uap_user", "-p$$MYSQL_PASSWORD"]
  71. interval: 10s
  72. timeout: 5s
  73. retries: 10
  74. start_period: 10s
  75. # ==========================================
  76. # Redis
  77. # ==========================================
  78. redis:
  79. image: redis:alpine
  80. ports:
  81. - "6379:6379"
  82. restart: always
  83. healthcheck:
  84. test: ["CMD", "redis-cli", "ping"]
  85. interval: 10s
  86. timeout: 5s
  87. retries: 5
  88. # ==========================================
  89. # Ory Hydra Services
  90. # ==========================================
  91. hydra-migrate:
  92. image: oryd/hydra:v2.2.0
  93. environment:
  94. - TZ=Asia/Shanghai
  95. - DSN=postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable&max_conns=20&max_idle_conns=4
  96. command: migrate sql -e --yes
  97. depends_on:
  98. postgresd:
  99. condition: service_healthy
  100. restart: on-failure
  101. hydra:
  102. image: oryd/hydra:v2.2.0
  103. depends_on:
  104. hydra-migrate:
  105. condition: service_completed_successfully
  106. ports:
  107. - "4444:4444"
  108. - "4445:4445"
  109. - "5555:5555"
  110. command: serve -c /etc/config/hydra/hydra.yml all --dev
  111. environment:
  112. - TZ=Asia/Shanghai
  113. - DSN=postgres://hydra:secret@postgresd:5432/hydra?sslmode=disable&max_conns=20&max_idle_conns=4
  114. - URLS_SELF_ISSUER=http://127.0.0.1:4444
  115. - URLS_CONSENT=http://localhost:5173/consent
  116. - URLS_LOGIN=http://localhost:5173/login
  117. - URLS_LOGOUT=http://localhost:5173/login
  118. - SECRETS_SYSTEM=youReallyNeedToChangeThis
  119. - OIDC_SUBJECT_IDENTIFIERS_SUPPORTED_TYPES=public,pairwise
  120. - OIDC_SUBJECT_IDENTIFIERS_PAIRWISE_SALT=youReallyNeedToChangeThis
  121. - SERVE_COOKIES_SAME_SITE_MODE=Lax
  122. - SERVE_COOKIES_SAME_SITE_LEGACY_WORKAROUND=true
  123. - SERVE_PUBLIC_CORS_ENABLED=true
  124. - SERVE_PUBLIC_CORS_ALLOWED_ORIGINS=*
  125. - SERVE_PUBLIC_CORS_ALLOWED_METHODS=POST,GET,PUT,DELETE,PATCH,OPTIONS
  126. - SERVE_PUBLIC_CORS_ALLOWED_HEADERS=Authorization,Content-Type
  127. - SERVE_ADMIN_CORS_ENABLED=true
  128. - SERVE_ADMIN_CORS_ALLOWED_ORIGINS=*
  129. postgresd:
  130. image: postgres:15
  131. environment:
  132. - TZ=Asia/Shanghai
  133. - POSTGRES_USER=hydra
  134. - POSTGRES_PASSWORD=secret
  135. - POSTGRES_DB=hydra
  136. volumes:
  137. - postgres_data:/var/lib/postgresql/data
  138. healthcheck:
  139. test: ["CMD-SHELL", "pg_isready -U hydra"]
  140. interval: 10s
  141. timeout: 5s
  142. retries: 5
  143. start_period: 10s
  144. volumes:
  145. db_data:
  146. postgres_data: