1
0

snac_stack.yml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ---
  2. # Example of a SNAC + Traefik stack on Docker Swarm mode
  3. # SNAC behind Traefik v3 reverse proxy
  4. # including Let's Encrypt certificates, HTTP security headers
  5. # and caching */s/* (SNAC static files) for 24h with souin.
  6. #
  7. # docker stack deploy -c snac_stack.yml snac
  8. services:
  9. traefik:
  10. image: traefik:v3
  11. hostname: '{{.Node.Hostname}}'
  12. ports:
  13. # listen on host ports without ingress network
  14. - target: 80
  15. published: 80
  16. protocol: tcp
  17. mode: host
  18. - target: 443
  19. published: 443
  20. protocol: tcp
  21. mode: host
  22. - target: 443
  23. published: 443
  24. protocol: udp # for HTTP3
  25. mode: host
  26. networks:
  27. - proxy
  28. volumes:
  29. - /opt/docker/traefik/traefik.yml:/etc/traefik/traefik_config.yml # main Traefik static configuration
  30. - /opt/docker/traefik/dynamic:/etc/traefik/dynamic # for Traefik dynamic configuration files
  31. - /opt/docker/acme:/acme # directory for certificate storage files
  32. - /opt/docker/traefik/log:/var/log
  33. - /var/run/docker.sock:/var/run/docker.sock:ro
  34. - /usr/share/zoneinfo/America/Sao_Paulo:/etc/localtime:ro # Change this to another or comment/remove to use UTC
  35. - /etc/timezone:/etc/timezone:ro # Comment/remove to use UTC
  36. environment:
  37. - TZ=America/Sao_Paulo # Change it to another or comment/remove to use UTC
  38. deploy:
  39. mode: global
  40. placement:
  41. constraints:
  42. - node.role==manager
  43. labels:
  44. - traefik.enable=true
  45. - traefik.http.routers.mydashboard.rule=Host(`traefik.example.net`) # for Traefik dashboard
  46. - traefik.http.routers.mydashboard.service=api@internal
  47. - traefik.http.routers.mydashboard.middlewares=traefik_auth,traefik_retry
  48. - traefik.http.services.mydashboard.loadbalancer.server.port=1337
  49. - traefik.http.middlewares.traefik_retry.retry.attempts=3
  50. - traefik.http.middlewares.traefik_retry.retry.initialinterval=200ms
  51. # How to generate a password hash: echo $(htpasswd -nB desired_username) | sed -e s/\\$/\\$\\$/g
  52. - traefik.http.middlewares.traefik_auth.basicauth.users=desired_username:PASTE_THE_PASSWORD_HASH_HERE
  53. resources:
  54. limits:
  55. cpus: "2"
  56. memory: 1g
  57. reservations:
  58. memory: 256m
  59. snac:
  60. image: codeberg.org/daltux/snac:2.82-dev_daltux3
  61. hostname: '{{.Node.Hostname}}'
  62. restart: unless-stopped
  63. security_opt:
  64. - no-new-privileges:true
  65. volumes:
  66. - /opt/snac:/data
  67. networks:
  68. - proxy
  69. depends_on:
  70. - traefik
  71. environment:
  72. - TZ=America/Sao_Paulo # Change this to your own or comment/remove it to use UTC.
  73. deploy:
  74. mode: replicated
  75. replicas: 1
  76. labels:
  77. - traefik.enable=true
  78. - traefik.http.services.snac.loadbalancer.server.port=8001
  79. - traefik.http.routers.snac.rule=Host(`snac.example.net`)
  80. - traefik.http.routers.snac.priority=1
  81. - traefik.http.routers.snac.middlewares=snac_headers@swarm,traefik_retry@swarm
  82. - "traefik.http.routers.snac_static.rule=Host(`snac.example.net`) && PathRegexp(`^/.+/s/.+`)"
  83. - "traefik.http.routers.snac_static.priority=2"
  84. - "traefik.http.routers.snac_static.middlewares=snac_headers@swarm,snac_cache_static@swarm,traefik_retry@swarm"
  85. - traefik.http.middlewares.snac_headers.headers.stsSeconds=31536000
  86. - traefik.http.middlewares.snac_headers.headers.stsIncludeSubdomains=false
  87. - traefik.http.middlewares.snac_headers.headers.stsPreload=false
  88. - traefik.http.middlewares.snac_headers.headers.customFrameOptionsValue=SAMEORIGIN
  89. - traefik.http.middlewares.snac_headers.headers.contentTypeNosniff=true
  90. - traefik.http.middlewares.snac_headers.headers.browserXssFilter=true
  91. - traefik.http.middlewares.snac_headers.headers.referrerPolicy=strict-origin-when-cross-origin
  92. - "traefik.http.middlewares.snac_headers.headers.contentSecurityPolicy=default-src 'self'; base-uri 'self'; script-src 'none'; style-src 'self' 'unsafe-inline'; form-action 'self'; img-src https: data:; font-src 'self'; media-src https: data:; connect-src 'none'; frame-src 'none'; frame-ancestors 'none';"
  93. - traefik.http.middlewares.snac_cache_static.plugin.souin.api.souin=true
  94. - traefik.http.middlewares.snac_cache_static.plugin.souin.log_level=info
  95. - traefik.http.middlewares.snac_cache_static.plugin.souin.default_cache.ttl=1440m
  96. - traefik.http.middlewares.snac_cache_static.plugin.souin.default_cache.allowed_http_verbs=GET,HEAD
  97. - traefik.http.middlewares.snac_cache_static.plugin.souin.default_cache.stale=1h
  98. - traefik.http.middlewares.snac_cache_static.plugin.souin.default_cache.etag=true
  99. - "traefik.http.middlewares.snac_cache_static.plugin.souin.default_cache.default_cache_control=public, max-age=86400"
  100. resources:
  101. limits:
  102. cpus: "3"
  103. memory: 1g
  104. reservations:
  105. memory: 256m
  106. networks:
  107. proxy:
  108. name: proxy
  109. driver: overlay
  110. attachable: true
  111. external: true