# Immich - Photo/video backup solution
# URL: http://192.168.0.200:8212 (LAN only)
# Port: 2283
# Google Photos alternative with ML-powered features
# SSO: Authentik OIDC (sso.vish.gg/application/o/immich-atlantis/)
version: "3.9"

services:
  immich-redis:
    image: redis
    container_name: Immich-REDIS
    hostname: immich-redis
    security_opt:
      - no-new-privileges:true
    healthcheck:
      test: ["CMD-SHELL", "redis-cli ping || exit 1"]
    user: 1026:100
    environment:
      - TZ=America/Los_Angeles
    volumes:
      - /volume2/metadata/docker/immich/redis:/data:rw
    restart: on-failure:5

  immich-db:
    image: ghcr.io/immich-app/postgres:16-vectorchord0.4.3-pgvectors0.2.0
    container_name: Immich-DB
    hostname: immich-db
    security_opt:
      - no-new-privileges:true
    shm_size: 256mb
    healthcheck:
      test: ["CMD", "pg_isready", "-q", "-d", "immich", "-U", "immichuser"]
      interval: 10s
      timeout: 5s
      retries: 5
    volumes:
      - /volume2/metadata/docker/immich/db:/var/lib/postgresql/data:rw
    environment:
      - TZ=America/Los_Angeles
      - POSTGRES_DB=immich
      - POSTGRES_USER=immichuser
      - POSTGRES_PASSWORD="REDACTED_PASSWORD"  # pragma: allowlist secret
      # Uncomment if your database is on spinning disks instead of SSD
      - DB_STORAGE_TYPE=HDD
    restart: on-failure:5

  immich-server:
    image: ghcr.io/immich-app/immich-server:release
    container_name: Immich-SERVER
    hostname: immich-server
    user: 1026:100
    security_opt:
      - no-new-privileges:true
    env_file:
      - stack.env
    ports:
      - 8212:2283
    environment:
      - IMMICH_CONFIG_FILE=/config/immich-config.json
    volumes:
      # Main Immich data folder
      - /volume2/metadata/docker/immich/upload:/data:rw
      # Mount Synology Photos library as external read-only source
      - /volume1/homes/vish/Photos:/external/photos:ro
      - /etc/localtime:/etc/localtime:ro
      # SSO config
      - /volume2/metadata/docker/immich/config/immich-config.json:/config/immich-config.json:ro
    depends_on:
      immich-redis:
        condition: service_healthy
      immich-db:
        condition: service_started
    restart: on-failure:5
    deploy:
      resources:
        limits:
          memory: 4G

  immich-machine-learning:
    image: ghcr.io/immich-app/immich-machine-learning:release
    container_name: Immich-LEARNING
    hostname: immich-machine-learning
    user: 1026:100
    security_opt:
      - no-new-privileges:true
    env_file:
      - stack.env
    volumes:
      - /volume2/metadata/docker/immich/upload:/data:rw
      - /volume1/homes/vish/Photos:/external/photos:ro
      - /volume2/metadata/docker/immich/cache:/cache:rw
      - /volume2/metadata/docker/immich/cache:/.cache:rw
      - /volume2/metadata/docker/immich/cache:/.config:rw
      - /volume2/metadata/docker/immich/matplotlib:/matplotlib:rw
    environment:
      - MPLCONFIGDIR=/matplotlib
    depends_on:
      immich-db:
        condition: service_started
    restart: on-failure:5
    deploy:
      resources:
        limits:
          memory: 4G
