mirror of
				https://github.com/community-scripts/ProxmoxVE.git
				synced 2025-11-04 10:22:50 +00:00 
			
		
		
		
	immich: prepare for new version (#5025)
- Remove pgvecto.rs > vchord migration operation - Check for vchord update - only apply if Immich has update - Additional operations for vchord 0.3.0 to 0.4.x - Use UV - Move libopencl to dependencies - Use vchord 0.3.0 only if Immich <= 1.134.0 - vchord 0.4.x for 1.134.1+ - Use UV
This commit is contained in:
		
							
								
								
									
										88
									
								
								ct/immich.sh
									
									
									
									
									
								
							
							
						
						
									
										88
									
								
								ct/immich.sh
									
									
									
									
									
								
							@@ -27,6 +27,9 @@ function update_script() {
 | 
			
		||||
    msg_error "No ${APP} Installation Found!"
 | 
			
		||||
    exit
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
  setup_uv
 | 
			
		||||
 | 
			
		||||
  STAGING_DIR=/opt/staging
 | 
			
		||||
  BASE_DIR=${STAGING_DIR}/base-images
 | 
			
		||||
  SOURCE_DIR=${STAGING_DIR}/image-source
 | 
			
		||||
@@ -40,7 +43,7 @@ function update_script() {
 | 
			
		||||
      for url in "${INTEL_URLS[@]}"; do
 | 
			
		||||
        curl -fsSLO "$url"
 | 
			
		||||
      done
 | 
			
		||||
      $STD dpkg -i ./*.deb
 | 
			
		||||
      $STD apt install -y ./*.deb
 | 
			
		||||
      rm ./*.deb
 | 
			
		||||
      msg_ok "Intel iGPU dependencies updated"
 | 
			
		||||
    fi
 | 
			
		||||
@@ -177,54 +180,42 @@ function update_script() {
 | 
			
		||||
      msg_ok "Image-processing libraries compiled"
 | 
			
		||||
    fi
 | 
			
		||||
  fi
 | 
			
		||||
  RELEASE=$(curl -s https://api.github.com/repos/immich-app/immich/releases?per_page=1 | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
 | 
			
		||||
  RELEASE=$(curl -fsSL https://api.github.com/repos/immich-app/immich/releases?per_page=1 | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
 | 
			
		||||
  if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
 | 
			
		||||
    msg_info "Stopping ${APP} services"
 | 
			
		||||
    systemctl stop immich-web
 | 
			
		||||
    systemctl stop immich-ml
 | 
			
		||||
    msg_ok "Stopped ${APP}"
 | 
			
		||||
    if [[ "$(cat /opt/${APP}_version.txt)" < "1.133.0" ]]; then
 | 
			
		||||
      msg_info "Upgrading to the VectorChord PostgreSQL extension"
 | 
			
		||||
      NUMBER="$(
 | 
			
		||||
        sed -n '2p' <(
 | 
			
		||||
          sudo -u postgres psql -A -d immich <<EOF
 | 
			
		||||
        SELECT atttypmod as dimsize
 | 
			
		||||
          FROM pg_attribute f
 | 
			
		||||
          JOIN pg_class c ON c.oid = f.attrelid
 | 
			
		||||
          WHERE c.relkind = 'r'::char
 | 
			
		||||
          AND f.attnum > 0
 | 
			
		||||
          AND c.relname = 'smart_search'::text
 | 
			
		||||
          AND f.attname = 'embedding'::text;
 | 
			
		||||
EOF
 | 
			
		||||
        )
 | 
			
		||||
      )"
 | 
			
		||||
      $STD sudo -u postgres psql -d immich <<EOF
 | 
			
		||||
      DROP INDEX IF EXISTS clip_index;
 | 
			
		||||
      DROP INDEX IF EXISTS face_index;
 | 
			
		||||
      ALTER TABLE smart_search ALTER COLUMN embedding SET DATA TYPE real[];
 | 
			
		||||
      ALTER TABLE face_search ALTER COLUMN embedding SET DATA TYPE real[];
 | 
			
		||||
EOF
 | 
			
		||||
      $STD apt-get update
 | 
			
		||||
      $STD apt-get install postgresql-16-pgvector -y
 | 
			
		||||
      curl -fsSL https://github.com/tensorchord/VectorChord/releases/download/0.3.0/postgresql-16-vchord_0.3.0-1_amd64.deb -o vchord.deb
 | 
			
		||||
      $STD dpkg -i vchord.deb
 | 
			
		||||
      rm vchord.deb
 | 
			
		||||
      sed -i "s|vectors.so|vchord.so|" /etc/postgresql/16/main/postgresql.conf
 | 
			
		||||
      systemctl restart postgresql.service
 | 
			
		||||
      $STD sudo -u postgres psql -d immich <<EOF
 | 
			
		||||
      CREATE EXTENSION IF NOT EXISTS vchord CASCADE;
 | 
			
		||||
      ALTER TABLE smart_search ALTER COLUMN embedding SET DATA TYPE vector($NUMBER);
 | 
			
		||||
      ALTER TABLE face_search ALTER COLUMN embedding SET DATA TYPE vector(512);
 | 
			
		||||
EOF
 | 
			
		||||
      $STD apt purge vectors-pg16 -y
 | 
			
		||||
      msg_ok "Database upgrade complete"
 | 
			
		||||
    fi
 | 
			
		||||
    INSTALL_DIR="/opt/${APP}"
 | 
			
		||||
    UPLOAD_DIR="$(sed -n '/^IMMICH_MEDIA_LOCATION/s/[^=]*=//p' /opt/immich/.env)"
 | 
			
		||||
    SRC_DIR="${INSTALL_DIR}/source"
 | 
			
		||||
    APP_DIR="${INSTALL_DIR}/app"
 | 
			
		||||
    ML_DIR="${APP_DIR}/machine-learning"
 | 
			
		||||
    GEO_DIR="${INSTALL_DIR}/geodata"
 | 
			
		||||
    VCHORD_RELEASE="$(curl -fsSL https://api.github.com/repos/tensorchord/vectorchord/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')"
 | 
			
		||||
 | 
			
		||||
    if [[ ! -f ~/.vchord_version ]] || [[ "$VCHORD_RELEASE" != "$(cat ~/.vchord_version)" ]]; then
 | 
			
		||||
      msg_info "Updating VectorChord"
 | 
			
		||||
      if [[ ! -f ~/.vchord_version ]] || [[ ! "$(cat ~/.vchord_version)" > "0.3.0" ]]; then
 | 
			
		||||
        $STD sudo -u postgres pg_dumpall --clean --if-exists --username=postgres | gzip >/etc/postgresql/immich-db-vchord0.3.0.sql.gz
 | 
			
		||||
        chown postgres /etc/postgresql/immich-db-vchord0.3.0.sql.gz
 | 
			
		||||
        $STD sudo -u postgres gunzip --stdout /etc/postgresql/immich-db-vchord0.3.0.sql.gz |
 | 
			
		||||
          sed -e "s/SELECT pg_catalog.set_config('search_path', '', false);/SELECT pg_catalog.set_config('search_path', 'public, pg_catalog', true);/g" \
 | 
			
		||||
            -e "/vchordrq.prewarm_dim/d" |
 | 
			
		||||
          sudo -u postgres psql
 | 
			
		||||
      fi
 | 
			
		||||
      curl -fsSL "https://github.com/tensorchord/vectorchord/releases/download/${VCHORD_RELEASE}/postgresql-16-vchord_${VCHORD_RELEASE}-1_amd64.deb" -o vchord.deb
 | 
			
		||||
      $STD apt install -y ./vchord.deb
 | 
			
		||||
      $STD sudo -u postgres psql -d immich -c "ALTER EXTENSION vchord UPDATE;"
 | 
			
		||||
      systemctl restart postgresql
 | 
			
		||||
      if [[ ! -f ~/.vchord-version ]] || [[ ! "$(cat ~/.vchord_version)" > "0.3.0" ]]; then
 | 
			
		||||
        $STD sudo -u postgres psql -d immich -c "REINDEX DATABASE;"
 | 
			
		||||
      fi
 | 
			
		||||
      echo "$VCHORD_RELEASE" >~/.vchord_version
 | 
			
		||||
      rm ./vchord.deb
 | 
			
		||||
      msg_ok "Updated VectorChord to v${VCHORD_RELEASE}"
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    cp "$ML_DIR"/ml_start.sh "$INSTALL_DIR"
 | 
			
		||||
    rm -rf "${APP_DIR:?}"/*
 | 
			
		||||
    rm -rf "$SRC_DIR"
 | 
			
		||||
@@ -252,28 +243,21 @@ EOF
 | 
			
		||||
    msg_ok "Updated ${APP} web and microservices"
 | 
			
		||||
 | 
			
		||||
    cd "$SRC_DIR"/machine-learning
 | 
			
		||||
    $STD python3 -m venv "$ML_DIR"/ml-venv
 | 
			
		||||
    export VIRTUAL_ENV="${ML_DIR}"/ml-venv
 | 
			
		||||
    $STD /usr/local/bin/uv venv "$VIRTUAL_ENV"
 | 
			
		||||
    if [[ -f ~/.openvino ]]; then
 | 
			
		||||
      msg_info "Updating HW-accelerated machine-learning"
 | 
			
		||||
      (
 | 
			
		||||
        source "$ML_DIR"/ml-venv/bin/activate
 | 
			
		||||
        $STD pip3 install -U uv
 | 
			
		||||
        uv -q sync --extra openvino --no-cache --active
 | 
			
		||||
      )
 | 
			
		||||
      patchelf --clear-execstack "$ML_DIR"/ml-venv/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.cpython-311-x86_64-linux-gnu.so
 | 
			
		||||
      /usr/local/bin/uv -q sync --extra openvino --no-cache --active
 | 
			
		||||
      patchelf --clear-execstack "${VIRTUAL_ENV}/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.cpython-311-x86_64-linux-gnu.so"
 | 
			
		||||
      msg_ok "Updated HW-accelerated machine-learning"
 | 
			
		||||
    else
 | 
			
		||||
      msg_info "Updating machine-learning"
 | 
			
		||||
      (
 | 
			
		||||
        source "$ML_DIR"/ml-venv/bin/activate
 | 
			
		||||
        $STD pip3 install -U uv
 | 
			
		||||
        uv -q sync --extra cpu --no-cache --active
 | 
			
		||||
      )
 | 
			
		||||
      /usr/local/bin/uv -q sync --extra cpu --no-cache --active
 | 
			
		||||
      msg_ok "Updated machine-learning"
 | 
			
		||||
    fi
 | 
			
		||||
    cd "$SRC_DIR"
 | 
			
		||||
    cp -a machine-learning/{ann,immich_ml} "$ML_DIR"
 | 
			
		||||
    cp "$INSTALL_DIR"/ml_start.sh "$ML_DIR"
 | 
			
		||||
    mv "$INSTALL_DIR"/ml_start.sh "$ML_DIR"
 | 
			
		||||
    if [[ -f ~/.openvino ]]; then
 | 
			
		||||
      sed -i "/intra_op/s/int = 0/int = os.cpu_count() or 0/" "$ML_DIR"/immich_ml/config.py
 | 
			
		||||
    fi
 | 
			
		||||
@@ -292,8 +276,6 @@ EOF
 | 
			
		||||
    $STD npm i -g @immich/cli
 | 
			
		||||
    msg_ok "Updated Immich CLI"
 | 
			
		||||
 | 
			
		||||
    sed -i "s|pgvecto.rs|vectorchord|" /opt/"${APP}"/.env
 | 
			
		||||
 | 
			
		||||
    chown -R immich:immich "$INSTALL_DIR"
 | 
			
		||||
    echo "$RELEASE" >/opt/"${APP}"_version.txt
 | 
			
		||||
    msg_ok "Updated ${APP} to v${RELEASE}"
 | 
			
		||||
 
 | 
			
		||||
@@ -43,6 +43,10 @@
 | 
			
		||||
    {
 | 
			
		||||
      "text": "To change upload location, edit 'IMMICH_MEDIA_LOCATION' in `/opt/immich/.env`, and create the symlink 'upload' in /opt/immich/app & /opt/immich/app/machine-learning to your new upload location",
 | 
			
		||||
      "type": "info"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      "text": "Logs: `/var/log/immich`",
 | 
			
		||||
      "type": "info"
 | 
			
		||||
    }
 | 
			
		||||
  ]
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,8 @@ setting_up_container
 | 
			
		||||
network_check
 | 
			
		||||
update_os
 | 
			
		||||
 | 
			
		||||
setup_uv
 | 
			
		||||
 | 
			
		||||
msg_info "Configuring apt and installing dependencies"
 | 
			
		||||
echo "deb http://deb.debian.org/debian testing main contrib" >/etc/apt/sources.list.d/immich.list
 | 
			
		||||
cat <<EOF >/etc/apt/preferences.d/immich
 | 
			
		||||
@@ -27,7 +29,6 @@ $STD apt-get install --no-install-recommends -y \
 | 
			
		||||
  redis \
 | 
			
		||||
  autoconf \
 | 
			
		||||
  build-essential \
 | 
			
		||||
  python3-venv \
 | 
			
		||||
  python3-dev \
 | 
			
		||||
  cmake \
 | 
			
		||||
  jq \
 | 
			
		||||
@@ -63,6 +64,7 @@ $STD apt-get install --no-install-recommends -y \
 | 
			
		||||
  mesa-utils \
 | 
			
		||||
  mesa-va-drivers \
 | 
			
		||||
  mesa-vulkan-drivers \
 | 
			
		||||
  ocl-icd-libopencl1 \
 | 
			
		||||
  tini \
 | 
			
		||||
  zlib1g
 | 
			
		||||
$STD apt-get install -y \
 | 
			
		||||
@@ -88,14 +90,13 @@ read -r -p "Install OpenVINO dependencies for Intel HW-accelerated machine-learn
 | 
			
		||||
if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then
 | 
			
		||||
  msg_info "Installing OpenVINO dependencies"
 | 
			
		||||
  touch ~/.openvino
 | 
			
		||||
  $STD apt-get -y install --no-install-recommends ocl-icd-libopencl1
 | 
			
		||||
  tmp_dir=$(mktemp -d)
 | 
			
		||||
  $STD pushd "$tmp_dir"
 | 
			
		||||
  curl -fsSL https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.17384.11/intel-igc-core_1.0.17384.11_amd64.deb -O
 | 
			
		||||
  curl -fsSL https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.17384.11/intel-igc-opencl_1.0.17384.11_amd64.deb -O
 | 
			
		||||
  curl -fsSL https://github.com/intel/compute-runtime/releases/download/24.31.30508.7/intel-opencl-icd_24.31.30508.7_amd64.deb -O
 | 
			
		||||
  curl -fsSL https://github.com/intel/compute-runtime/releases/download/24.31.30508.7/libigdgmm12_22.4.1_amd64.deb -O
 | 
			
		||||
  $STD dpkg -i ./*.deb
 | 
			
		||||
  curl -fsSLO https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.17384.11/intel-igc-core_1.0.17384.11_amd64.deb
 | 
			
		||||
  curl -fsSLO https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.17384.11/intel-igc-opencl_1.0.17384.11_amd64.deb
 | 
			
		||||
  curl -fsSLO https://github.com/intel/compute-runtime/releases/download/24.31.30508.7/intel-opencl-icd_24.31.30508.7_amd64.deb
 | 
			
		||||
  curl -fsSLO https://github.com/intel/compute-runtime/releases/download/24.31.30508.7/libigdgmm12_22.4.1_amd64.deb
 | 
			
		||||
  $STD apt install -y ./*.deb
 | 
			
		||||
  $STD popd
 | 
			
		||||
  rm -rf "$tmp_dir"
 | 
			
		||||
  dpkg -l | grep "intel-opencl-icd" | awk '{print $3}' >~/.intel_version
 | 
			
		||||
@@ -113,10 +114,11 @@ NODE_VERSION="22" setup_nodejs
 | 
			
		||||
PG_VERSION="16" setup_postgresql
 | 
			
		||||
 | 
			
		||||
msg_info "Setting up Postgresql Database"
 | 
			
		||||
$STD apt-get install postgresql-16-pgvector
 | 
			
		||||
curl -fsSL https://github.com/tensorchord/VectorChord/releases/download/0.3.0/postgresql-16-vchord_0.3.0-1_amd64.deb -o vchord.deb
 | 
			
		||||
$STD dpkg -i vchord.deb
 | 
			
		||||
VCHORD_RELEASE="$(curl -fsSL https://api.github.com/repos/tensorchord/vectorchord/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')"
 | 
			
		||||
curl -fsSL "https://github.com/tensorchord/VectorChord/releases/download/${VCHORD_RELEASE}/postgresql-16-vchord_${VCHORD_RELEASE}-1_amd64.deb" -o vchord.deb
 | 
			
		||||
$STD apt install -y ./vchord.deb
 | 
			
		||||
rm vchord.deb
 | 
			
		||||
echo "$VCHORD_RELEASE" >~/.vchord_version
 | 
			
		||||
DB_NAME="immich"
 | 
			
		||||
DB_USER="immich"
 | 
			
		||||
DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c18)
 | 
			
		||||
@@ -273,7 +275,7 @@ msg_ok "Custom Photo-processing Library Compiled"
 | 
			
		||||
 | 
			
		||||
msg_info "Installing ${APPLICATION} (more patience please)"
 | 
			
		||||
tmp_file=$(mktemp)
 | 
			
		||||
RELEASE=$(curl -s https://api.github.com/repos/immich-app/immich/releases?per_page=1 | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
 | 
			
		||||
RELEASE=$(curl -fsSL https://api.github.com/repos/immich-app/immich/releases?per_page=1 | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
 | 
			
		||||
curl -fsSL "https://github.com/immich-app/immich/archive/refs/tags/v${RELEASE}.zip" -o "$tmp_file"
 | 
			
		||||
unzip -q "$tmp_file"
 | 
			
		||||
INSTALL_DIR="/opt/${APPLICATION}"
 | 
			
		||||
@@ -304,23 +306,16 @@ cp LICENSE "$APP_DIR"
 | 
			
		||||
msg_ok "Installed Immich Web Components"
 | 
			
		||||
 | 
			
		||||
cd "$SRC_DIR"/machine-learning
 | 
			
		||||
$STD python3 -m venv "$ML_DIR/ml-venv"
 | 
			
		||||
export VIRTUAL_ENV="${ML_DIR}/ml-venv"
 | 
			
		||||
$STD uv venv "$VIRTUAL_ENV"
 | 
			
		||||
if [[ -f ~/.openvino ]]; then
 | 
			
		||||
  msg_info "Installing HW-accelerated machine-learning"
 | 
			
		||||
  (
 | 
			
		||||
    source "$ML_DIR"/ml-venv/bin/activate
 | 
			
		||||
    $STD pip3 install uv
 | 
			
		||||
    uv -q sync --extra openvino --no-cache --active
 | 
			
		||||
  )
 | 
			
		||||
  patchelf --clear-execstack "$ML_DIR"/ml-venv/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.cpython-311-x86_64-linux-gnu.so
 | 
			
		||||
  uv -q sync --extra openvino --no-cache --active
 | 
			
		||||
  patchelf --clear-execstack "${VIRTUAL_ENV}/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.cpython-311-x86_64-linux-gnu.so"
 | 
			
		||||
  msg_ok "Installed HW-accelerated machine-learning"
 | 
			
		||||
else
 | 
			
		||||
  msg_info "Installing machine-learning"
 | 
			
		||||
  (
 | 
			
		||||
    source "$ML_DIR"/ml-venv/bin/activate
 | 
			
		||||
    $STD pip3 install uv
 | 
			
		||||
    uv -q sync --extra cpu --no-cache --active
 | 
			
		||||
  )
 | 
			
		||||
  uv -q sync --extra cpu --no-cache --active
 | 
			
		||||
  msg_ok "Installed machine-learning"
 | 
			
		||||
fi
 | 
			
		||||
cd "$SRC_DIR"
 | 
			
		||||
@@ -351,7 +346,9 @@ URL_LIST=(
 | 
			
		||||
  https://download.geonames.org/export/dump/cities500.zip
 | 
			
		||||
  https://raw.githubusercontent.com/nvkelso/natural-earth-vector/v5.1.2/geojson/ne_10m_admin_0_countries.geojson
 | 
			
		||||
)
 | 
			
		||||
echo "${URL_LIST[@]}" | xargs -n1 -P 8 wget -q
 | 
			
		||||
for geo in "${URL_LIST[@]}"; do
 | 
			
		||||
  curl -fsSLO "$geo"
 | 
			
		||||
done
 | 
			
		||||
unzip -q cities500.zip
 | 
			
		||||
date --iso-8601=seconds | tr -d "\n" >geodata-date.txt
 | 
			
		||||
rm cities500.zip
 | 
			
		||||
@@ -390,13 +387,13 @@ cat <<EOF >"${ML_DIR}"/ml_start.sh
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
 | 
			
		||||
cd ${ML_DIR}
 | 
			
		||||
. ml-venv/bin/activate
 | 
			
		||||
. ${VIRTUAL_ENV}/bin/activate
 | 
			
		||||
 | 
			
		||||
set -a
 | 
			
		||||
. ${INSTALL_DIR}/.env
 | 
			
		||||
set +a
 | 
			
		||||
 | 
			
		||||
python -m immich_ml
 | 
			
		||||
python3 -m immich_ml
 | 
			
		||||
EOF
 | 
			
		||||
chmod +x "$ML_DIR"/ml_start.sh
 | 
			
		||||
cat <<EOF >/etc/systemd/system/"${APPLICATION}"-web.service
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user