# Synor Storage Layer - Docker Compose
# Decentralized storage network components

version: '3.9'

services:
  # Storage Node 1
  storage-node-1:
    build:
      context: .
      dockerfile: docker/storage-node/Dockerfile
    container_name: synor-storage-node-1
    hostname: storage-node-1
    restart: unless-stopped
    environment:
      - RUST_LOG=info
      - NODE_ID=storage-node-1
      - L1_RPC=http://synor-node-1:8545
    volumes:
      - storage-node-1-data:/data/storage
      - ./docker/storage-node/config.toml:/config/config.toml:ro
    ports:
      - "4101:4001"   # P2P
      - "5101:5001"   # API
      - "8101:8080"   # Gateway
    networks:
      - synor-storage-net
      - synor-testnet
    depends_on:
      - synor-node-1
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5001/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

  # Storage Node 2
  storage-node-2:
    build:
      context: .
      dockerfile: docker/storage-node/Dockerfile
    container_name: synor-storage-node-2
    hostname: storage-node-2
    restart: unless-stopped
    environment:
      - RUST_LOG=info
      - NODE_ID=storage-node-2
      - L1_RPC=http://synor-node-1:8545
      - BOOTSTRAP_NODES=/dns4/storage-node-1/tcp/4001
    volumes:
      - storage-node-2-data:/data/storage
      - ./docker/storage-node/config.toml:/config/config.toml:ro
    ports:
      - "4102:4001"
      - "5102:5001"
      - "8102:8080"
    networks:
      - synor-storage-net
      - synor-testnet
    depends_on:
      - storage-node-1
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5001/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

  # Storage Node 3
  storage-node-3:
    build:
      context: .
      dockerfile: docker/storage-node/Dockerfile
    container_name: synor-storage-node-3
    hostname: storage-node-3
    restart: unless-stopped
    environment:
      - RUST_LOG=info
      - NODE_ID=storage-node-3
      - L1_RPC=http://synor-node-1:8545
      - BOOTSTRAP_NODES=/dns4/storage-node-1/tcp/4001
    volumes:
      - storage-node-3-data:/data/storage
      - ./docker/storage-node/config.toml:/config/config.toml:ro
    ports:
      - "4103:4001"
      - "5103:5001"
      - "8103:8080"
    networks:
      - synor-storage-net
      - synor-testnet
    depends_on:
      - storage-node-1
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5001/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

  # Public Gateway (load-balanced entry point)
  storage-gateway:
    image: nginx:alpine
    container_name: synor-storage-gateway
    hostname: storage-gateway
    restart: unless-stopped
    volumes:
      - ./docker/storage-gateway/nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - "8180:80"     # Public gateway
      - "8181:443"    # HTTPS (if configured)
    networks:
      - synor-storage-net
    depends_on:
      - storage-node-1
      - storage-node-2
      - storage-node-3
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost/health"]
      interval: 15s
      timeout: 5s
      retries: 3

volumes:
  storage-node-1-data:
    driver: local
  storage-node-2-data:
    driver: local
  storage-node-3-data:
    driver: local

networks:
  synor-storage-net:
    driver: bridge
    ipam:
      config:
        - subnet: 172.21.0.0/16
  synor-testnet:
    external: true
