Skip to content

Commit 791eca9

Browse files
authored
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
1 parent 4190582 commit 791eca9

File tree

3 files changed

+62
-79
lines changed

3 files changed

+62
-79
lines changed

ct/immich.sh

Lines changed: 35 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ function update_script() {
2727
msg_error "No ${APP} Installation Found!"
2828
exit
2929
fi
30+
31+
setup_uv
32+
3033
STAGING_DIR=/opt/staging
3134
BASE_DIR=${STAGING_DIR}/base-images
3235
SOURCE_DIR=${STAGING_DIR}/image-source
@@ -40,7 +43,7 @@ function update_script() {
4043
for url in "${INTEL_URLS[@]}"; do
4144
curl -fsSLO "$url"
4245
done
43-
$STD dpkg -i ./*.deb
46+
$STD apt install -y ./*.deb
4447
rm ./*.deb
4548
msg_ok "Intel iGPU dependencies updated"
4649
fi
@@ -177,54 +180,42 @@ function update_script() {
177180
msg_ok "Image-processing libraries compiled"
178181
fi
179182
fi
180-
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) }')
183+
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) }')
181184
if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
182185
msg_info "Stopping ${APP} services"
183186
systemctl stop immich-web
184187
systemctl stop immich-ml
185188
msg_ok "Stopped ${APP}"
186-
if [[ "$(cat /opt/${APP}_version.txt)" < "1.133.0" ]]; then
187-
msg_info "Upgrading to the VectorChord PostgreSQL extension"
188-
NUMBER="$(
189-
sed -n '2p' <(
190-
sudo -u postgres psql -A -d immich <<EOF
191-
SELECT atttypmod as dimsize
192-
FROM pg_attribute f
193-
JOIN pg_class c ON c.oid = f.attrelid
194-
WHERE c.relkind = 'r'::char
195-
AND f.attnum > 0
196-
AND c.relname = 'smart_search'::text
197-
AND f.attname = 'embedding'::text;
198-
EOF
199-
)
200-
)"
201-
$STD sudo -u postgres psql -d immich <<EOF
202-
DROP INDEX IF EXISTS clip_index;
203-
DROP INDEX IF EXISTS face_index;
204-
ALTER TABLE smart_search ALTER COLUMN embedding SET DATA TYPE real[];
205-
ALTER TABLE face_search ALTER COLUMN embedding SET DATA TYPE real[];
206-
EOF
207-
$STD apt-get update
208-
$STD apt-get install postgresql-16-pgvector -y
209-
curl -fsSL https://github.com/tensorchord/VectorChord/releases/download/0.3.0/postgresql-16-vchord_0.3.0-1_amd64.deb -o vchord.deb
210-
$STD dpkg -i vchord.deb
211-
rm vchord.deb
212-
sed -i "s|vectors.so|vchord.so|" /etc/postgresql/16/main/postgresql.conf
213-
systemctl restart postgresql.service
214-
$STD sudo -u postgres psql -d immich <<EOF
215-
CREATE EXTENSION IF NOT EXISTS vchord CASCADE;
216-
ALTER TABLE smart_search ALTER COLUMN embedding SET DATA TYPE vector($NUMBER);
217-
ALTER TABLE face_search ALTER COLUMN embedding SET DATA TYPE vector(512);
218-
EOF
219-
$STD apt purge vectors-pg16 -y
220-
msg_ok "Database upgrade complete"
221-
fi
222189
INSTALL_DIR="/opt/${APP}"
223190
UPLOAD_DIR="$(sed -n '/^IMMICH_MEDIA_LOCATION/s/[^=]*=//p' /opt/immich/.env)"
224191
SRC_DIR="${INSTALL_DIR}/source"
225192
APP_DIR="${INSTALL_DIR}/app"
226193
ML_DIR="${APP_DIR}/machine-learning"
227194
GEO_DIR="${INSTALL_DIR}/geodata"
195+
VCHORD_RELEASE="$(curl -fsSL https://api.github.com/repos/tensorchord/vectorchord/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')"
196+
197+
if [[ ! -f ~/.vchord_version ]] || [[ "$VCHORD_RELEASE" != "$(cat ~/.vchord_version)" ]]; then
198+
msg_info "Updating VectorChord"
199+
if [[ ! -f ~/.vchord_version ]] || [[ ! "$(cat ~/.vchord_version)" > "0.3.0" ]]; then
200+
$STD sudo -u postgres pg_dumpall --clean --if-exists --username=postgres | gzip >/etc/postgresql/immich-db-vchord0.3.0.sql.gz
201+
chown postgres /etc/postgresql/immich-db-vchord0.3.0.sql.gz
202+
$STD sudo -u postgres gunzip --stdout /etc/postgresql/immich-db-vchord0.3.0.sql.gz |
203+
sed -e "s/SELECT pg_catalog.set_config('search_path', '', false);/SELECT pg_catalog.set_config('search_path', 'public, pg_catalog', true);/g" \
204+
-e "/vchordrq.prewarm_dim/d" |
205+
sudo -u postgres psql
206+
fi
207+
curl -fsSL "https://github.com/tensorchord/vectorchord/releases/download/${VCHORD_RELEASE}/postgresql-16-vchord_${VCHORD_RELEASE}-1_amd64.deb" -o vchord.deb
208+
$STD apt install -y ./vchord.deb
209+
$STD sudo -u postgres psql -d immich -c "ALTER EXTENSION vchord UPDATE;"
210+
systemctl restart postgresql
211+
if [[ ! -f ~/.vchord-version ]] || [[ ! "$(cat ~/.vchord_version)" > "0.3.0" ]]; then
212+
$STD sudo -u postgres psql -d immich -c "REINDEX DATABASE;"
213+
fi
214+
echo "$VCHORD_RELEASE" >~/.vchord_version
215+
rm ./vchord.deb
216+
msg_ok "Updated VectorChord to v${VCHORD_RELEASE}"
217+
fi
218+
228219
cp "$ML_DIR"/ml_start.sh "$INSTALL_DIR"
229220
rm -rf "${APP_DIR:?}"/*
230221
rm -rf "$SRC_DIR"
@@ -252,28 +243,21 @@ EOF
252243
msg_ok "Updated ${APP} web and microservices"
253244

254245
cd "$SRC_DIR"/machine-learning
255-
$STD python3 -m venv "$ML_DIR"/ml-venv
246+
export VIRTUAL_ENV="${ML_DIR}"/ml-venv
247+
$STD /usr/local/bin/uv venv "$VIRTUAL_ENV"
256248
if [[ -f ~/.openvino ]]; then
257249
msg_info "Updating HW-accelerated machine-learning"
258-
(
259-
source "$ML_DIR"/ml-venv/bin/activate
260-
$STD pip3 install -U uv
261-
uv -q sync --extra openvino --no-cache --active
262-
)
263-
patchelf --clear-execstack "$ML_DIR"/ml-venv/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.cpython-311-x86_64-linux-gnu.so
250+
/usr/local/bin/uv -q sync --extra openvino --no-cache --active
251+
patchelf --clear-execstack "${VIRTUAL_ENV}/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.cpython-311-x86_64-linux-gnu.so"
264252
msg_ok "Updated HW-accelerated machine-learning"
265253
else
266254
msg_info "Updating machine-learning"
267-
(
268-
source "$ML_DIR"/ml-venv/bin/activate
269-
$STD pip3 install -U uv
270-
uv -q sync --extra cpu --no-cache --active
271-
)
255+
/usr/local/bin/uv -q sync --extra cpu --no-cache --active
272256
msg_ok "Updated machine-learning"
273257
fi
274258
cd "$SRC_DIR"
275259
cp -a machine-learning/{ann,immich_ml} "$ML_DIR"
276-
cp "$INSTALL_DIR"/ml_start.sh "$ML_DIR"
260+
mv "$INSTALL_DIR"/ml_start.sh "$ML_DIR"
277261
if [[ -f ~/.openvino ]]; then
278262
sed -i "/intra_op/s/int = 0/int = os.cpu_count() or 0/" "$ML_DIR"/immich_ml/config.py
279263
fi
@@ -292,8 +276,6 @@ EOF
292276
$STD npm i -g @immich/cli
293277
msg_ok "Updated Immich CLI"
294278

295-
sed -i "s|pgvecto.rs|vectorchord|" /opt/"${APP}"/.env
296-
297279
chown -R immich:immich "$INSTALL_DIR"
298280
echo "$RELEASE" >/opt/"${APP}"_version.txt
299281
msg_ok "Updated ${APP} to v${RELEASE}"

frontend/public/json/immich.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
{
4444
"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",
4545
"type": "info"
46+
},
47+
{
48+
"text": "Logs: `/var/log/immich`",
49+
"type": "info"
4650
}
4751
]
4852
}

install/immich-install.sh

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ setting_up_container
1313
network_check
1414
update_os
1515

16+
setup_uv
17+
1618
msg_info "Configuring apt and installing dependencies"
1719
echo "deb http://deb.debian.org/debian testing main contrib" >/etc/apt/sources.list.d/immich.list
1820
cat <<EOF >/etc/apt/preferences.d/immich
@@ -27,7 +29,6 @@ $STD apt-get install --no-install-recommends -y \
2729
redis \
2830
autoconf \
2931
build-essential \
30-
python3-venv \
3132
python3-dev \
3233
cmake \
3334
jq \
@@ -63,6 +64,7 @@ $STD apt-get install --no-install-recommends -y \
6364
mesa-utils \
6465
mesa-va-drivers \
6566
mesa-vulkan-drivers \
67+
ocl-icd-libopencl1 \
6668
tini \
6769
zlib1g
6870
$STD apt-get install -y \
@@ -88,14 +90,13 @@ read -r -p "Install OpenVINO dependencies for Intel HW-accelerated machine-learn
8890
if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then
8991
msg_info "Installing OpenVINO dependencies"
9092
touch ~/.openvino
91-
$STD apt-get -y install --no-install-recommends ocl-icd-libopencl1
9293
tmp_dir=$(mktemp -d)
9394
$STD pushd "$tmp_dir"
94-
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
95-
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
96-
curl -fsSL https://github.com/intel/compute-runtime/releases/download/24.31.30508.7/intel-opencl-icd_24.31.30508.7_amd64.deb -O
97-
curl -fsSL https://github.com/intel/compute-runtime/releases/download/24.31.30508.7/libigdgmm12_22.4.1_amd64.deb -O
98-
$STD dpkg -i ./*.deb
95+
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
96+
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
97+
curl -fsSLO https://github.com/intel/compute-runtime/releases/download/24.31.30508.7/intel-opencl-icd_24.31.30508.7_amd64.deb
98+
curl -fsSLO https://github.com/intel/compute-runtime/releases/download/24.31.30508.7/libigdgmm12_22.4.1_amd64.deb
99+
$STD apt install -y ./*.deb
99100
$STD popd
100101
rm -rf "$tmp_dir"
101102
dpkg -l | grep "intel-opencl-icd" | awk '{print $3}' >~/.intel_version
@@ -113,10 +114,11 @@ NODE_VERSION="22" setup_nodejs
113114
PG_VERSION="16" setup_postgresql
114115

115116
msg_info "Setting up Postgresql Database"
116-
$STD apt-get install postgresql-16-pgvector
117-
curl -fsSL https://github.com/tensorchord/VectorChord/releases/download/0.3.0/postgresql-16-vchord_0.3.0-1_amd64.deb -o vchord.deb
118-
$STD dpkg -i vchord.deb
117+
VCHORD_RELEASE="$(curl -fsSL https://api.github.com/repos/tensorchord/vectorchord/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')"
118+
curl -fsSL "https://github.com/tensorchord/VectorChord/releases/download/${VCHORD_RELEASE}/postgresql-16-vchord_${VCHORD_RELEASE}-1_amd64.deb" -o vchord.deb
119+
$STD apt install -y ./vchord.deb
119120
rm vchord.deb
121+
echo "$VCHORD_RELEASE" >~/.vchord_version
120122
DB_NAME="immich"
121123
DB_USER="immich"
122124
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"
273275

274276
msg_info "Installing ${APPLICATION} (more patience please)"
275277
tmp_file=$(mktemp)
276-
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) }')
278+
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) }')
277279
curl -fsSL "https://github.com/immich-app/immich/archive/refs/tags/v${RELEASE}.zip" -o "$tmp_file"
278280
unzip -q "$tmp_file"
279281
INSTALL_DIR="/opt/${APPLICATION}"
@@ -304,23 +306,16 @@ cp LICENSE "$APP_DIR"
304306
msg_ok "Installed Immich Web Components"
305307

306308
cd "$SRC_DIR"/machine-learning
307-
$STD python3 -m venv "$ML_DIR/ml-venv"
309+
export VIRTUAL_ENV="${ML_DIR}/ml-venv"
310+
$STD uv venv "$VIRTUAL_ENV"
308311
if [[ -f ~/.openvino ]]; then
309312
msg_info "Installing HW-accelerated machine-learning"
310-
(
311-
source "$ML_DIR"/ml-venv/bin/activate
312-
$STD pip3 install uv
313-
uv -q sync --extra openvino --no-cache --active
314-
)
315-
patchelf --clear-execstack "$ML_DIR"/ml-venv/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.cpython-311-x86_64-linux-gnu.so
313+
uv -q sync --extra openvino --no-cache --active
314+
patchelf --clear-execstack "${VIRTUAL_ENV}/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_pybind11_state.cpython-311-x86_64-linux-gnu.so"
316315
msg_ok "Installed HW-accelerated machine-learning"
317316
else
318317
msg_info "Installing machine-learning"
319-
(
320-
source "$ML_DIR"/ml-venv/bin/activate
321-
$STD pip3 install uv
322-
uv -q sync --extra cpu --no-cache --active
323-
)
318+
uv -q sync --extra cpu --no-cache --active
324319
msg_ok "Installed machine-learning"
325320
fi
326321
cd "$SRC_DIR"
@@ -351,7 +346,9 @@ URL_LIST=(
351346
https://download.geonames.org/export/dump/cities500.zip
352347
https://raw.githubusercontent.com/nvkelso/natural-earth-vector/v5.1.2/geojson/ne_10m_admin_0_countries.geojson
353348
)
354-
echo "${URL_LIST[@]}" | xargs -n1 -P 8 wget -q
349+
for geo in "${URL_LIST[@]}"; do
350+
curl -fsSLO "$geo"
351+
done
355352
unzip -q cities500.zip
356353
date --iso-8601=seconds | tr -d "\n" >geodata-date.txt
357354
rm cities500.zip
@@ -390,13 +387,13 @@ cat <<EOF >"${ML_DIR}"/ml_start.sh
390387
#!/usr/bin/env bash
391388
392389
cd ${ML_DIR}
393-
. ml-venv/bin/activate
390+
. ${VIRTUAL_ENV}/bin/activate
394391
395392
set -a
396393
. ${INSTALL_DIR}/.env
397394
set +a
398395
399-
python -m immich_ml
396+
python3 -m immich_ml
400397
EOF
401398
chmod +x "$ML_DIR"/ml_start.sh
402399
cat <<EOF >/etc/systemd/system/"${APPLICATION}"-web.service

0 commit comments

Comments
 (0)