services:
  n8n:
    extends:
      file: ${TEMPLATES_PATH}
      service: default
    build:
      context: .
      dockerfile: ${SERVICE_PATH}/n8n/Dockerfile
    container_name: n8n
    ports:
      - 4022:5678
    networks:
      - ip4net
    environment:
      - N8N_BLOCK_ENV_ACCESS_IN_NODE=false
      - MAM_USERNAME=${N8N_MAM_USERNAME}
      - MAM_PASSWORD=${N8N_MAM_PASSWORD}
      - RESTIC_PASSWORD=${N8N_RESTIC_PASSWORD}
      - NODES_EXCLUDE=[]
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=n8n
      - DB_POSTGRESDB_PASSWORD=${N8N_DB_PASSWORD}
      - DB_POSTGRESDB_SCHEMA=public
    volumes:
      - ${SERVICE_PATH}/n8n/data:/home/node/.n8n
      - ${SERVICE_PATH}/n8n/data/rclone.conf:/home/node/.config/rclone/rclone.conf
      - ${PWD}/scripts:/home/node/.n8n/external-scripts
      - ${DB_PATH}/databasus/data/backups:/home/node/.n8n/database
      - ${EXTERNAL_STORAGE}/:/home/node/.n8n/data
    labels:
      # Traefik
      - "traefik.enable=true"
      - "traefik.http.routers.n8n.rule=Host(`n8n.${LOCAL_DOMAIN}`)"
      - "traefik.http.routers.n8n.entrypoints=https"
      - "traefik.http.routers.n8n.tls=true"
