cloud-docker-compose.yml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. backend:
  70. image: '${DOCKER_IMAGE_BACKEND?Variable not set}:${TAG-latest}'
  71. env_file:
  72. - .env
  73. environment:
  74. - SERVER_NAME=${DOMAIN?Variable not set}
  75. - SERVER_HOST=https://${DOMAIN?Variable not set}
  76. # Allow explicit env var override for tests
  77. - SMTP_HOST=${SMTP_HOST}
  78. build:
  79. context: ./backend
  80. dockerfile: backend.dockerfile
  81. args:
  82. INSTALL_DEV: ${INSTALL_DEV-false}
  83. deploy:
  84. labels:
  85. - traefik.enable=true
  86. - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
  87. - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.rule=PathPrefix(`/api`) || PathPrefix(`/docs`) || PathPrefix(`/redoc`)
  88. - traefik.http.services.${STACK_NAME?Variable not set}-backend.loadbalancer.server.port=80
  89. frontend:
  90. image: '${DOCKER_IMAGE_FRONTEND?Variable not set}:${TAG-latest}'
  91. build:
  92. context: ./frontend
  93. args:
  94. FRONTEND_ENV: ${FRONTEND_ENV-production}
  95. deploy:
  96. labels:
  97. - traefik.enable=true
  98. - traefik.constraint-label-stack=${TRAEFIK_TAG?Variable not set}
  99. - traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.rule=PathPrefix(`/`)
  100. - traefik.http.services.${STACK_NAME?Variable not set}-frontend.loadbalancer.server.port=80
  101. networks:
  102. traefik-public:
  103. # Allow setting it to false for testing
  104. external: true