docker-compose.yml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. version: "3.3"
  2. services:
  3. proxy:
  4. image: traefik:v2.9
  5. networks:
  6. - ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
  7. - default
  8. volumes:
  9. - /var/run/docker.sock:/var/run/docker.sock
  10. command:
  11. # Enable Docker in Traefik, so that it reads labels from Docker services
  12. - --providers.docker
  13. # Add a constraint to only use services with the label for this stack
  14. # from the env var TRAEFIK_TAG
  15. - --providers.docker.constraints=Label(`traefik.constraint-label-stack`, `${TRAEFIK_TAG?Variable not set}`)
  16. # Do not expose all Docker services, only the ones explicitly exposed
  17. - --providers.docker.exposedbydefault=false
  18. # Enable Docker Swarm mode
  19. - --providers.docker.swarmmode
  20. # Enable the access log, with HTTP requests
  21. - --accesslog
  22. # Enable the Traefik log, for configurations and errors
  23. - --log
  24. # Enable the Dashboard and API
  25. - --api
  26. deploy:
  27. placement:
  28. constraints:
  29. - node.role == manager
  30. labels:
  31. # Enable Traefik for this service, to make it available in the public network
  32. - traefik.enable=true
  33. # Use the traefik-public network (declared below)
  34. - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
  35. # Use the custom label "traefik.constraint-label=traefik-public"
  36. # This public Traefik will only use services with this label
  37. - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
  38. # traefik-http set up only to use the middleware to redirect to https
  39. - traefik.http.middlewares.${STACK_NAME?Variable not set}-https-redirect.redirectscheme.scheme=https
  40. - traefik.http.middlewares.${STACK_NAME?Variable not set}-https-redirect.redirectscheme.permanent=true
  41. # Handle host with and without "www" to redirect to only one of them
  42. # Uses environment variable DOMAIN
  43. # To disable www redirection remove the Host() you want to discard, here and
  44. # below for HTTPS
  45. - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.rule=Host(`${DOMAIN?Variable not set}`) || Host(`www.${DOMAIN?Variable not set}`)
  46. - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.entrypoints=http
  47. # traefik-https the actual router using HTTPS
  48. - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.rule=Host(`${DOMAIN?Variable not set}`) || Host(`www.${DOMAIN?Variable not set}`)
  49. - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.entrypoints=https
  50. - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.tls=true
  51. # Use the "le" (Let's Encrypt) resolver created below
  52. - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.tls.certresolver=le
  53. # Define the port inside of the Docker service to use
  54. - traefik.http.services.${STACK_NAME?Variable not set}-proxy.loadbalancer.server.port=80
  55. # Handle domain with and without "www" to redirect to only one
  56. # To disable www redirection remove the next line
  57. - traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.regex=^https?://(www.)?(${DOMAIN?Variable not set})/(.*)
  58. # Redirect a domain with www to non-www
  59. # To disable it remove the next line
  60. - traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.replacement=https://${DOMAIN?Variable not set}/$${3}
  61. # Redirect a domain without www to www
  62. # To enable it remove the previous line and uncomment the next
  63. # - traefik.http.middlewares.${STACK_NAME}-www-redirect.redirectregex.replacement=https://www.${DOMAIN}/$${3}
  64. # Middleware to redirect www, to disable it remove the next line
  65. - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-https.middlewares=${STACK_NAME?Variable not set}-www-redirect
  66. # Middleware to redirect www, and redirect HTTP to HTTPS
  67. # to disable www redirection remove the section: ${STACK_NAME?Variable not set}-www-redirect,
  68. - traefik.http.routers.${STACK_NAME?Variable not set}-proxy-http.middlewares=${STACK_NAME?Variable not set}-www-redirect,${STACK_NAME?Variable not set}-https-redirect
  69. db:
  70. image: postgres:15
  71. volumes:
  72. - app-db-data:/var/lib/postgresql/data/pgdata
  73. env_file:
  74. - .env
  75. environment:
  76. - PGDATA=/var/lib/postgresql/data/pgdata
  77. deploy:
  78. placement:
  79. constraints:
  80. - node.labels.${STACK_NAME?Variable not set}.app-db-data == true
  81. pgadmin:
  82. image: dpage/pgadmin4
  83. networks:
  84. - ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
  85. - default
  86. depends_on:
  87. - db
  88. env_file:
  89. - .env
  90. deploy:
  91. labels:
  92. - traefik.enable=true
  93. - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
  94. - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
  95. - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.rule=Host(`pgadmin.${DOMAIN?Variable not set}`)
  96. - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.entrypoints=http
  97. - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
  98. - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.rule=Host(`pgadmin.${DOMAIN?Variable not set}`)
  99. - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.entrypoints=https
  100. - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.tls=true
  101. - traefik.http.routers.${STACK_NAME?Variable not set}-pgadmin-https.tls.certresolver=le
  102. - traefik.http.services.${STACK_NAME?Variable not set}-pgadmin.loadbalancer.server.port=5050
  103. queue:
  104. image: rabbitmq:3
  105. # Using the below image instead is required to enable the "Broker" tab in the flower UI:
  106. # image: rabbitmq:3-management
  107. #
  108. # You also have to change the flower command
  109. flower:
  110. image: mher/flower:0.9.7
  111. networks:
  112. - ${TRAEFIK_PUBLIC_NETWORK?Variable not set}
  113. - default
  114. env_file:
  115. - .env
  116. command:
  117. - "--broker=amqp://guest@queue:5672//"
  118. # For the "Broker" tab to work in the flower UI, uncomment the following command argument,
  119. # and change the queue service's image as well
  120. # - "--broker_api=http://guest:guest@queue:15672/api//"
  121. deploy:
  122. labels:
  123. - traefik.enable=true
  124. - traefik.docker.network=${TRAEFIK_PUBLIC_NETWORK?Variable not set}
  125. - traefik.constraint-label=${TRAEFIK_PUBLIC_TAG?Variable not set}
  126. - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.rule=Host(`flower.${DOMAIN?Variable not set}`)
  127. - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.entrypoints=http
  128. - traefik.http.routers.${STACK_NAME?Variable not set}-flower-http.middlewares=${STACK_NAME?Variable not set}-https-redirect
  129. - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.rule=Host(`flower.${DOMAIN?Variable not set}`)
  130. - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.entrypoints=https
  131. - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls=true
  132. - traefik.http.routers.${STACK_NAME?Variable not set}-flower-https.tls.certresolver=le
  133. - traefik.http.services.${STACK_NAME?Variable not set}-flower.loadbalancer.server.port=5555
  134. backend:
  135. image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}'
  136. depends_on:
  137. - db
  138. env_file:
  139. - .env
  140. environment:
  141. - SERVER_NAME=${DOMAIN?Variable not set}
  142. - SERVER_HOST=https://${DOMAIN?Variable not set}
  143. # Allow explicit env var override for tests
  144. - SMTP_HOST=${SMTP_HOST}
  145. build:
  146. context: ./backend
  147. dockerfile: backend.dockerfile
  148. args:
  149. INSTALL_DEV: ${INSTALL_DEV-false}
  150. deploy:
  151. labels:
  152. - traefik.enable=true
  153. - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
  154. - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=PathPrefix(`/api`) || PathPrefix(`/docs`) || PathPrefix(`/redoc`)
  155. - traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=80
  156. celeryworker:
  157. image: '${DOCKER_IMAGE_CELERYWORKER?Variable not set}:${TAG-latest}'
  158. depends_on:
  159. - db
  160. - queue
  161. env_file:
  162. - .env
  163. environment:
  164. - SERVER_NAME=${DOMAIN?Variable not set}
  165. - SERVER_HOST=https://${DOMAIN?Variable not set}
  166. # Allow explicit env var override for tests
  167. - SMTP_HOST=${SMTP_HOST?Variable not set}
  168. build:
  169. context: ./backend
  170. dockerfile: celeryworker.dockerfile
  171. args:
  172. INSTALL_DEV: ${INSTALL_DEV-false}
  173. frontend:
  174. image: '${DOCKER_IMAGE_FRONTEND?Variable not set}:${TAG-latest}'
  175. build:
  176. context: ./frontend
  177. args:
  178. FRONTEND_ENV: ${FRONTEND_ENV-production}
  179. deploy:
  180. labels:
  181. - traefik.enable=true
  182. - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
  183. - traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.rule=PathPrefix(`/`)
  184. - traefik.http.services.${STACK_NAME?Variable not set}-frontend.loadbalancer.server.port=80
  185. volumes:
  186. app-db-data:
  187. networks:
  188. traefik-public:
  189. # Allow setting it to false for testing
  190. external: true