# Local dev infra for @mac-sync server.
#
# Services:
#   - postgres : metadata DB (macsync.* schema)
#   - redis    : BullMQ broker for thumbnail / face / classification workers
#   - minio    : S3-compatible blob store for originals / thumbnails / previews
#
# Ports are picked to not collide with imajin-media-gallery's stack on
# apricot (25448 / 26392 / 9012-9013), so both can run side-by-side during
# the port transition.
#
# Usage: docker compose -f docker-compose.dev.yml up -d

services:
  mac-sync-postgres:
    image: pgvector/pgvector:pg16
    container_name: mac-sync-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-postgres}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-macsync_dev_password}
      POSTGRES_DB: ${POSTGRES_DB:-macsync}
    ports:
      - '${POSTGRES_PORT:-25450}:5432'
    volumes:
      - mac-sync-postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-macsync}']
      interval: 10s
      timeout: 5s
      retries: 5

  mac-sync-redis:
    image: redis:7.4-alpine
    container_name: mac-sync-redis
    restart: unless-stopped
    ports:
      - '${REDIS_PORT:-26393}:6379'
    command:
      - redis-server
      - --appendonly
      - 'yes'
      - --appendfsync
      - 'everysec'
      - --maxmemory
      - '${REDIS_MAX_MEMORY:-512mb}'
      - --maxmemory-policy
      - 'allkeys-lru'
    volumes:
      - mac-sync-redis-data:/data
    healthcheck:
      test: ['CMD', 'redis-cli', 'ping']
      interval: 10s
      timeout: 3s
      retries: 5

  mac-sync-minio:
    image: minio/minio:latest
    container_name: mac-sync-minio
    restart: unless-stopped
    environment:
      # MINIO_ROOT_* are the container's own required vars; their values come
      # from the same S3_* host env the app reads, so one set configures both.
      MINIO_ROOT_USER: ${S3_ACCESS_KEY:-macsync_access}
      MINIO_ROOT_PASSWORD: ${S3_SECRET_KEY:-macsync_secret_dev_key}
    ports:
      - '${MINIO_PORT:-9014}:9000'
      - '${MINIO_CONSOLE_PORT:-9015}:9001'
    command: server /data --console-address ":9001"
    volumes:
      - mac-sync-minio-data:/data
    healthcheck:
      test: ['CMD', 'curl', '-f', 'http://localhost:9000/minio/health/live']
      interval: 30s
      timeout: 10s
      retries: 3

volumes:
  mac-sync-postgres-data:
    name: mac-sync-${MAC_SYNC_ENV:-dev}-postgres-data
  mac-sync-redis-data:
    name: mac-sync-${MAC_SYNC_ENV:-dev}-redis-data
  mac-sync-minio-data:
    name: mac-sync-${MAC_SYNC_ENV:-dev}-minio-data
