Immich Refactor #2 (#11375)

This commit is contained in:
Chris
2026-01-31 20:07:27 -05:00
committed by GitHub
parent f9cf742c25
commit 61964c264e
2 changed files with 69 additions and 43 deletions

View File

@@ -52,9 +52,7 @@ Package: *
Pin:release a=testing Pin:release a=testing
Pin-Priority: 450 Pin-Priority: 450
EOF EOF
if [[ -f /etc/apt/preferences.d/immich ]]; then [[ -f /etc/apt/preferences.d/immich ]] && rm /etc/apt/preferences.d/immich
rm /etc/apt/preferences.d/immich
fi
$STD apt update $STD apt update
msg_ok "Added Debian Testing repo" msg_ok "Added Debian Testing repo"
fi fi
@@ -117,7 +115,7 @@ EOF
if [[ $(cat ~/.immich) > "2.5.1" ]]; then if [[ $(cat ~/.immich) > "2.5.1" ]]; then
msg_info "Enabling Maintenance Mode" msg_info "Enabling Maintenance Mode"
cd /opt/immich/app/bin cd /opt/immich/app/bin
$STD bash ./immich-admin enable-maintenance-mode $STD ./immich-admin enable-maintenance-mode
export MAINT_MODE=1 export MAINT_MODE=1
$STD cd - $STD cd -
msg_ok "Enabled Maintenance Mode" msg_ok "Enabled Maintenance Mode"
@@ -127,18 +125,14 @@ EOF
systemctl stop immich-ml systemctl stop immich-ml
msg_ok "Stopped Services" msg_ok "Stopped Services"
VCHORD_RELEASE="0.5.3" VCHORD_RELEASE="0.5.3"
if [[ ! -f ~/.vchord_version ]] || [[ "$VCHORD_RELEASE" != "$(cat ~/.vchord_version)" ]]; then [[ -f ~/.vchord_version ]] && mv ~/.vchord_version ~/.vectorchord
msg_info "Upgrading VectorChord" if check_for_gh_release "VectorChord" "tensorchord/VectorChord" "${VCHORD_RELEASE}"; then
curl -fsSL "https://github.com/tensorchord/vectorchord/releases/download/${VCHORD_RELEASE}/postgresql-16-vchord_${VCHORD_RELEASE}-1_amd64.deb" -o vchord.deb fetch_and_deploy_gh_release "VectorChord" "tensorchord/VectorChord" "binary" "${VCHORD_RELEASE}" "/tmp" "postgresql-16-vchord_*_amd64.deb"
$STD apt install -y ./vchord.deb
systemctl restart postgresql systemctl restart postgresql
$STD sudo -u postgres psql -d immich -c "ALTER EXTENSION vector UPDATE;" $STD sudo -u postgres psql -d immich -c "ALTER EXTENSION vector UPDATE;"
$STD sudo -u postgres psql -d immich -c "ALTER EXTENSION vchord UPDATE;" $STD sudo -u postgres psql -d immich -c "ALTER EXTENSION vchord UPDATE;"
$STD sudo -u postgres psql -d immich -c "REINDEX INDEX face_index;" $STD sudo -u postgres psql -d immich -c "REINDEX INDEX face_index;"
$STD sudo -u postgres psql -d immich -c "REINDEX INDEX clip_index;" $STD sudo -u postgres psql -d immich -c "REINDEX INDEX clip_index;"
echo "$VCHORD_RELEASE" >~/.vchord_version
rm ./vchord.deb
msg_ok "Upgraded VectorChord to v${VCHORD_RELEASE}"
fi fi
if ! dpkg -l | grep -q ccache; then if ! dpkg -l | grep -q ccache; then
$STD apt install -yqq ccache $STD apt install -yqq ccache
@@ -152,7 +146,7 @@ EOF
ML_DIR="${APP_DIR}/machine-learning" ML_DIR="${APP_DIR}/machine-learning"
GEO_DIR="${INSTALL_DIR}/geodata" GEO_DIR="${INSTALL_DIR}/geodata"
cp "$ML_DIR"/ml_start.sh "$INSTALL_DIR" [[ -f "$ML_DIR"/ml_start.sh ]] && cp "$ML_DIR"/ml_start.sh "$INSTALL_DIR"
if grep -qs "set -a" "$APP_DIR"/bin/start.sh; then if grep -qs "set -a" "$APP_DIR"/bin/start.sh; then
cp "$APP_DIR"/bin/start.sh "$INSTALL_DIR" cp "$APP_DIR"/bin/start.sh "$INSTALL_DIR"
else else
@@ -188,7 +182,7 @@ EOF
export SHARP_FORCE_GLOBAL_LIBVIPS=true export SHARP_FORCE_GLOBAL_LIBVIPS=true
$STD pnpm --filter immich --frozen-lockfile --prod --no-optional deploy "$APP_DIR" $STD pnpm --filter immich --frozen-lockfile --prod --no-optional deploy "$APP_DIR"
cp "$APP_DIR"/package.json "$APP_DIR"/bin cp "$APP_DIR"/package.json "$APP_DIR"/bin
sed -i 's|^start|./start|' "$APP_DIR"/bin/immich-admin sed -i "s|^start|${APP_DIR}/bin/start|" "$APP_DIR"/bin/immich-admin
# openapi & web build # openapi & web build
cd "$SRC_DIR" cd "$SRC_DIR"
@@ -204,8 +198,7 @@ EOF
$STD pnpm --filter @immich/sdk --filter @immich/cli --frozen-lockfile install $STD pnpm --filter @immich/sdk --filter @immich/cli --frozen-lockfile install
$STD pnpm --filter @immich/sdk --filter @immich/cli build $STD pnpm --filter @immich/sdk --filter @immich/cli build
$STD pnpm --filter @immich/cli --prod --no-optional deploy "$APP_DIR"/cli $STD pnpm --filter @immich/cli --prod --no-optional deploy "$APP_DIR"/cli
cd "$APP_DIR" [[ -f "$INSTALL_DIR"/start.sh ]] && mv "$INSTALL_DIR"/start.sh "$APP_DIR"/bin
mv "$INSTALL_DIR"/start.sh "$APP_DIR"/bin
# plugins # plugins
cd "$SRC_DIR" cd "$SRC_DIR"
@@ -236,10 +229,8 @@ EOF
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"
mv "$INSTALL_DIR"/ml_start.sh "$ML_DIR" [[ -f "$INSTALL_DIR"/ml_start.sh ]] && mv "$INSTALL_DIR"/ml_start.sh "$ML_DIR"
if [[ -f ~/.openvino ]]; then [[ -f ~/.openvino ]] && 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
ln -sf "$APP_DIR"/resources "$INSTALL_DIR" ln -sf "$APP_DIR"/resources "$INSTALL_DIR"
cd "$APP_DIR" cd "$APP_DIR"
grep -rl /usr/src | xargs -n1 sed -i "s|\/usr/src|$INSTALL_DIR|g" grep -rl /usr/src | xargs -n1 sed -i "s|\/usr/src|$INSTALL_DIR|g"
@@ -248,18 +239,39 @@ EOF
ln -s "${UPLOAD_DIR:-/opt/immich/upload}" "$APP_DIR"/upload ln -s "${UPLOAD_DIR:-/opt/immich/upload}" "$APP_DIR"/upload
ln -s "${UPLOAD_DIR:-/opt/immich/upload}" "$ML_DIR"/upload ln -s "${UPLOAD_DIR:-/opt/immich/upload}" "$ML_DIR"/upload
ln -s "$GEO_DIR" "$APP_DIR" ln -s "$GEO_DIR" "$APP_DIR"
[[ ! -f /usr/bin/immich ]] && ln -sf "$APP_DIR"/cli/bin/immich /usr/bin/immich
[[ ! -f /usr/bin/immich-admin ]] && ln -sf "$APP_DIR"/bin/immich-admin /usr/bin/immich-admin
chown -R immich:immich "$INSTALL_DIR" chown -R immich:immich "$INSTALL_DIR"
if [[ "${MAINT_MODE:-0}" == 1 ]]; then if [[ "${MAINT_MODE:-0}" == 1 ]]; then
msg_info "Disabling Maintenance Mode" msg_info "Disabling Maintenance Mode"
cd /opt/immich/app/bin cd /opt/immich/app/bin
$STD bash ./immich-admin disable-maintenance-mode $STD ./immich-admin disable-maintenance-mode
unset MAINT_MODE unset MAINT_MODE
$STD cd - $STD cd -
msg_ok "Disabled Maintenance Mode" msg_ok "Disabled Maintenance Mode"
fi fi
systemctl restart immich-ml immich-web systemctl restart immich-ml immich-web
msg_ok "Updated successfully!" msg_ok "Updated successfully!"
msg_info "Checking health of Immich-web & Immich-ml services"
sleep 5
web=0
until curl -fs localhost:2283/api/server/ping | grep -q "pong" || [[ $web -gt 1 ]]; do
msg_warn "Problem detected with Immich-web service, restarting..."
systemctl restart immich-web && sleep 5
[[ $(curl -fs localhost:2283/api/server/ping | grep "pong") ]] && break
((web++))
done
[[ $web -lt 1 ]] && msg_ok "Immich-web service is reachable!" || msg_error "Please check '/var/log/immich/web.log' for more details"
ml=0
until [[ $(curl -fs localhost:3003/ping) == "pong" ]] || [[ $ml -gt 1 ]]; do
msg_warn "Problem detected with Immich-ml service, restarting..."
systemctl restart immich-ml && sleep 5
[[ $(curl -fs localhost:3003/ping) == "pong" ]] && break
((ml++))
done
[[ $ml -lt 1 ]] && msg_ok "Immich-ml service is reachable!" || msg_error "Please check '/var/log/immich/ml.log' for more details"
fi fi
exit exit
} }
@@ -271,7 +283,7 @@ function compile_libjxl() {
: "${LIBJXL_REVISION:=$(jq -cr '.revision' "$BASE_DIR"/server/sources/libjxl.json)}" : "${LIBJXL_REVISION:=$(jq -cr '.revision' "$BASE_DIR"/server/sources/libjxl.json)}"
if [[ "$LIBJXL_REVISION" != "$(grep 'libjxl' ~/.immich_library_revisions | awk '{print $2}')" ]]; then if [[ "$LIBJXL_REVISION" != "$(grep 'libjxl' ~/.immich_library_revisions | awk '{print $2}')" ]]; then
msg_info "Recompiling libjxl" msg_info "Recompiling libjxl"
if [[ -d "$SOURCE" ]]; then rm -rf "$SOURCE"; fi [[ -d "$SOURCE" ]] && rm -rf "$SOURCE"
$STD git clone https://github.com/libjxl/libjxl.git "$SOURCE" $STD git clone https://github.com/libjxl/libjxl.git "$SOURCE"
cd "$SOURCE" cd "$SOURCE"
$STD git reset --hard "$LIBJXL_REVISION" $STD git reset --hard "$LIBJXL_REVISION"
@@ -318,7 +330,7 @@ function compile_libheif() {
: "${LIBHEIF_REVISION:=$(jq -cr '.revision' "$BASE_DIR"/server/sources/libheif.json)}" : "${LIBHEIF_REVISION:=$(jq -cr '.revision' "$BASE_DIR"/server/sources/libheif.json)}"
if [[ "${update:-}" ]] || [[ "$LIBHEIF_REVISION" != "$(grep 'libheif' ~/.immich_library_revisions | awk '{print $2}')" ]]; then if [[ "${update:-}" ]] || [[ "$LIBHEIF_REVISION" != "$(grep 'libheif' ~/.immich_library_revisions | awk '{print $2}')" ]]; then
msg_info "Recompiling libheif" msg_info "Recompiling libheif"
if [[ -d "$SOURCE" ]]; then rm -rf "$SOURCE"; fi [[ -d "$SOURCE" ]] && rm -rf "$SOURCE"
$STD git clone https://github.com/strukturag/libheif.git "$SOURCE" $STD git clone https://github.com/strukturag/libheif.git "$SOURCE"
cd "$SOURCE" cd "$SOURCE"
$STD git reset --hard "$LIBHEIF_REVISION" $STD git reset --hard "$LIBHEIF_REVISION"
@@ -334,7 +346,7 @@ function compile_libheif() {
-DWITH_X265=OFF \ -DWITH_X265=OFF \
-DWITH_EXAMPLES=OFF \ -DWITH_EXAMPLES=OFF \
.. ..
$STD make install -j "$(nproc)" $STD make install -j"$(nproc)"
ldconfig /usr/local/lib ldconfig /usr/local/lib
$STD make clean $STD make clean
cd "$STAGING_DIR" cd "$STAGING_DIR"
@@ -349,7 +361,7 @@ function compile_libraw() {
: "${LIBRAW_REVISION:=$(jq -cr '.revision' "$BASE_DIR"/server/sources/libraw.json)}" : "${LIBRAW_REVISION:=$(jq -cr '.revision' "$BASE_DIR"/server/sources/libraw.json)}"
if [[ "$LIBRAW_REVISION" != "$(grep 'libraw' ~/.immich_library_revisions | awk '{print $2}')" ]]; then if [[ "$LIBRAW_REVISION" != "$(grep 'libraw' ~/.immich_library_revisions | awk '{print $2}')" ]]; then
msg_info "Recompiling libraw" msg_info "Recompiling libraw"
if [[ -d "$SOURCE" ]]; then rm -rf "$SOURCE"; fi [[ -d "$SOURCE" ]] && rm -rf "$SOURCE"
$STD git clone https://github.com/libraw/libraw.git "$SOURCE" $STD git clone https://github.com/libraw/libraw.git "$SOURCE"
cd "$SOURCE" cd "$SOURCE"
$STD git reset --hard "$LIBRAW_REVISION" $STD git reset --hard "$LIBRAW_REVISION"
@@ -371,7 +383,7 @@ function compile_imagemagick() {
if [[ "$IMAGEMAGICK_REVISION" != "$(grep 'imagemagick' ~/.immich_library_revisions | awk '{print $2}')" ]] || if [[ "$IMAGEMAGICK_REVISION" != "$(grep 'imagemagick' ~/.immich_library_revisions | awk '{print $2}')" ]] ||
! grep -q 'DMAGICK_LIBRAW' /usr/local/lib/ImageMagick-7*/config-Q16HDRI/configure.xml; then ! grep -q 'DMAGICK_LIBRAW' /usr/local/lib/ImageMagick-7*/config-Q16HDRI/configure.xml; then
msg_info "Recompiling ImageMagick" msg_info "Recompiling ImageMagick"
if [[ -d "$SOURCE" ]]; then rm -rf "$SOURCE"; fi [[ -d "$SOURCE" ]] && rm -rf "$SOURCE"
$STD git clone https://github.com/ImageMagick/ImageMagick.git "$SOURCE" $STD git clone https://github.com/ImageMagick/ImageMagick.git "$SOURCE"
cd "$SOURCE" cd "$SOURCE"
$STD git reset --hard "$IMAGEMAGICK_REVISION" $STD git reset --hard "$IMAGEMAGICK_REVISION"
@@ -391,7 +403,7 @@ function compile_libvips() {
: "${LIBVIPS_REVISION:=$(jq -cr '.revision' "$BASE_DIR"/server/sources/libvips.json)}" : "${LIBVIPS_REVISION:=$(jq -cr '.revision' "$BASE_DIR"/server/sources/libvips.json)}"
if [[ "$LIBVIPS_REVISION" != "$(grep 'libvips' ~/.immich_library_revisions | awk '{print $2}')" ]]; then if [[ "$LIBVIPS_REVISION" != "$(grep 'libvips' ~/.immich_library_revisions | awk '{print $2}')" ]]; then
msg_info "Recompiling libvips" msg_info "Recompiling libvips"
if [[ -d "$SOURCE" ]]; then rm -rf "$SOURCE"; fi [[ -d "$SOURCE" ]] && rm -rf "$SOURCE"
$STD git clone https://github.com/libvips/libvips.git "$SOURCE" $STD git clone https://github.com/libvips/libvips.git "$SOURCE"
cd "$SOURCE" cd "$SOURCE"
$STD git reset --hard "$LIBVIPS_REVISION" $STD git reset --hard "$LIBVIPS_REVISION"

View File

@@ -149,12 +149,7 @@ NODE_VERSION="24" NODE_MODULE="pnpm@${PNPM_VERSION}" setup_nodejs
PG_VERSION="16" PG_MODULES="pgvector" setup_postgresql PG_VERSION="16" PG_MODULES="pgvector" setup_postgresql
VCHORD_RELEASE="0.5.3" VCHORD_RELEASE="0.5.3"
msg_info "Installing Vectorchord v${VCHORD_RELEASE}" fetch_and_deploy_gh_release "VectorChord" "tensorchord/VectorChord" "binary" "${VCHORD_RELEASE}" "/tmp" "postgresql-16-vchord_*_amd64.deb"
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
msg_ok "Installed Vectorchord v${VCHORD_RELEASE}"
sed -i -e "/^#shared_preload/s/^#//;/^shared_preload/s/''/'vchord.so'/" /etc/postgresql/16/main/postgresql.conf sed -i -e "/^#shared_preload/s/^#//;/^shared_preload/s/''/'vchord.so'/" /etc/postgresql/16/main/postgresql.conf
systemctl restart postgresql.service systemctl restart postgresql.service
@@ -228,7 +223,7 @@ $STD cmake --preset=release-noplugins \
-DWITH_X265=OFF \ -DWITH_X265=OFF \
-DWITH_EXAMPLES=OFF \ -DWITH_EXAMPLES=OFF \
.. ..
$STD make install -j "$(nproc)" $STD make install -j"$(nproc)"
ldconfig /usr/local/lib ldconfig /usr/local/lib
$STD make clean $STD make clean
cd "$STAGING_DIR" cd "$STAGING_DIR"
@@ -293,7 +288,6 @@ APP_DIR="${INSTALL_DIR}/app"
PLUGIN_DIR="${APP_DIR}/corePlugin" PLUGIN_DIR="${APP_DIR}/corePlugin"
ML_DIR="${APP_DIR}/machine-learning" ML_DIR="${APP_DIR}/machine-learning"
GEO_DIR="${INSTALL_DIR}/geodata" GEO_DIR="${INSTALL_DIR}/geodata"
mkdir -p "$INSTALL_DIR"
mkdir -p {"${APP_DIR}","${UPLOAD_DIR}","${GEO_DIR}","${INSTALL_DIR}"/cache} mkdir -p {"${APP_DIR}","${UPLOAD_DIR}","${GEO_DIR}","${INSTALL_DIR}"/cache}
fetch_and_deploy_gh_release "immich" "immich-app/immich" "tarball" "v2.5.2" "$SRC_DIR" fetch_and_deploy_gh_release "immich" "immich-app/immich" "tarball" "v2.5.2" "$SRC_DIR"
@@ -312,7 +306,7 @@ unset SHARP_IGNORE_GLOBAL_LIBVIPS
export SHARP_FORCE_GLOBAL_LIBVIPS=true export SHARP_FORCE_GLOBAL_LIBVIPS=true
$STD pnpm --filter immich --frozen-lockfile --prod --no-optional deploy "$APP_DIR" $STD pnpm --filter immich --frozen-lockfile --prod --no-optional deploy "$APP_DIR"
cp "$APP_DIR"/package.json "$APP_DIR"/bin cp "$APP_DIR"/package.json "$APP_DIR"/bin
sed -i 's|^start|./start|' "$APP_DIR"/bin/immich-admin sed -i "s|^start|${APP_DIR}/bin/start|" "$APP_DIR"/bin/immich-admin
# openapi & web build # openapi & web build
cd "$SRC_DIR" cd "$SRC_DIR"
@@ -358,9 +352,7 @@ else
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"
if [[ -f ~/.openvino ]]; then [[ -f ~/.openvino ]] && 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
ln -sf "$APP_DIR"/resources "$INSTALL_DIR" ln -sf "$APP_DIR"/resources "$INSTALL_DIR"
cd "$APP_DIR" cd "$APP_DIR"
@@ -434,9 +426,11 @@ set +a
/usr/bin/node ${APP_DIR}/dist/main.js "\$@" /usr/bin/node ${APP_DIR}/dist/main.js "\$@"
EOF EOF
chmod +x "$ML_DIR"/ml_start.sh "$APP_DIR"/bin/start.sh chmod +x "$ML_DIR"/ml_start.sh "$APP_DIR"/bin/start.sh
cat <<EOF >/etc/systemd/system/"${APPLICATION}"-web.service ln -sf "$APP_DIR"/cli/bin/immich /usr/bin/immich
ln -sf "$APP_DIR"/bin/immich-admin /usr/bin/immich-admin
cat <<EOF >/etc/systemd/system/immich-web.service
[Unit] [Unit]
Description=${APPLICATION} Web Service Description=Immich Web Service
After=network.target After=network.target
Requires=redis-server.service Requires=redis-server.service
Requires=postgresql.service Requires=postgresql.service
@@ -458,9 +452,9 @@ StandardError=append:/var/log/immich/web.log
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
cat <<EOF >/etc/systemd/system/"${APPLICATION}"-ml.service cat <<EOF >/etc/systemd/system/immich-ml.service
[Unit] [Unit]
Description=${APPLICATION} Machine-Learning Description=Immich Machine-Learning
After=network.target After=network.target
[Service] [Service]
@@ -480,9 +474,29 @@ StandardError=append:/var/log/immich/ml.log
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
chown -R immich:immich "$INSTALL_DIR" /var/log/immich chown -R immich:immich "$INSTALL_DIR" /var/log/immich
systemctl enable -q --now "$APPLICATION"-ml.service "$APPLICATION"-web.service systemctl enable -q --now immich-ml.service immich-web.service
msg_ok "Modified user, created env file, scripts and services" msg_ok "Modified user, created env file, scripts and services"
msg_info "Checking health of Immich-web & Immich-ml services"
sleep 5
web=0
until curl -fs localhost:2283/api/server/ping | grep -q "pong" || [[ $web -gt 1 ]]; do
msg_warn "Problem detected with Immich-web service, restarting..."
systemctl restart immich-web && sleep 5
[[ $(curl -fs localhost:2283/api/server/ping | grep "pong") ]] && break
((web++))
done
[[ $web -lt 1 ]] && msg_ok "Immich-web service is reachable!" || msg_error "Please check '/var/log/immich/web.log' for more details"
ml=0
until [[ $(curl -fs localhost:3003/ping) == "pong" ]] || [[ $ml -gt 1 ]]; do
msg_warn "Problem detected with Immich-ml service, restarting..."
systemctl restart immich-ml && sleep 5
[[ $(curl -fs localhost:3003/ping) == "pong" ]] && break
((ml++))
done
[[ $ml -lt 1 ]] && msg_ok "Immich-ml service is reachable!" || msg_error "Please check '/var/log/immich/ml.log' for more details"
motd_ssh motd_ssh
customize customize
cleanup_lxc cleanup_lxc