# Synor Hosting Layer - Docker Compose
# Subdomain-based web hosting on Synor Storage

version: '3.9'

services:
  # Hosting Gateway (main entry point)
  hosting-gateway:
    build:
      context: .
      dockerfile: docker/hosting-gateway/Dockerfile
    container_name: synor-hosting-gateway
    hostname: hosting-gateway
    restart: unless-stopped
    environment:
      - RUST_LOG=info
      - LISTEN_ADDR=0.0.0.0:8080
      - HOSTING_DOMAIN=synor.cc
      - STORAGE_GATEWAY_URL=http://storage-gateway:80
      - RATE_LIMIT=100
    ports:
      - "8280:8080"     # HTTP
    networks:
      - synor-hosting-net
      - synor-storage-net
    depends_on:
      - storage-gateway
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 10s

  # Caddy reverse proxy with automatic HTTPS
  caddy:
    image: caddy:alpine
    container_name: synor-hosting-caddy
    hostname: caddy
    restart: unless-stopped
    volumes:
      - ./docker/hosting-gateway/Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy-data:/data
      - caddy-config:/config
    ports:
      - "80:80"         # HTTP (redirects to HTTPS)
      - "443:443"       # HTTPS
    networks:
      - synor-hosting-net
    depends_on:
      - hosting-gateway
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost:80"]
      interval: 30s
      timeout: 5s
      retries: 3

  # Storage Gateway (from storage stack)
  storage-gateway:
    image: nginx:alpine
    container_name: synor-hosting-storage-gw
    hostname: storage-gateway
    restart: unless-stopped
    volumes:
      - ./docker/storage-gateway/nginx.conf:/etc/nginx/nginx.conf:ro
    networks:
      - synor-hosting-net
      - synor-storage-net
    depends_on:
      - storage-node-1
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost/health"]
      interval: 15s
      timeout: 5s
      retries: 3

  # Storage Node (minimal for hosting)
  storage-node-1:
    build:
      context: .
      dockerfile: docker/storage-node/Dockerfile
    container_name: synor-hosting-storage-1
    hostname: storage-node-1
    restart: unless-stopped
    environment:
      - RUST_LOG=info
      - NODE_ID=storage-node-1
    volumes:
      - storage-node-1-data:/data/storage
    networks:
      - synor-storage-net
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5001/health"]
      interval: 30s
      timeout: 10s
      retries: 3

volumes:
  caddy-data:
    driver: local
  caddy-config:
    driver: local
  storage-node-1-data:
    driver: local

networks:
  synor-hosting-net:
    driver: bridge
    ipam:
      config:
        - subnet: 172.22.0.0/16
  synor-storage-net:
    driver: bridge
    ipam:
      config:
        - subnet: 172.21.0.0/16
