services:
  immich-server:
    container_name: ${CONTAINER_NAME}-server
    restart: always
    networks:
      - 1panel-network
    image: altran1502/immich-server:v2.5.5
    volumes:
      - ${UPLOAD_LOCATION}:/usr/src/app/upload
      - /etc/localtime:/etc/localtime:ro
    environment:
      - DB_PASSWORD=${PANEL_DB_USER_PASSWORD}
      - DB_HOSTNAME=${CONTAINER_NAME}-postgres
      - DB_USERNAME=${PANEL_DB_USER}
      - DB_DATABASE_NAME=${PANEL_DB_NAME}
      - REDIS_HOSTNAME=${CONTAINER_NAME}-redis
    ports:
      - ${PANEL_APP_PORT_HTTP}:2283
    depends_on:
      - immich-redis
      - immich-database
    healthcheck:
      disable: false
    labels:  
      createdBy: "Apps"

  immich-machine-learning:
    container_name: ${CONTAINER_NAME}-machine_learning
    restart: always
    networks:
      - 1panel-network
    image: altran1502/immich-machine-learning:v2.5.5
    volumes:
      - ${CACHE_PATH}:/cache
    environment:
      - DB_PASSWORD=${PANEL_DB_USER_PASSWORD}
      - DB_HOSTNAME=${CONTAINER_NAME}-postgres
      - DB_USERNAME=${PANEL_DB_USER}
      - DB_DATABASE_NAME=${PANEL_DB_NAME}
      - REDIS_HOSTNAME=${CONTAINER_NAME}-redis
    healthcheck:
      disable: false
    labels:  
      createdBy: "Apps"

  immich-redis:
    container_name: ${CONTAINER_NAME}-redis
    restart: always
    networks:
      - 1panel-network
    image: "redis:6.2-alpine"
    healthcheck:
      test: redis-cli ping || exit 1
    labels:  
      createdBy: "Apps"

  immich-database:
    container_name: ${CONTAINER_NAME}-postgres
    restart: always
    networks:
      - 1panel-network
    image: "tensorchord/pgvecto-rs:pg14-v0.2.0"
    environment:
      - REDIS_HOSTNAME=${CONTAINER_NAME}-redis
      - POSTGRES_PASSWORD=${PANEL_DB_USER_PASSWORD}
      - POSTGRES_USER=${PANEL_DB_USER}
      - POSTGRES_DB=${PANEL_DB_NAME}
      - POSTGRES_INITDB_ARGS=--data-checksums
    volumes:
      - ${DB_PATH}:/var/lib/postgresql/data
    healthcheck:
      test: >-
        pg_isready --dbname="$${PANEL_DB_NAME}" --username="$${PANEL_DB_USER}" || exit 1;
        Chksum="$$(psql --dbname="$${PANEL_DB_NAME}" --username="$${PANEL_DB_USER}" --tuples-only --no-align
        --command='SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database')";
        echo "checksum failure count is $$Chksum";
        [ "$$Chksum" = '0' ] || exit 1
      interval: 5m
      start_interval: 30s
      start_period: 5m
    command: >-
      postgres
      -c shared_preload_libraries=vectors.so
      -c 'search_path="$$user", public, vectors'
      -c logging_collector=on
      -c max_wal_size=2GB
      -c shared_buffers=512MB
      -c wal_compression=on
    labels:  
      createdBy: "Apps"

networks:
  1panel-network:
    external: true