docker-compose.prod.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. version: "3.9"
  2. x-common: &common
  3. restart: unless-stopped
  4. networks:
  5. - photoplaces
  6. # Secrets for Docker Swarm mode (optional, ignored in compose)
  7. x-secrets: &secrets
  8. db_password:
  9. external: true
  10. redis_password:
  11. external: true
  12. jwt_secret:
  13. external: true
  14. jwt_refresh_secret:
  15. external: true
  16. s3_secret_key:
  17. external: true
  18. services:
  19. caddy:
  20. <<: *common
  21. image: caddy:2.8-alpine
  22. ports:
  23. - "80:80"
  24. volumes:
  25. - ./Caddyfile:/etc/caddy/Caddyfile
  26. - caddy_data:/data
  27. - caddy_config:/config
  28. environment:
  29. DOMAIN: ${DOMAIN}
  30. depends_on:
  31. backend:
  32. condition: service_healthy
  33. frontend:
  34. condition: service_healthy
  35. healthcheck:
  36. test: ["CMD", "wget", "-q", "--spider", "http://localhost:2019/metrics"]
  37. interval: 30s
  38. timeout: 10s
  39. retries: 3
  40. start_period: 10s
  41. postgres:
  42. <<: *common
  43. image: postgis/postgis:16-3.4-alpine
  44. environment:
  45. POSTGRES_DB: photoplaces
  46. POSTGRES_USER: photoplaces
  47. POSTGRES_PASSWORD_FILE: /run/secrets/db_password
  48. volumes:
  49. - pgdata:/var/lib/postgresql/data
  50. healthcheck:
  51. test: ["CMD-SHELL", "pg_isready -U photoplaces"]
  52. interval: 10s
  53. retries: 5
  54. secrets:
  55. - db_password
  56. redis:
  57. <<: *common
  58. image: redis:7-alpine
  59. command: redis-server --requirepass-file /run/secrets/redis_password
  60. volumes:
  61. - redisdata:/data
  62. healthcheck:
  63. test: ["CMD", "redis-cli", "-a", "$(cat /run/secrets/redis_password)", "ping"]
  64. interval: 10s
  65. retries: 5
  66. secrets:
  67. - redis_password
  68. minio:
  69. <<: *common
  70. image: minio/minio:latest
  71. command: server /data --console-address ":9001"
  72. volumes:
  73. - miniodata:/data
  74. environment:
  75. MINIO_ROOT_USER: ${S3_ACCESS_KEY}
  76. MINIO_ROOT_PASSWORD_FILE: /run/secrets/s3_secret_key
  77. healthcheck:
  78. test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
  79. interval: 10s
  80. retries: 5
  81. secrets:
  82. - s3_secret_key
  83. # Порты 9000/9001 ТОЛЬКО внутри Docker сети (нет внешнего доступа)
  84. backend:
  85. <<: *common
  86. build:
  87. context: ./backend
  88. dockerfile: Dockerfile
  89. env_file:
  90. - ./env.prod
  91. environment:
  92. APP_ENV: production
  93. SERVER_PORT: "8080"
  94. DATABASE_URL: postgres://photoplaces:$(cat /run/secrets/db_password)@postgres:5432/photoplaces?sslmode=disable
  95. REDIS_URL: redis://:$(cat /run/secrets/redis_password)@redis:6379/0
  96. S3_ENDPOINT: http://minio:9000
  97. S3_PUBLIC_ENDPOINT: ${S3_PUBLIC_ENDPOINT}
  98. S3_ACCESS_KEY: ${S3_ACCESS_KEY}
  99. S3_SECRET_KEY_FILE: /run/secrets/s3_secret_key
  100. S3_BUCKET: photoplaces
  101. JWT_SECRET_FILE: /run/secrets/jwt_secret
  102. JWT_REFRESH_SECRET_FILE: /run/secrets/jwt_refresh_secret
  103. CLOUDPAYMENTS_PUBLIC_ID: ${CLOUDPAYMENTS_PUBLIC_ID}
  104. CLOUDPAYMENTS_API_SECRET: ${CLOUDPAYMENTS_API_SECRET}
  105. ALLOWED_ORIGINS: ${ALLOWED_ORIGINS}
  106. depends_on:
  107. postgres:
  108. condition: service_healthy
  109. redis:
  110. condition: service_healthy
  111. minio:
  112. condition: service_healthy
  113. healthcheck:
  114. test: ["CMD", "wget", "-q", "--spider", "http://localhost:8080/api/v1/health"]
  115. interval: 30s
  116. timeout: 10s
  117. retries: 3
  118. start_period: 10s
  119. secrets:
  120. - db_password
  121. - redis_password
  122. - jwt_secret
  123. - jwt_refresh_secret
  124. - s3_secret_key
  125. frontend:
  126. <<: *common
  127. build:
  128. context: ./frontend
  129. dockerfile: Dockerfile
  130. args:
  131. NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL}
  132. NEXT_PUBLIC_MAP_PROVIDER: yandex
  133. NEXT_PUBLIC_YANDEX_MAPS_API_KEY: ${YANDEX_MAPS_API_KEY}
  134. depends_on:
  135. backend:
  136. condition: service_healthy
  137. healthcheck:
  138. test: ["CMD", "wget", "-q", "--spider", "http://localhost:3000"]
  139. interval: 30s
  140. timeout: 10s
  141. retries: 3
  142. start_period: 15s
  143. volumes:
  144. pgdata:
  145. redisdata:
  146. miniodata:
  147. caddy_data:
  148. caddy_config:
  149. networks:
  150. photoplaces:
  151. secrets:
  152. db_password:
  153. external: true
  154. redis_password:
  155. external: true
  156. jwt_secret:
  157. external: true
  158. jwt_refresh_secret:
  159. external: true
  160. s3_secret_key:
  161. external: true