version: '3.8'

services:
  littleshop:
    build: ./LittleShop
    image: littleshop:latest
    container_name: littleshop
    restart: unless-stopped
    environment:
      - ASPNETCORE_ENVIRONMENT=Production
      - ASPNETCORE_URLS=http://+:8080
      - Jwt__Key=${Jwt__Key:-YourSuperSecretKeyThatIsAtLeast32CharactersLong!}
      - BTCPAY_SERVER_URL=${BTCPAY_SERVER_URL:-https://thebankofdebbie.giize.com}
      - BTCPAY_STORE_ID=${BTCPAY_STORE_ID:-}
      - BTCPAY_API_KEY=${BTCPAY_API_KEY:-}
      - BTCPAY_WEBHOOK_SECRET=${BTCPAY_WEBHOOK_SECRET:-}
      - ConnectionStrings__DefaultConnection=Data Source=/app/data/littleshop.db
    volumes:
      - littleshop_data:/app/data
      - littleshop_uploads:/app/wwwroot/uploads
      - littleshop_logs:/app/logs
    ports:
      - "8081:8080"  # Expose on port 8081 to avoid conflicts with BTCPay
    networks:
      - littleshop_network
    labels:
      # Traefik configuration for reverse proxy
      - "traefik.enable=true"
      - "traefik.docker.network=littleshop_network"

      # HTTP Router for LittleShop
      - "traefik.http.routers.littleshop.rule=Host(`shop.thebankofdebbie.giize.com`)"
      - "traefik.http.routers.littleshop.entrypoints=websecure"
      - "traefik.http.routers.littleshop.tls=true"
      - "traefik.http.routers.littleshop.tls.certresolver=letsencrypt"

      # Service
      - "traefik.http.services.littleshop.loadbalancer.server.port=8080"

      # Middleware for forwarded headers
      - "traefik.http.routers.littleshop.middlewares=littleshop-headers"
      - "traefik.http.middlewares.littleshop-headers.headers.customrequestheaders.X-Forwarded-Proto=https"
      - "traefik.http.middlewares.littleshop-headers.headers.customrequestheaders.X-Forwarded-Host=shop.thebankofdebbie.giize.com"

  # Optional: Reverse proxy with nginx if Traefik is not available
  nginx:
    image: nginx:alpine
    container_name: littleshop-nginx
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./ssl:/etc/nginx/ssl:ro
    depends_on:
      - littleshop
    networks:
      - littleshop_network
    profiles:
      - nginx  # Only start with: docker-compose --profile nginx up

volumes:
  littleshop_data:
    driver: local
  littleshop_uploads:
    driver: local
  littleshop_logs:
    driver: local

networks:
  littleshop_network:
    driver: bridge