service-deploy-v1.j2 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. {#
  2. Archetype: service-deploy-traefik-v1
  3. Description:
  4. Swarm deployment with Traefik labels in deploy section.
  5. Approach:
  6. - Labels must be in deploy section for swarm mode
  7. - Includes full HTTP + HTTPS Traefik configuration
  8. - Critical: traefik.docker.network label for multi-network containers
  9. Usage:
  10. Use for swarm services exposed through Traefik.
  11. Combines with service-labels-traefik-https-v1 for standalone mode.
  12. #}
  13. {% if swarm_enabled and traefik_enabled %}
  14. deploy:
  15. mode: {{ swarm_placement_mode }}
  16. {% if swarm_placement_mode == 'replicated' %}
  17. replicas: {{ swarm_replicas }}
  18. {% endif %}
  19. restart_policy:
  20. condition: on-failure
  21. labels:
  22. - traefik.enable=true
  23. - traefik.docker.network={{ traefik_network }}
  24. - traefik.http.services.{{ service_name }}-web.loadBalancer.server.port={{ service_port }}
  25. - traefik.http.routers.{{ service_name }}-http.service={{ service_name }}-web
  26. - traefik.http.routers.{{ service_name }}-http.rule=Host(`{{ traefik_host }}`)
  27. - traefik.http.routers.{{ service_name }}-http.entrypoints={{ traefik_entrypoint }}
  28. {% if traefik_tls_enabled %}
  29. - traefik.http.routers.{{ service_name }}-https.service={{ service_name }}-web
  30. - traefik.http.routers.{{ service_name }}-https.rule=Host(`{{ traefik_host }}`)
  31. - traefik.http.routers.{{ service_name }}-https.entrypoints={{ traefik_tls_entrypoint }}
  32. - traefik.http.routers.{{ service_name }}-https.tls=true
  33. - traefik.http.routers.{{ service_name }}-https.tls.certresolver={{ traefik_tls_certresolver }}
  34. {% endif %}
  35. {% endif %}