services:
  server:
    build:
      context: .
      dockerfile: deployments/Dockerfile
      args:
        VERSION: ${VERSION:-dev}
        GIT_COMMIT: ${GIT_COMMIT:-unknown}
    image: drip-server:${VERSION:-latest}
    container_name: drip-server
    restart: unless-stopped

    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
      - "20000-20100:20000-20100"

    volumes:
      - drip-data:/app/data
      # Mount TLS certificates if not using auto-TLS
      # - ./certs:/app/data/certs:ro

    environment:
      TZ: ${TZ:-UTC}

    command: >
      server
      --domain ${DOMAIN:-tunnel.localhost}
      --port ${PORT:-8080}
      ${TLS_CERT:+--tls-cert /app/data/certs/fullchain.pem}
      ${TLS_KEY:+--tls-key /app/data/certs/privkey.pem}
      ${AUTO_TLS:+--auto-tls}
      ${AUTH_TOKEN:+--token ${AUTH_TOKEN}}

    networks:
      - drip-net

    logging:
      driver: json-file
      options:
        max-size: 10m
        max-file: "3"

    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 512M
        reservations:
          cpus: '0.5'
          memory: 128M

    healthcheck:
      test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:${PORT:-8080}/health"]
      interval: 30s
      timeout: 3s
      retries: 3
      start_period: 5s

volumes:
  drip-data:
    driver: local

networks:
  drip-net:
    driver: bridge
