services:
  n8n:
    build:
      context: .
      dockerfile: Dockerfile.n8n
    container_name: n8n-agent-system
    restart: unless-stopped
    ports:
      - "5678:5678"
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=admin123
      - N8N_HOST=my-n8n-docker.duckdns.org
      - N8N_PROTOCOL=https
      - WEBHOOK_URL=https://my-n8n-docker.duckdns.org/
      - N8N_PROXY_HOPS=1
      - GENERIC_TIMEZONE=UTC
      - N8N_LOG_LEVEL=info
      - N8N_METRICS=true
      - N8N_DIAGNOSTICS_ENABLED=true
      - TELEGRAM_BOT_TOKEN=8620375768:AAFVx67vigeU5VsuK1eqMqWuI2gZFFN6C6c
      - HOME_ASSISTANT_TOKEN=${HOME_ASSISTANT_TOKEN}
      - N8N_BLOCK_ENV_ACCESS_IN_NODE=false
      - OLLAMA_BASE_URL=http://ollama-server:11434
      - TELEGRAM_CHAT_ID=YOUR_TELEGRAM_CHAT_ID
      - N8N_CORS_ALLOWED_ORIGINS=https://mytradings.duckdns.org
    volumes:
      - n8n_data:/home/node/.n8n
      - ./agents:/home/node/.n8n/agents:ro
    networks:
      - agent-network

  caddy:
    build:
      context: .
      dockerfile: Dockerfile.caddy
    container_name: caddy
    restart: unless-stopped
    ports:
      - "443:443"
      - "443:443/udp"
    environment:
      - DUCKDNS_TOKEN=b370eb27-81e4-428f-b1af-5041b5fad5bb
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./dashboard.html:/srv/dashboard.html:ro
      - caddy_data:/data
      - caddy_config:/config
      - caddy_logs:/var/log/caddy
    networks:
      - agent-network

  fail2ban:
    image: crazymax/fail2ban:latest
    container_name: fail2ban
    restart: unless-stopped
    network_mode: host
    cap_add:
      - NET_ADMIN
      - NET_RAW
    volumes:
      - caddy_logs:/var/log/caddy:ro
      - ./fail2ban:/data
    environment:
      - TZ=UTC
      - F2B_LOG_LEVEL=INFO
      - F2B_DB_PURGE_AGE=1d

  duckdns:
    image: lscr.io/linuxserver/duckdns:latest
    container_name: duckdns
    restart: unless-stopped
    environment:
      - SUBDOMAINS=my-n8n-docker,mytradings
      - TOKEN=b370eb27-81e4-428f-b1af-5041b5fad5bb
      - TZ=UTC
    networks:
      - agent-network

  nmap-api:
    build:
      context: ./nmap-api
      dockerfile: Dockerfile
    container_name: nmap-api
    restart: unless-stopped
    privileged: true
    network_mode: host
    environment:
      - SCAN_TARGET=host.docker.internal
      - FALLBACK_IP=192.168.0.101

  ollama-server:
    image: ollama/ollama:latest
    container_name: ollama-server
    restart: unless-stopped
    ports:
      - "11434:11434"
    environment:
      - OLLAMA_ORIGINS=*
    volumes:
      - ollama_data:/root/.ollama
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    networks:
      - agent-network


volumes:
  n8n_data:
    driver: local
  ollama_data:
    driver: local
  caddy_data:
    driver: local
  caddy_config:
    driver: local
  caddy_logs:
    driver: local

networks:
  agent-network:
    driver: bridge
