services:
  remnawave:
    image: remnawave/backend:2
    container_name: remnawave
    hostname: remnawave
    restart: unless-stopped
    env_file: /srv/remnawave/env/.env

    ports:
      - "127.0.0.1:4000:4000"
      - "127.0.0.1:4001:4001"

    depends_on:
      remnawave-db:
        condition: service_healthy
      remnawave-redis:
        condition: service_healthy

    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:3001/health"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 30s

    ulimits:
      nofile:
        soft: 1048576
        hard: 1048576

    networks:
      - remnawave-network

    logging:
      driver: json-file
      options:
        max-size: "100m"
        max-file: "5"

  remnawave-db:
    image: postgres:17.6
    container_name: remnawave-db
    hostname: remnawave-db
    restart: unless-stopped
    env_file: /srv/remnawave/env/.env
    environment:
      - TZ=UTC

    ports:
      - "127.0.0.1:6767:5432"

    volumes:
      - /srv/remnawave/postgres:/var/lib/postgresql/data

    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
      interval: 3s
      timeout: 10s
      retries: 3

    networks:
      - remnawave-network

    logging:
      driver: json-file
      options:
        max-size: "100m"
        max-file: "5"

  remnawave-redis:
    image: valkey/valkey:8.1-alpine
    container_name: remnawave-redis
    hostname: remnawave-redis
    restart: unless-stopped

    command: >
      valkey-server --save "" --appendonly no --maxmemory-policy noeviction --loglevel warning

    healthcheck:
      test: ["CMD", "valkey-cli", "ping"]
      interval: 3s
      timeout: 3s
      retries: 3

    networks:
      - remnawave-network

    logging:
      driver: json-file
      options:
        max-size: "100m"
        max-file: "5"

networks:
  remnawave-network:
    name: remnawave-network
    driver: bridge
