x-defaults: &defaults
  restart: unless-stopped
  logging:
    driver: json-file
    options:
      max-size: 100m
      max-file: '3'

services:
  cassandra:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}cassandra:${CASSANDRA_VERSION:-5.0.2}
    ports:
      - '${CASSANDRA_CQL_PORT_OVERRIDE:-9042}:9042'
      - '${CASSANDRA_THRIFT_PORT_OVERRIDE:-9160}:9160'
    volumes:
      - cassandra_data:/var/lib/cassandra
      - cassandra_logs:/var/log/cassandra

      # Custom configuration
      # - ./cassandra.yaml:/etc/cassandra/cassandra.yaml:ro
    environment:
      - TZ=${TZ:-UTC}
      - CASSANDRA_CLUSTER_NAME=${CASSANDRA_CLUSTER_NAME:-Test Cluster}
      - CASSANDRA_DC=${CASSANDRA_DC:-datacenter1}
      - CASSANDRA_RACK=${CASSANDRA_RACK:-rack1}
      - CASSANDRA_ENDPOINT_SNITCH=${CASSANDRA_ENDPOINT_SNITCH:-GossipingPropertyFileSnitch}
      - CASSANDRA_NUM_TOKENS=${CASSANDRA_NUM_TOKENS:-256}
      - CASSANDRA_SEEDS=${CASSANDRA_SEEDS:-cassandra}
      - CASSANDRA_START_RPC=${CASSANDRA_START_RPC:-false}
      - MAX_HEAP_SIZE=${MAX_HEAP_SIZE:-1G}
      - HEAP_NEWSIZE=${HEAP_NEWSIZE:-100M}
    deploy:
      resources:
        limits:
          cpus: ${CASSANDRA_CPU_LIMIT:-2.00}
          memory: ${CASSANDRA_MEMORY_LIMIT:-2G}
        reservations:
          cpus: ${CASSANDRA_CPU_RESERVATION:-0.50}
          memory: ${CASSANDRA_MEMORY_RESERVATION:-1G}
    healthcheck:
      test: [CMD-SHELL, "cqlsh -e 'DESCRIBE CLUSTER'"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 60s

volumes:
  cassandra_data:
  cassandra_logs:
