version: "3.8"

# =============================================================================
# The Things Stack LoRaWAN Network Server — Smart City Digital Twin
# =============================================================================
# Déploiement derrière Traefik avec sous-domaines dédiés
# Subdomaines:
#   - tts.digitribe.fr      → Console web (port 1885)
#   - tts-api.digitribe.fr  → REST API (port 1884)
# =============================================================================

services:
  tts-postgres:
    container_name: smart-city-tts-postgres
    image: postgres:14
    restart: unless-stopped
    environment:
      - POSTGRES_PASSWORD=root
      - POSTGRES_USER=root
      - POSTGRES_DB=ttn_lorawan
    volumes:
      - tts-postgres-data:/var/lib/postgresql/data
    networks:
      - smartcity-shared
  tts-redis:
    container_name: smart-city-tts-redis
    image: redis:7
    command: redis-server --appendonly yes
    restart: unless-stopped
    volumes:
      - tts-redis-data:/data
    networks:
      - smartcity-shared
  tts-stack:
    container_name: smart-city-tts-stack
    image: thethingsnetwork/lorawan-stack:latest
    entrypoint: ttn-lw-stack -c /config/ttn-lw-stack-docker.yml
    command: start
    restart: unless-stopped
    depends_on:
      - tts-redis
      - tts-postgres
    volumes:
      - ./configuration/the-things-stack/config:/config:ro
      - ./configuration/the-things-stack/blob:/srv/ttn-lorawan/public/blob
    environment:
      TTN_LW_BLOB_LOCAL_DIRECTORY: /srv/ttn-lorawan/public/blob
      TTN_LW_REDIS_ADDRESS: tts-redis:6379
      TTN_LW_IS_DATABASE_URI: postgres://root:***@tts-postgres:5432/ttn_lorawan?sslmode=disable
    ports:
      - "1701:1700/udp"  # ChirpStack uses 1700
    labels:
      - "traefik.enable=true"
      # Console web
      - "traefik.http.routers.tts-console.rule=Host(`tts.digitribe.fr`)"
      - "traefik.http.routers.tts-console.entrypoints=websecure"
      - "traefik.http.routers.tts-console.tls.certresolver=letsencrypt"
      - "traefik.http.services.tts-console.loadbalancer.server.port=1885"
      # API REST
      - "traefik.http.routers.tts-api.rule=Host(`tts-api.digitribe.fr`)"
      - "traefik.http.routers.tts-api.entrypoints=websecure"
      - "traefik.http.routers.tts-api.tls.certresolver=letsencrypt"
      - "traefik.http.services.tts-api.loadbalancer.server.port=1884"
    networks:
      - traefik-public
      - smartcity-shared
volumes:
  tts-postgres-data:
  tts-redis-data:

networks:
  traefik-public:
    external: true
  smartcity-shared:
    external: true
