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:
Chris 2025-06-19 01:55:39 -04:00 committed by GitHub
parent 4190582659
commit 791eca99b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 62 additions and 79 deletions

View File

@ -27,6 +27,9 @@ function update_script() {
msg_error "No ${APP} Installation Found!" msg_error "No ${APP} Installation Found!"
exit exit
fi fi
setup_uv
STAGING_DIR=/opt/staging STAGING_DIR=/opt/staging
BASE_DIR=${STAGING_DIR}/base-images BASE_DIR=${STAGING_DIR}/base-images
SOURCE_DIR=${STAGING_DIR}/image-source SOURCE_DIR=${STAGING_DIR}/image-source
@ -40,7 +43,7 @@ function update_script() {
for url in "${INTEL_URLS[@]}"; do for url in "${INTEL_URLS[@]}"; do
curl -fsSLO "$url" curl -fsSLO "$url"
done done
$STD dpkg -i ./*.deb $STD apt install -y ./*.deb
rm ./*.deb rm ./*.deb
msg_ok "Intel iGPU dependencies updated" msg_ok "Intel iGPU dependencies updated"
fi fi
@ -177,54 +180,42 @@ function update_script() {
msg_ok "Image-processing libraries compiled" msg_ok "Image-processing libraries compiled"
fi fi
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 if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
msg_info "Stopping ${APP} services" msg_info "Stopping ${APP} services"
systemctl stop immich-web systemctl stop immich-web
systemctl stop immich-ml systemctl stop immich-ml
msg_ok "Stopped ${APP}" 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}" INSTALL_DIR="/opt/${APP}"
UPLOAD_DIR="$(sed -n '/^IMMICH_MEDIA_LOCATION/s/[^=]*=//p' /opt/immich/.env)" UPLOAD_DIR="$(sed -n '/^IMMICH_MEDIA_LOCATION/s/[^=]*=//p' /opt/immich/.env)"
SRC_DIR="${INSTALL_DIR}/source" SRC_DIR="${INSTALL_DIR}/source"
APP_DIR="${INSTALL_DIR}/app" APP_DIR="${INSTALL_DIR}/app"
ML_DIR="${APP_DIR}/machine-learning" ML_DIR="${APP_DIR}/machine-learning"
GEO_DIR="${INSTALL_DIR}/geodata" 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" cp "$ML_DIR"/ml_start.sh "$INSTALL_DIR"
rm -rf "${APP_DIR:?}"/* rm -rf "${APP_DIR:?}"/*
rm -rf "$SRC_DIR" rm -rf "$SRC_DIR"
@ -252,28 +243,21 @@ EOF
msg_ok "Updated ${APP} web and microservices" msg_ok "Updated ${APP} web and microservices"
cd "$SRC_DIR"/machine-learning 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 if [[ -f ~/.openvino ]]; then
msg_info "Updating HW-accelerated machine-learning" msg_info "Updating HW-accelerated machine-learning"
( /usr/local/bin/uv -q sync --extra openvino --no-cache --active
source "$ML_DIR"/ml-venv/bin/activate patchelf --clear-execstack "${VIRTUAL_ENV}/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.cpython-311-x86_64-linux-gnu.so"
$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
msg_ok "Updated HW-accelerated machine-learning" msg_ok "Updated HW-accelerated machine-learning"
else else
msg_info "Updating machine-learning" msg_info "Updating machine-learning"
( /usr/local/bin/uv -q sync --extra cpu --no-cache --active
source "$ML_DIR"/ml-venv/bin/activate
$STD pip3 install -U uv
uv -q sync --extra cpu --no-cache --active
)
msg_ok "Updated machine-learning" msg_ok "Updated machine-learning"
fi fi
cd "$SRC_DIR" cd "$SRC_DIR"
cp -a machine-learning/{ann,immich_ml} "$ML_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 if [[ -f ~/.openvino ]]; then
sed -i "/intra_op/s/int = 0/int = os.cpu_count() or 0/" "$ML_DIR"/immich_ml/config.py sed -i "/intra_op/s/int = 0/int = os.cpu_count() or 0/" "$ML_DIR"/immich_ml/config.py
fi fi
@ -292,8 +276,6 @@ EOF
$STD npm i -g @immich/cli $STD npm i -g @immich/cli
msg_ok "Updated Immich CLI" msg_ok "Updated Immich CLI"
sed -i "s|pgvecto.rs|vectorchord|" /opt/"${APP}"/.env
chown -R immich:immich "$INSTALL_DIR" chown -R immich:immich "$INSTALL_DIR"
echo "$RELEASE" >/opt/"${APP}"_version.txt echo "$RELEASE" >/opt/"${APP}"_version.txt
msg_ok "Updated ${APP} to v${RELEASE}" msg_ok "Updated ${APP} to v${RELEASE}"

View File

@ -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", "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" "type": "info"
},
{
"text": "Logs: `/var/log/immich`",
"type": "info"
} }
] ]
} }

View File

@ -13,6 +13,8 @@ setting_up_container
network_check network_check
update_os update_os
setup_uv
msg_info "Configuring apt and installing dependencies" msg_info "Configuring apt and installing dependencies"
echo "deb http://deb.debian.org/debian testing main contrib" >/etc/apt/sources.list.d/immich.list echo "deb http://deb.debian.org/debian testing main contrib" >/etc/apt/sources.list.d/immich.list
cat <<EOF >/etc/apt/preferences.d/immich cat <<EOF >/etc/apt/preferences.d/immich
@ -27,7 +29,6 @@ $STD apt-get install --no-install-recommends -y \
redis \ redis \
autoconf \ autoconf \
build-essential \ build-essential \
python3-venv \
python3-dev \ python3-dev \
cmake \ cmake \
jq \ jq \
@ -63,6 +64,7 @@ $STD apt-get install --no-install-recommends -y \
mesa-utils \ mesa-utils \
mesa-va-drivers \ mesa-va-drivers \
mesa-vulkan-drivers \ mesa-vulkan-drivers \
ocl-icd-libopencl1 \
tini \ tini \
zlib1g zlib1g
$STD apt-get install -y \ $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 if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then
msg_info "Installing OpenVINO dependencies" msg_info "Installing OpenVINO dependencies"
touch ~/.openvino touch ~/.openvino
$STD apt-get -y install --no-install-recommends ocl-icd-libopencl1
tmp_dir=$(mktemp -d) tmp_dir=$(mktemp -d)
$STD pushd "$tmp_dir" $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 -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 -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 -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 -fsSL https://github.com/intel/compute-runtime/releases/download/24.31.30508.7/intel-opencl-icd_24.31.30508.7_amd64.deb -O curl -fsSLO https://github.com/intel/compute-runtime/releases/download/24.31.30508.7/intel-opencl-icd_24.31.30508.7_amd64.deb
curl -fsSL https://github.com/intel/compute-runtime/releases/download/24.31.30508.7/libigdgmm12_22.4.1_amd64.deb -O curl -fsSLO https://github.com/intel/compute-runtime/releases/download/24.31.30508.7/libigdgmm12_22.4.1_amd64.deb
$STD dpkg -i ./*.deb $STD apt install -y ./*.deb
$STD popd $STD popd
rm -rf "$tmp_dir" rm -rf "$tmp_dir"
dpkg -l | grep "intel-opencl-icd" | awk '{print $3}' >~/.intel_version 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 PG_VERSION="16" setup_postgresql
msg_info "Setting up Postgresql Database" msg_info "Setting up Postgresql Database"
$STD apt-get install postgresql-16-pgvector 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/0.3.0/postgresql-16-vchord_0.3.0-1_amd64.deb -o vchord.deb curl -fsSL "https://github.com/tensorchord/VectorChord/releases/download/${VCHORD_RELEASE}/postgresql-16-vchord_${VCHORD_RELEASE}-1_amd64.deb" -o vchord.deb
$STD dpkg -i vchord.deb $STD apt install -y ./vchord.deb
rm vchord.deb rm vchord.deb
echo "$VCHORD_RELEASE" >~/.vchord_version
DB_NAME="immich" DB_NAME="immich"
DB_USER="immich" DB_USER="immich"
DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c18) 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)" msg_info "Installing ${APPLICATION} (more patience please)"
tmp_file=$(mktemp) 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" curl -fsSL "https://github.com/immich-app/immich/archive/refs/tags/v${RELEASE}.zip" -o "$tmp_file"
unzip -q "$tmp_file" unzip -q "$tmp_file"
INSTALL_DIR="/opt/${APPLICATION}" INSTALL_DIR="/opt/${APPLICATION}"
@ -304,23 +306,16 @@ cp LICENSE "$APP_DIR"
msg_ok "Installed Immich Web Components" msg_ok "Installed Immich Web Components"
cd "$SRC_DIR"/machine-learning 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 if [[ -f ~/.openvino ]]; then
msg_info "Installing HW-accelerated machine-learning" msg_info "Installing HW-accelerated machine-learning"
( uv -q sync --extra openvino --no-cache --active
source "$ML_DIR"/ml-venv/bin/activate patchelf --clear-execstack "${VIRTUAL_ENV}/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.cpython-311-x86_64-linux-gnu.so"
$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
msg_ok "Installed HW-accelerated machine-learning" msg_ok "Installed HW-accelerated machine-learning"
else else
msg_info "Installing machine-learning" msg_info "Installing machine-learning"
( uv -q sync --extra cpu --no-cache --active
source "$ML_DIR"/ml-venv/bin/activate
$STD pip3 install uv
uv -q sync --extra cpu --no-cache --active
)
msg_ok "Installed machine-learning" msg_ok "Installed machine-learning"
fi fi
cd "$SRC_DIR" cd "$SRC_DIR"
@ -351,7 +346,9 @@ URL_LIST=(
https://download.geonames.org/export/dump/cities500.zip 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 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 unzip -q cities500.zip
date --iso-8601=seconds | tr -d "\n" >geodata-date.txt date --iso-8601=seconds | tr -d "\n" >geodata-date.txt
rm cities500.zip rm cities500.zip
@ -390,13 +387,13 @@ cat <<EOF >"${ML_DIR}"/ml_start.sh
#!/usr/bin/env bash #!/usr/bin/env bash
cd ${ML_DIR} cd ${ML_DIR}
. ml-venv/bin/activate . ${VIRTUAL_ENV}/bin/activate
set -a set -a
. ${INSTALL_DIR}/.env . ${INSTALL_DIR}/.env
set +a set +a
python -m immich_ml python3 -m immich_ml
EOF EOF
chmod +x "$ML_DIR"/ml_start.sh chmod +x "$ML_DIR"/ml_start.sh
cat <<EOF >/etc/systemd/system/"${APPLICATION}"-web.service cat <<EOF >/etc/systemd/system/"${APPLICATION}"-web.service