# Immich - Photo/video backup solution
# URL: https://photos.vishconcord.synology.me
# Port: 2283
# Google Photos alternative with ML-powered features
#
# IMPORTANT: Portainer git deploy does NOT load env_file references.
# All env vars from stack.env MUST be set as Portainer stack environment
# overrides. Without them, DB_HOSTNAME defaults to "database" (Immich v2.6.2+)
# causing "getaddrinfo ENOTFOUND database" crashes.
# Fixed 2026-03-27: env vars added as Portainer stack overrides via API.

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
    env_file:
      - stack.env
    environment:
      - TZ=${TZ}
    volumes:
      - /volume1/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
    env_file:
      - stack.env
    healthcheck:
      test: ["CMD", "pg_isready", "-q", "-d", "${DB_DATABASE_NAME}", "-U", "${DB_USERNAME}"]
      interval: 10s
      timeout: 5s
      retries: 5
    shm_size: 128mb
    volumes:
      - /volume1/docker/immich/db:/var/lib/postgresql/data:rw
    environment:
      - TZ=${TZ}
      - POSTGRES_DB=${DB_DATABASE_NAME}
      - POSTGRES_USER=${DB_USERNAME}
      - POSTGRES_PASSWORD="REDACTED_PASSWORD"
      - 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
    environment:
      - NODE_ENV=${NODE_ENV}
      - TZ=${TZ}
      - DB_HOSTNAME=${DB_HOSTNAME}
      - DB_USERNAME=${DB_USERNAME}
      - DB_PASSWORD="REDACTED_PASSWORD"
      - DB_DATABASE_NAME=${DB_DATABASE_NAME}
      - REDIS_HOSTNAME=${REDIS_HOSTNAME}
      - LOG_LEVEL=${LOG_LEVEL}
      - JWT_SECRET=${JWT_SECRET}
      - IMMICH_CONFIG_FILE=/config/immich-config.json
    ports:
      - 8212:2283
    volumes:
      - /volume1/docker/immich/upload:/data:rw
      - /volume1/docker/immich/external_photos/photos:/external/photos:rw
      - /volume1/docker/immich/config/immich-config.json:/config/immich-config.json:ro
    restart: on-failure:5
    depends_on:
      immich-redis:
        condition: service_healthy
      immich-db:
        condition: service_started

  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
    environment:
      - NODE_ENV=${NODE_ENV}
      - TZ=${TZ}
      - DB_HOSTNAME=${DB_HOSTNAME}
      - DB_USERNAME=${DB_USERNAME}
      - DB_PASSWORD="REDACTED_PASSWORD"
      - DB_DATABASE_NAME=${DB_DATABASE_NAME}
      - REDIS_HOSTNAME=${REDIS_HOSTNAME}
      - LOG_LEVEL=${LOG_LEVEL}
      - JWT_SECRET=${JWT_SECRET}
      - MPLCONFIGDIR=/matplotlib
    volumes:
      - /volume1/docker/immich/upload:/data:rw
      - /volume1/docker/immich/external_photos/photos:/external/photos:rw
      - /volume1/docker/immich/cache:/cache:rw
      - /volume1/docker/immich/cache:/.cache:rw
      - /volume1/docker/immich/cache:/.config:rw
      - /volume1/docker/immich/matplotlib:/matplotlib:rw
    restart: on-failure:5
    depends_on:
      immich-db:
        condition: service_started
