services:
  photo-library:
    image: ghcr.io/example/photo-library:1.12.3
    container_name: photo-library
    restart: unless-stopped
    depends_on:
      database:
        condition: service_healthy
      cache:
        condition: service_healthy
    ports:
      - "2283:8080"
    environment:
      TZ: America/Toronto
      DATABASE_URL: postgresql://photo_library:${DB_PASSWORD}@database:5432/photo_library
      REDIS_URL: redis://cache:6379/0
      UPLOAD_DIRECTORY: /data/uploads
      THUMBNAIL_DIRECTORY: /data/thumbnails
      MAX_UPLOAD_SIZE: 20G
      ENABLE_MACHINE_LEARNING: "true"
      PUBLIC_REGISTRATION: "false"
    volumes:
      - photo_uploads:/data/uploads
      - photo_thumbnails:/data/thumbnails
      - /mnt/photos/import:/data/import:ro
    healthcheck:
      test: ["CMD", "wget", "--quiet", "--spider", "http://localhost:8080/health"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 45s
    networks:
      - photo_network

  machine-learning:
    image: ghcr.io/example/photo-library-ml:1.12.3
    container_name: photo-library-ml
    restart: unless-stopped
    environment:
      TZ: America/Toronto
      MODEL_CACHE_DIRECTORY: /cache
    volumes:
      - model_cache:/cache
    networks:
      - photo_network

  database:
    image: postgres:16-alpine
    container_name: photo-library-db
    restart: unless-stopped
    environment:
      POSTGRES_DB: photo_library
      POSTGRES_USER: photo_library
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    volumes:
      - database_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U photo_library -d photo_library"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - photo_network

  cache:
    image: redis:7-alpine
    container_name: photo-library-cache
    restart: unless-stopped
    command: redis-server --save 60 1 --loglevel warning
    volumes:
      - cache_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5
    networks:
      - photo_network

volumes:
  photo_uploads:
  photo_thumbnails:
  model_cache:
  database_data:
  cache_data:

networks:
  photo_network:
    driver: bridge