compose.yaml.j2 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. services:
  2. {{ service_name }}:
  3. image: n8nio/n8n:1.118.1
  4. command: worker
  5. {#
  6. If not in swarm mode, apply container name and hostname
  7. #}
  8. {% if not swarm_enabled -%}
  9. container_name: {{ container_name }}
  10. hostname: {{ container_hostname }}
  11. {% endif -%}
  12. {#
  13. Environment variables for n8n worker configuration:
  14. - Database connection (must match n8n-server)
  15. - Encryption key (must match n8n-server)
  16. - Redis queue configuration
  17. - Optional metrics
  18. #}
  19. environment:
  20. - N8N_LOG_LEVEL={{ container_loglevel }}
  21. - GENERIC_TIMEZONE={{ container_timezone }}
  22. - TZ={{ container_timezone }}
  23. {% if database_enabled -%}
  24. {% if database_type == 'postgres' -%}
  25. - DB_TYPE=postgresdb
  26. - DB_POSTGRESDB_HOST={{ database_host }}
  27. - DB_POSTGRESDB_PORT={{ database_port }}
  28. - DB_POSTGRESDB_DATABASE={{ database_name }}
  29. - DB_POSTGRESDB_USER={{ database_user }}
  30. {% if swarm_enabled -%}
  31. - DB_POSTGRESDB_PASSWORD_FILE=/run/secrets/{{ service_name }}_database_password
  32. {% else -%}
  33. - DB_POSTGRESDB_PASSWORD={{ database_password }}
  34. {% endif -%}
  35. {% elif database_type == 'mysql' -%}
  36. - DB_TYPE=mysqldb
  37. - DB_MYSQLDB_HOST={{ database_host }}
  38. - DB_MYSQLDB_PORT={{ database_port }}
  39. - DB_MYSQLDB_DATABASE={{ database_name }}
  40. - DB_MYSQLDB_USER={{ database_user }}
  41. {% if swarm_enabled -%}
  42. - DB_MYSQLDB_PASSWORD_FILE=/run/secrets/{{ service_name }}_database_password
  43. {% else -%}
  44. - DB_MYSQLDB_PASSWORD={{ database_password }}
  45. {% endif -%}
  46. {% endif -%}
  47. {% endif -%}
  48. {% if swarm_enabled -%}
  49. - N8N_ENCRYPTION_KEY_FILE=/run/secrets/{{ service_name }}_encryption_key
  50. {% else -%}
  51. - N8N_ENCRYPTION_KEY={{ encryption_key }}
  52. {% endif -%}
  53. - EXECUTIONS_MODE=queue
  54. - QUEUE_BULL_REDIS_HOST={{ redis_host }}
  55. - QUEUE_BULL_REDIS_PORT={{ redis_port }}
  56. - QUEUE_HEALTH_CHECK_ACTIVE=true
  57. {% if metrics_enabled -%}
  58. - N8N_METRICS=true
  59. {% if metrics_detailed -%}
  60. - N8N_METRICS_INCLUDE_WORKFLOW_ID_LABELS=true
  61. - N8N_METRICS_INCLUDE_NODE_TYPE_LABEL=true
  62. {% endif -%}
  63. {% endif -%}
  64. {#
  65. Volume configuration for persistent data
  66. #}
  67. volumes:
  68. - /etc/localtime:/etc/localtime:ro
  69. - data:/home/node/.n8n
  70. {#
  71. If not in swarm mode, apply restart policy
  72. #}
  73. {% if not swarm_enabled -%}
  74. restart: {{ restart_policy }}
  75. {% endif -%}
  76. {#
  77. Deploy configuration for Swarm mode:
  78. - Multiple worker replicas for scaling
  79. - Uses Docker secrets for sensitive data
  80. #}
  81. {% if swarm_enabled -%}
  82. deploy:
  83. replicas: {{ swarm_replicas }}
  84. {% if swarm_placement_host -%}
  85. placement:
  86. constraints:
  87. - node.hostname == {{ swarm_placement_host }}
  88. {% endif -%}
  89. secrets:
  90. - {{ service_name }}_encryption_key
  91. {% if database_enabled -%}
  92. - {{ service_name }}_database_password
  93. {% endif -%}
  94. {% endif -%}
  95. {#
  96. Volume definitions:
  97. - data: Persistent storage for n8n worker data
  98. #}
  99. volumes:
  100. data:
  101. driver: local
  102. {#
  103. Docker Swarm secrets (only when swarm_enabled is set):
  104. - Encryption key and database password (external secrets)
  105. #}
  106. {% if swarm_enabled -%}
  107. secrets:
  108. {{ service_name }}_encryption_key:
  109. external: true
  110. {% if database_enabled -%}
  111. {{ service_name }}_database_password:
  112. external: true
  113. {% endif -%}
  114. {% endif -%}