compose.yaml.j2 9.9 KB

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