compose.yaml.j2.final 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. {% if queue_enabled and not queue_redis_external -%}
  2. services:
  3. redis:
  4. image: redis:7-alpine
  5. {% if not swarm_enabled -%}
  6. container_name: {{ service_name }}-redis
  7. {% endif -%}
  8. volumes:
  9. - redis_data:/data
  10. {% if network_mode == 'bridge' -%}
  11. networks:
  12. - {{ network_name }}
  13. {% else -%}
  14. {% endif -%}
  15. {% if not swarm_enabled -%}
  16. restart: {{ restart_policy }}
  17. {% endif -%}
  18. healthcheck:
  19. test: ["CMD", "redis-cli", "ping"]
  20. interval: 5s
  21. timeout: 3s
  22. retries: 5
  23. {% if swarm_enabled -%}
  24. deploy:
  25. replicas: 1
  26. placement:
  27. constraints:
  28. - node.role == manager
  29. {% endif -%}
  30. {% endif -%}
  31. {{ service_name }}:
  32. image: n8nio/n8n:1.118.1
  33. {% if not swarm_enabled -%}
  34. container_name: {{ container_name }}
  35. hostname: {{ container_hostname }}
  36. {% endif -%}
  37. environment:
  38. - N8N_LOG_LEVEL={{ container_loglevel }}
  39. - GENERIC_TIMEZONE={{ container_timezone }}
  40. - TZ={{ container_timezone }}
  41. - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
  42. - N8N_RUNNERS_ENABLED=true
  43. {% if traefik_enabled -%}
  44. - N8N_HOST={{ traefik_host }}
  45. {% if traefik_tls_enabled -%}
  46. - N8N_PROTOCOL=https
  47. - N8N_EDITOR_BASE_URL=https://{{ traefik_host }}
  48. {% else -%}
  49. - N8N_PROTOCOL=http
  50. - N8N_EDITOR_BASE_URL=http://{{ traefik_host }}
  51. {% endif -%}
  52. {% endif -%}
  53. - NODE_ENV=production
  54. {% if database_enabled -%}
  55. {% if database_type == 'postgres' -%}
  56. - DB_TYPE=postgresdb
  57. - DB_POSTGRESDB_HOST={{ database_host }}
  58. - DB_POSTGRESDB_PORT={{ database_port }}
  59. - DB_POSTGRESDB_DATABASE={{ database_name }}
  60. - DB_POSTGRESDB_USER={{ database_user }}
  61. {% if swarm_enabled -%}
  62. - DB_POSTGRESDB_PASSWORD_FILE=/run/secrets/{{ database_password_secret_name }}
  63. {% else -%}
  64. - DB_POSTGRESDB_PASSWORD={{ database_password }}
  65. {% endif -%}
  66. {% elif database_type == 'mysql' -%}
  67. - DB_TYPE=mysqldb
  68. - DB_MYSQLDB_HOST={{ database_host }}
  69. - DB_MYSQLDB_PORT={{ database_port }}
  70. - DB_MYSQLDB_DATABASE={{ database_name }}
  71. - DB_MYSQLDB_USER={{ database_user }}
  72. {% if swarm_enabled -%}
  73. - DB_MYSQLDB_PASSWORD_FILE=/run/secrets/{{ database_password_secret_name }}
  74. {% else -%}
  75. - DB_MYSQLDB_PASSWORD={{ database_password }}
  76. {% endif -%}
  77. {% endif -%}
  78. {% endif -%}
  79. {% if swarm_enabled -%}
  80. - N8N_ENCRYPTION_KEY_FILE=/run/secrets/{{ encryption_key_secret_name }}
  81. {% else -%}
  82. - N8N_ENCRYPTION_KEY={{ encryption_key }}
  83. {% endif -%}
  84. {% if webhook_url -%}
  85. - WEBHOOK_URL={{ webhook_url }}
  86. {% endif -%}
  87. - N8N_PROXY_HOPS={{ proxy_hops }}
  88. {% if metrics_enabled -%}
  89. - N8N_METRICS=true
  90. {% if metrics_detailed -%}
  91. - N8N_METRICS_INCLUDE_WORKFLOW_ID_LABELS=true
  92. - N8N_METRICS_INCLUDE_NODE_TYPE_LABEL=true
  93. - N8N_METRICS_INCLUDE_API_ENDPOINTS=true
  94. - N8N_METRICS_INCLUDE_API_STATUS_CODE_LABELS=true
  95. - N8N_METRICS_INCLUDE_CREDENTIAL_TYPE_LABEL=true
  96. {% endif -%}
  97. {% endif -%}
  98. - EXECUTIONS_DATA_SAVE_ON_ERROR={{ execution_save_on_error }}
  99. - EXECUTIONS_DATA_SAVE_ON_SUCCESS={{ execution_save_on_success }}
  100. {% if queue_enabled -%}
  101. - EXECUTIONS_MODE=queue
  102. - QUEUE_BULL_REDIS_HOST={{ queue_redis_host }}
  103. - QUEUE_BULL_REDIS_PORT={{ queue_redis_port }}
  104. - QUEUE_HEALTH_CHECK_ACTIVE=true
  105. {% if metrics_enabled -%}
  106. - N8N_METRICS_INCLUDE_QUEUE_METRICS=true
  107. {% endif -%}
  108. {% endif -%}
  109. volumes:
  110. - /etc/localtime:/etc/localtime:ro
  111. - data:/home/node/.n8n
  112. {% if network_mode == 'bridge' -%}
  113. networks:
  114. {% if traefik_enabled -%}
  115. - {{ traefik_network }}
  116. {% endif -%}
  117. - {{ network_name }}
  118. {% else -%}
  119. {% endif -%}
  120. {% if queue_enabled and not queue_redis_external -%}
  121. depends_on:
  122. redis:
  123. condition: service_healthy
  124. {% endif -%}
  125. {% if traefik_enabled -%}
  126. labels:
  127. - traefik.enable=true
  128. {% if network_mode == 'bridge' -%}
  129. - traefik.docker.network={{ traefik_network }}
  130. {% endif -%}
  131. {% if traefik_webhook_host -%}
  132. - traefik.http.routers.{{ service_name }}.rule=Host(`{{ traefik_host }}.{{ traefik_domain }}`) || Host(`{{ traefik_webhook_host }}`)
  133. {% else -%}
  134. - traefik.http.routers.{{ service_name }}.rule=Host(`{{ traefik_host }}.{{ traefik_domain }}`)
  135. {% endif -%}
  136. {% if traefik_tls_enabled -%}
  137. - traefik.http.routers.{{ service_name }}.entrypoints={{ traefik_tls_entrypoint }}
  138. - traefik.http.routers.{{ service_name }}.tls=true
  139. - traefik.http.routers.{{ service_name }}.tls.certresolver={{ traefik_tls_certresolver }}
  140. {% else -%}
  141. - traefik.http.routers.{{ service_name }}.entrypoints={{ traefik_entrypoint }}
  142. {% endif -%}
  143. - traefik.http.services.{{ service_name }}-web.loadbalancer.server.port=5678
  144. - traefik.http.routers.{{ service_name }}.service={{ service_name }}-web
  145. {% endif -%}
  146. {% if not swarm_enabled -%}
  147. restart: {{ restart_policy }}
  148. {% endif -%}
  149. {% if swarm_enabled -%}
  150. deploy:
  151. replicas: {{ swarm_replicas }}
  152. {% if swarm_placement_host -%}
  153. placement:
  154. constraints:
  155. - node.hostname == {{ swarm_placement_host }}
  156. {% endif -%}
  157. {% if traefik_enabled -%}
  158. labels:
  159. - traefik.enable=true
  160. - traefik.docker.network={{ traefik_network }}
  161. {% if traefik_webhook_host -%}
  162. - traefik.http.routers.{{ service_name }}.rule=Host(`{{ traefik_host }}.{{ traefik_domain }}`) || Host(`{{ traefik_webhook_host }}`)
  163. {% else -%}
  164. - traefik.http.routers.{{ service_name }}.rule=Host(`{{ traefik_host }}.{{ traefik_domain }}`)
  165. {% endif -%}
  166. {% if traefik_tls_enabled -%}
  167. - traefik.http.routers.{{ service_name }}.entrypoints={{ traefik_tls_entrypoint }}
  168. - traefik.http.routers.{{ service_name }}.tls=true
  169. - traefik.http.routers.{{ service_name }}.tls.certresolver={{ traefik_tls_certresolver }}
  170. {% else -%}
  171. - traefik.http.routers.{{ service_name }}.entrypoints={{ traefik_entrypoint }}
  172. {% endif -%}
  173. - traefik.http.services.{{ service_name }}-web.loadbalancer.server.port=5678
  174. - traefik.http.routers.{{ service_name }}.service={{ service_name }}-web
  175. {% endif -%}
  176. secrets:
  177. - {{ encryption_key_secret_name }}
  178. {% if database_enabled -%}
  179. - {{ database_password_secret_name }}
  180. {% endif -%}
  181. {% endif -%}
  182. {% if queue_enabled and queue_embedded_worker -%}
  183. {{ service_name }}-worker:
  184. image: n8nio/n8n:1.118.1
  185. command: worker
  186. {% if not swarm_enabled -%}
  187. container_name: {{ container_name }}-worker
  188. {% endif -%}
  189. environment:
  190. - N8N_LOG_LEVEL={{ container_loglevel }}
  191. - GENERIC_TIMEZONE={{ container_timezone }}
  192. - TZ={{ container_timezone }}
  193. {% if database_enabled -%}
  194. {% if database_type == 'postgres' -%}
  195. - DB_TYPE=postgresdb
  196. - DB_POSTGRESDB_HOST={{ database_host }}
  197. - DB_POSTGRESDB_PORT={{ database_port }}
  198. - DB_POSTGRESDB_DATABASE={{ database_name }}
  199. - DB_POSTGRESDB_USER={{ database_user }}
  200. {% if swarm_enabled -%}
  201. - DB_POSTGRESDB_PASSWORD_FILE=/run/secrets/{{ database_password_secret_name }}
  202. {% else -%}
  203. - DB_POSTGRESDB_PASSWORD={{ database_password }}
  204. {% endif -%}
  205. {% elif database_type == 'mysql' -%}
  206. - DB_TYPE=mysqldb
  207. - DB_MYSQLDB_HOST={{ database_host }}
  208. - DB_MYSQLDB_PORT={{ database_port }}
  209. - DB_MYSQLDB_DATABASE={{ database_name }}
  210. - DB_MYSQLDB_USER={{ database_user }}
  211. {% if swarm_enabled -%}
  212. - DB_MYSQLDB_PASSWORD_FILE=/run/secrets/{{ database_password_secret_name }}
  213. {% else -%}
  214. - DB_MYSQLDB_PASSWORD={{ database_password }}
  215. {% endif -%}
  216. {% endif -%}
  217. {% endif -%}
  218. {% if swarm_enabled -%}
  219. - N8N_ENCRYPTION_KEY_FILE=/run/secrets/{{ encryption_key_secret_name }}
  220. {% else -%}
  221. - N8N_ENCRYPTION_KEY={{ encryption_key }}
  222. {% endif -%}
  223. - EXECUTIONS_MODE=queue
  224. - QUEUE_BULL_REDIS_HOST={{ queue_redis_host }}
  225. - QUEUE_BULL_REDIS_PORT={{ queue_redis_port }}
  226. - QUEUE_HEALTH_CHECK_ACTIVE=true
  227. {% if metrics_enabled -%}
  228. - N8N_METRICS=true
  229. {% if metrics_detailed -%}
  230. - N8N_METRICS_INCLUDE_WORKFLOW_ID_LABELS=true
  231. - N8N_METRICS_INCLUDE_NODE_TYPE_LABEL=true
  232. {% endif -%}
  233. {% endif -%}
  234. volumes:
  235. - /etc/localtime:/etc/localtime:ro
  236. - data:/home/node/.n8n
  237. {% if network_mode == 'bridge' -%}
  238. networks:
  239. - {{ network_name }}
  240. {% else -%}
  241. {% endif -%}
  242. {% if not queue_redis_external -%}
  243. depends_on:
  244. redis:
  245. condition: service_healthy
  246. {% endif -%}
  247. {% if not swarm_enabled -%}
  248. restart: {{ restart_policy }}
  249. {% endif -%}
  250. {% if swarm_enabled -%}
  251. deploy:
  252. replicas: 1
  253. {% if swarm_placement_host -%}
  254. placement:
  255. constraints:
  256. - node.hostname == {{ swarm_placement_host }}
  257. {% endif -%}
  258. secrets:
  259. - {{ encryption_key_secret_name }}
  260. {% if database_enabled -%}
  261. - {{ database_password_secret_name }}
  262. {% endif -%}
  263. {% endif -%}
  264. {% endif -%}
  265. volumes:
  266. data:
  267. driver: local
  268. {% if queue_enabled and not queue_redis_external -%}
  269. redis_data:
  270. driver: local
  271. {% endif -%}
  272. {% if network_mode == 'bridge' -%}
  273. networks:
  274. {{ network_name }}:
  275. {% if network_external -%}
  276. external: true
  277. {% else -%}
  278. driver: bridge
  279. {% endif -%}
  280. {% if traefik_enabled -%}
  281. {{ traefik_network }}:
  282. {% if traefik_network_external -%}
  283. external: true
  284. {% else -%}
  285. driver: bridge
  286. {% endif -%}
  287. {% endif -%}
  288. {% endif -%}
  289. {% if swarm_enabled -%}
  290. secrets:
  291. {{ encryption_key_secret_name }}:
  292. external: true
  293. {% if database_enabled -%}
  294. {{ database_password_secret_name }}:
  295. external: true
  296. {% endif -%}
  297. {% endif -%}