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

services:
  halo:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}halohub/halo:${HALO_VERSION:-2.21.9}
    ports:
      - '${HALO_PORT:-8090}:8090'
    volumes:
      - halo_data:/root/.halo2
    environment:
      - TZ=${TZ:-UTC}
      - SPRING_R2DBC_URL=${SPRING_R2DBC_URL:-r2dbc:pool:postgresql://halo-db:5432/halo}
      - SPRING_R2DBC_USERNAME=${POSTGRES_USER:-postgres}
      - SPRING_R2DBC_PASSWORD=${POSTGRES_PASSWORD:-postgres}
      - SPRING_SQL_INIT_PLATFORM=${SPRING_SQL_INIT_PLATFORM:-postgresql}
      - HALO_EXTERNAL_URL=${HALO_EXTERNAL_URL:-http://localhost:8090}
      - HALO_SECURITY_INITIALIZER_SUPERADMINUSERNAME=${HALO_ADMIN_USERNAME:-admin}
      - HALO_SECURITY_INITIALIZER_SUPERADMINPASSWORD=${HALO_ADMIN_PASSWORD:-}
    depends_on:
      halo-db:
        condition: service_healthy
    deploy:
      resources:
        limits:
          cpus: ${HALO_CPU_LIMIT:-2.0}
          memory: ${HALO_MEMORY_LIMIT:-2G}
        reservations:
          cpus: ${HALO_CPU_RESERVATION:-0.5}
          memory: ${HALO_MEMORY_RESERVATION:-512M}
    healthcheck:
      test: [CMD, wget, --no-verbose, --tries=1, --spider, 'http://localhost:8090/actuator/health']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  halo-db:
    <<: *defaults
    image: ${GLOBAL_REGISTRY:-}postgres:${POSTGRES_VERSION:-17.2-alpine3.21}
    environment:
      - TZ=${TZ:-UTC}
      - POSTGRES_USER=${POSTGRES_USER:-postgres}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
      - POSTGRES_DB=${POSTGRES_DB:-halo}
      - PGUSER=${POSTGRES_USER:-postgres}
    volumes:
      - halo_db_data:/var/lib/postgresql/data
    healthcheck:
      test: [CMD-SHELL, pg_isready]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
    deploy:
      resources:
        limits:
          cpus: ${HALO_DB_CPU_LIMIT:-1.0}
          memory: ${HALO_DB_MEMORY_LIMIT:-1G}
        reservations:
          cpus: ${HALO_DB_CPU_RESERVATION:-0.25}
          memory: ${HALO_DB_MEMORY_RESERVATION:-256M}

volumes:
  halo_data:
  halo_db_data:
