| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- services:
- {{ service_name }}:
- image: n8nio/n8n:1.118.1
- command: worker
- {#
- If not in swarm mode, apply container name and hostname
- #}
- {% if not swarm_enabled -%}
- container_name: {{ container_name }}
- hostname: {{ container_hostname }}
- {% endif -%}
- {#
- Environment variables for n8n worker configuration:
- - Database connection (must match n8n-server)
- - Encryption key (must match n8n-server)
- - Redis queue configuration
- - Optional metrics
- #}
- environment:
- - N8N_LOG_LEVEL={{ container_loglevel }}
- - GENERIC_TIMEZONE={{ container_timezone }}
- - TZ={{ container_timezone }}
- {% if database_enabled -%}
- {% if database_type == 'postgres' -%}
- - DB_TYPE=postgresdb
- - DB_POSTGRESDB_HOST={{ database_host }}
- - DB_POSTGRESDB_PORT={{ database_port }}
- - DB_POSTGRESDB_DATABASE={{ database_name }}
- - DB_POSTGRESDB_USER={{ database_user }}
- {% if swarm_enabled -%}
- - DB_POSTGRESDB_PASSWORD_FILE=/run/secrets/{{ service_name }}_database_password
- {% else -%}
- - DB_POSTGRESDB_PASSWORD={{ database_password }}
- {% endif -%}
- {% elif database_type == 'mysql' -%}
- - DB_TYPE=mysqldb
- - DB_MYSQLDB_HOST={{ database_host }}
- - DB_MYSQLDB_PORT={{ database_port }}
- - DB_MYSQLDB_DATABASE={{ database_name }}
- - DB_MYSQLDB_USER={{ database_user }}
- {% if swarm_enabled -%}
- - DB_MYSQLDB_PASSWORD_FILE=/run/secrets/{{ service_name }}_database_password
- {% else -%}
- - DB_MYSQLDB_PASSWORD={{ database_password }}
- {% endif -%}
- {% endif -%}
- {% endif -%}
- {% if swarm_enabled -%}
- - N8N_ENCRYPTION_KEY_FILE=/run/secrets/{{ service_name }}_encryption_key
- {% else -%}
- - N8N_ENCRYPTION_KEY={{ encryption_key }}
- {% endif -%}
- - EXECUTIONS_MODE=queue
- - QUEUE_BULL_REDIS_HOST={{ redis_host }}
- - QUEUE_BULL_REDIS_PORT={{ redis_port }}
- - QUEUE_HEALTH_CHECK_ACTIVE=true
- {% if metrics_enabled -%}
- - N8N_METRICS=true
- {% if metrics_detailed -%}
- - N8N_METRICS_INCLUDE_WORKFLOW_ID_LABELS=true
- - N8N_METRICS_INCLUDE_NODE_TYPE_LABEL=true
- {% endif -%}
- {% endif -%}
- {#
- Volume configuration for persistent data
- #}
- volumes:
- - /etc/localtime:/etc/localtime:ro
- - data:/home/node/.n8n
- {#
- If not in swarm mode, apply restart policy
- #}
- {% if not swarm_enabled -%}
- restart: {{ restart_policy }}
- {% endif -%}
- {#
- Deploy configuration for Swarm mode:
- - Multiple worker replicas for scaling
- - Uses Docker secrets for sensitive data
- #}
- {% if swarm_enabled -%}
- deploy:
- replicas: {{ swarm_replicas }}
- {% if swarm_placement_host -%}
- placement:
- constraints:
- - node.hostname == {{ swarm_placement_host }}
- {% endif -%}
- secrets:
- - {{ service_name }}_encryption_key
- {% if database_enabled -%}
- - {{ service_name }}_database_password
- {% endif -%}
- {% endif -%}
- {#
- Volume definitions:
- - data: Persistent storage for n8n worker data
- #}
- volumes:
- data:
- driver: local
- {#
- Docker Swarm secrets (only when swarm_enabled is set):
- - Encryption key and database password (external secrets)
- #}
- {% if swarm_enabled -%}
- secrets:
- {{ service_name }}_encryption_key:
- external: true
- {% if database_enabled -%}
- {{ service_name }}_database_password:
- external: true
- {% endif -%}
- {% endif -%}
|